changed to _create_backend_figure; started subplot removal

This commit is contained in:
Thomas Breloff 2016-05-15 11:23:27 -04:00
parent 2d0f9f01d5
commit bfe04bdd15
18 changed files with 162 additions and 152 deletions

View File

@ -28,8 +28,8 @@ export
plot,
plot!,
subplot,
subplot!,
# subplot,
# subplot!,
current,
default,
@ -177,7 +177,7 @@ include("themes.jl")
include("plot.jl")
include("series_args.jl")
include("series_new.jl")
include("subplot.jl")
# include("subplot.jl")
include("layouts.jl")
include("recipes.jl")
include("animation.jl")

View File

@ -52,6 +52,7 @@ subplot(pkg::AbstractBackend; kw...) = error("subplot($pkg; k
subplot!(pkg::AbstractBackend, subplt::Subplot; kw...) = error("subplot!($pkg, subplt; kw...) is not implemented")
# don't do anything as a default
_create_backend_figure(plt::Plot) = nothing
_before_add_series(plt::Plot) = nothing
_add_annotations{X,Y,V}(plt::Plot, anns::AVec{Tuple{X,Y,V}}) = nothing
_update_plot_pos_size(plt::AbstractPlot, d::KW) = nothing

View File

@ -133,23 +133,24 @@ end
# ---------------------------------------------------------------------------
function _create_plot(pkg::BokehBackend, d::KW)
# function _create_plot(pkg::BokehBackend, d::KW)
function _create_backend_figure(plt::Plot{BokehBackend})
# TODO: create the window/canvas/context that is the plot within the backend (call it `o`)
# TODO: initialize the plot... title, xlabel, bgcolor, etc
datacolumns = Bokeh.BokehDataSet[]
tools = Bokeh.tools()
filename = tempname() * ".html"
title = d[:title]
w, h = d[:size]
xaxis_type = d[:xscale] == :log10 ? :log : :auto
yaxis_type = d[:yscale] == :log10 ? :log : :auto
# legend = d[:legend] ? xxxx : nothing
title = plt.plotargs[:title]
w, h = plt.plotargs[:size]
xaxis_type = plt.plotargs[:xscale] == :log10 ? :log : :auto
yaxis_type = plt.plotargs[:yscale] == :log10 ? :log : :auto
# legend = plt.plotargs[:legend] ? xxxx : nothing
legend = nothing
extra_args = KW() # TODO: we'll put extra settings (xlim, etc) here
bplt = Bokeh.Plot(datacolumns, tools, filename, title, w, h, xaxis_type, yaxis_type, legend) #, extra_args)
Bokeh.Plot(datacolumns, tools, filename, title, w, h, xaxis_type, yaxis_type, legend) #, extra_args)
Plot(bplt, pkg, 0, d, KW[])
# Plot(bplt, pkg, 0, d, KW[])
end

View File

@ -570,9 +570,12 @@ end
# ---------------------------------------------------------------------------
# create a blank Gadfly.Plot object
function _create_plot(pkg::GadflyBackend, d::KW)
gplt = createGadflyPlotObject(d)
Plot(gplt, pkg, 0, d, KW[])
# function _create_plot(pkg::GadflyBackend, d::KW)
# gplt = createGadflyPlotObject(d)
# Plot(gplt, pkg, 0, d, KW[])
# end
function _create_backend_figure(plt::Plot{GadflyBackend})
createGadflyPlotObject(plt.plotargs)
end

View File

@ -82,14 +82,16 @@ immutable GLScreenWrapper
window
end
function _create_plot(pkg::GLVisualizeBackend, d::KW)
# TODO: create the window/canvas/context that is the plot within the backend (call it `o`)
# function _create_plot(pkg::GLVisualizeBackend, d::KW)
function _create_backend_figure(plt::Plot{GLVisualizeBackend})
# TODO: create the window/canvas/context that is the plot within the backend
# TODO: initialize the plot... title, xlabel, bgcolor, etc
# TODO: this should be moved to the display method?
w=GLVisualize.glscreen()
@async GLVisualize.renderloop(w)
Plot(GLScreenWrapper(w), pkg, 0, d, KW[])
GLScreenWrapper(w)
# Plot(GLScreenWrapper(w), pkg, 0, d, KW[])
end

View File

@ -848,9 +848,9 @@ function gr_display(subplt::Subplot{GRBackend})
end
end
function _create_plot(pkg::GRBackend, d::KW)
Plot(nothing, pkg, 0, d, KW[])
end
# function _create_plot(pkg::GRBackend, d::KW)
# Plot(nothing, pkg, 0, d, KW[])
# end
function _add_series(::GRBackend, plt::Plot, d::KW)
push!(plt.seriesargs, d)

View File

@ -29,12 +29,15 @@ end
# create a blank Gadfly.Plot object
function _create_plot(pkg::ImmerseBackend, d::KW)
# create the underlying Gadfly.Plot object
gplt = createGadflyPlotObject(d)
# save both the Immerse.Figure and the Gadfly.Plot
Plot((nothing,gplt), pkg, 0, d, KW[])
# function _create_plot(pkg::ImmerseBackend, d::KW)
# # create the underlying Gadfly.Plot object
# gplt = createGadflyPlotObject(d)
#
# # save both the Immerse.Figure and the Gadfly.Plot
# Plot((nothing,gplt), pkg, 0, d, KW[])
# end
function _create_backend_figure(plt::Plot{ImmerseBackend})
(nothing, createGadflyPlotObject(plt.plotargs))
end

View File

@ -229,11 +229,11 @@ end
# ---------------------------------------------------------------------------
function _create_plot(pkg::PGFPlotsBackend, d::KW)
# TODO: create the window/canvas/context that is the plot within the backend (call it `o`)
# TODO: initialize the plot... title, xlabel, bgcolor, etc
Plot(nothing, pkg, 0, d, KW[])
end
# function _create_plot(pkg::PGFPlotsBackend, d::KW)
# # TODO: create the window/canvas/context that is the plot within the backend (call it `o`)
# # TODO: initialize the plot... title, xlabel, bgcolor, etc
# Plot(nothing, pkg, 0, d, KW[])
# end
function _add_series(::PGFPlotsBackend, plt::Plot, d::KW)
@ -253,15 +253,15 @@ end
# ----------------------------------------------------------------
function _before_update_plot(plt::Plot{PGFPlotsBackend})
end
# function _before_update_plot(plt::Plot{PGFPlotsBackend})
# end
# TODO: override this to update plot items (title, xlabel, etc) after creation
function _update_plot(plt::Plot{PGFPlotsBackend}, d::KW)
end
function _update_plot_pos_size(plt::AbstractPlot{PGFPlotsBackend}, d::KW)
end
# function _update_plot_pos_size(plt::AbstractPlot{PGFPlotsBackend}, d::KW)
# end
# ----------------------------------------------------------------
@ -280,10 +280,10 @@ end
# ----------------------------------------------------------------
function _create_subplot(subplt::Subplot{PGFPlotsBackend}, isbefore::Bool)
# TODO: build the underlying Subplot object. this is where you might layout the panes within a GUI window, for example
true
end
# function _create_subplot(subplt::Subplot{PGFPlotsBackend}, isbefore::Bool)
# # TODO: build the underlying Subplot object. this is where you might layout the panes within a GUI window, for example
# true
# end
function _expand_limits(lims, plt::Plot{PGFPlotsBackend}, isx::Bool)
# TODO: call expand limits for each plot data

View File

@ -84,11 +84,11 @@ end
# ---------------------------------------------------------------------------
function _create_plot(pkg::PlotlyBackend, d::KW)
# TODO: create the window/canvas/context that is the plot within the backend (call it `o`)
# TODO: initialize the plot... title, xlabel, bgcolor, etc
Plot(nothing, pkg, 0, d, KW[])
end
# function _create_plot(pkg::PlotlyBackend, d::KW)
# # TODO: create the window/canvas/context that is the plot within the backend (call it `o`)
# # TODO: initialize the plot... title, xlabel, bgcolor, etc
# Plot(nothing, pkg, 0, d, KW[])
# end
function _add_series(::PlotlyBackend, plt::Plot, d::KW)

View File

@ -96,16 +96,20 @@ end
# ---------------------------------------------------------------------------
function _create_plot(pkg::PlotlyJSBackend, d::KW)
# TODO: create the window/canvas/context that is the plot within the backend (call it `o`)
# TODO: initialize the plot... title, xlabel, bgcolor, etc
# o = PlotlyJS.Plot(PlotlyJS.GenericTrace[], PlotlyJS.Layout(),
# Base.Random.uuid4(), PlotlyJS.ElectronDisplay())
# T = isijulia() ? PlotlyJS.JupyterPlot : PlotlyJS.ElectronPlot
# o = T(PlotlyJS.Plot())
o = PlotlyJS.plot()
# function _create_plot(pkg::PlotlyJSBackend, d::KW)
# # TODO: create the window/canvas/context that is the plot within the backend (call it `o`)
# # TODO: initialize the plot... title, xlabel, bgcolor, etc
# # o = PlotlyJS.Plot(PlotlyJS.GenericTrace[], PlotlyJS.Layout(),
# # Base.Random.uuid4(), PlotlyJS.ElectronDisplay())
# # T = isijulia() ? PlotlyJS.JupyterPlot : PlotlyJS.ElectronPlot
# # o = T(PlotlyJS.Plot())
# o = PlotlyJS.plot()
#
# Plot(o, pkg, 0, d, KW[])
# end
Plot(o, pkg, 0, d, KW[])
function _create_backend_figure(plt::Plot{PlotlyJSBackend})
PlotlyJS.plot()
end

View File

@ -315,23 +315,19 @@ end
# ---------------------------------------------------------------------------
function _create_plot(pkg::PyPlotBackend, d::KW)
# create the figure
# standalone plots will create a figure, but not if part of a subplot (do it later)
if haskey(d, :subplot)
function _create_backend_figure(plt::Plot)
if haskey(plt.plotargs, :subplot)
wrap = nothing
else
wrap = PyPlotAxisWrapper(nothing, nothing, pyplot_figure(d), [])
pyplot_3d_setup!(wrap, d)
if get(d, :polar, false)
wrap = PyPlotAxisWrapper(nothing, nothing, pyplot_figure(plt.plotargs), [])
pyplot_3d_setup!(wrap, plt.plotargs)
if get(plt.plotargs, :polar, false)
push!(wrap.kwargs, (:polar, true))
end
end
plt = Plot(wrap, pkg, 0, d, KW[])
plt
wrap
# plt = Plot(wrap, pkg, 0, plt.plotargs, KW[])
# plt
end
# ---------------------------------------------------------------------------
@ -1023,56 +1019,56 @@ end
# -----------------------------------------------------------------
function _create_subplot(subplt::Subplot{PyPlotBackend}, isbefore::Bool)
l = subplt.layout
plotargs = getplotargs(subplt, 1)
fig = pyplot_figure(plotargs)
nr = nrows(l)
for (i,(r,c)) in enumerate(l)
# add the plot to the figure
nc = ncols(l, r)
fakeidx = (r-1) * nc + c
ax = fig[:add_subplot](nr, nc, fakeidx)
subplt.plts[i].o = PyPlotAxisWrapper(ax, nothing, fig, [])
pyplot_3d_setup!(subplt.plts[i].o, plotargs)
end
subplt.o = PyPlotAxisWrapper(nothing, nothing, fig, [])
pyplot_3d_setup!(subplt.o, plotargs)
true
end
# this will be called internally, when creating a subplot from existing plots
# NOTE: if I ever need to "Rebuild a "ubplot from individual Plot's"... this is what I should use!
function subplot(plts::AVec{Plot{PyPlotBackend}}, layout::SubplotLayout, d::KW)
validateSubplotSupported()
p = length(layout)
n = sum([plt.n for plt in plts])
pkg = PyPlotBackend()
newplts = Plot{PyPlotBackend}[begin
plt.plotargs[:subplot] = true
_create_plot(pkg, plt.plotargs)
end for plt in plts]
subplt = Subplot(nothing, newplts, PyPlotBackend(), p, n, layout, d, true, false, false, (r,c) -> (nothing,nothing))
_preprocess_subplot(subplt, d)
_create_subplot(subplt, true)
for (i,plt) in enumerate(plts)
for seriesargs in plt.seriesargs
_add_series_subplot(newplts[i], seriesargs)
end
end
_postprocess_subplot(subplt, d)
subplt
end
# function _create_subplot(subplt::Subplot{PyPlotBackend}, isbefore::Bool)
# l = subplt.layout
# plotargs = getplotargs(subplt, 1)
# fig = pyplot_figure(plotargs)
#
# nr = nrows(l)
# for (i,(r,c)) in enumerate(l)
# # add the plot to the figure
# nc = ncols(l, r)
# fakeidx = (r-1) * nc + c
# ax = fig[:add_subplot](nr, nc, fakeidx)
#
# subplt.plts[i].o = PyPlotAxisWrapper(ax, nothing, fig, [])
# pyplot_3d_setup!(subplt.plts[i].o, plotargs)
# end
#
# subplt.o = PyPlotAxisWrapper(nothing, nothing, fig, [])
# pyplot_3d_setup!(subplt.o, plotargs)
# true
# end
#
# # this will be called internally, when creating a subplot from existing plots
# # NOTE: if I ever need to "Rebuild a "ubplot from individual Plot's"... this is what I should use!
# function subplot(plts::AVec{Plot{PyPlotBackend}}, layout::SubplotLayout, d::KW)
# validateSubplotSupported()
#
# p = length(layout)
# n = sum([plt.n for plt in plts])
#
# pkg = PyPlotBackend()
# newplts = Plot{PyPlotBackend}[begin
# plt.plotargs[:subplot] = true
# _create_plot(pkg, plt.plotargs)
# end for plt in plts]
#
# subplt = Subplot(nothing, newplts, PyPlotBackend(), p, n, layout, d, true, false, false, (r,c) -> (nothing,nothing))
#
# _preprocess_subplot(subplt, d)
# _create_subplot(subplt, true)
#
# for (i,plt) in enumerate(plts)
# for seriesargs in plt.seriesargs
# _add_series_subplot(newplts[i], seriesargs)
# end
# end
#
# _postprocess_subplot(subplt, d)
#
# subplt
# end
function _remove_axis(plt::Plot{PyPlotBackend}, isx::Bool)
@ -1144,16 +1140,16 @@ function finalizePlot(plt::Plot{PyPlotBackend})
PyPlot.draw()
end
function finalizePlot(subplt::Subplot{PyPlotBackend})
fig = subplt.o.fig
for (i,plt) in enumerate(subplt.plts)
ax = getLeftAxis(plt)
addPyPlotLegend(plt, ax)
updateAxisColors(ax, plt.plotargs)
end
# fig[:tight_layout]()
PyPlot.draw()
end
# function finalizePlot(subplt::Subplot{PyPlotBackend})
# fig = subplt.o.fig
# for (i,plt) in enumerate(subplt.plts)
# ax = getLeftAxis(plt)
# addPyPlotLegend(plt, ax)
# updateAxisColors(ax, plt.plotargs)
# end
# # fig[:tight_layout]()
# PyPlot.draw()
# end
# -----------------------------------------------------------------

View File

@ -128,12 +128,13 @@ function adjustQwtKeywords(plt::Plot{QwtBackend}, iscreating::Bool; kw...)
d
end
function _create_plot(pkg::QwtBackend, d::KW)
fixcolors(d)
dumpdict(d,"\n\n!!! plot")
o = Qwt.plot(zeros(0,0); d..., show=false)
plt = Plot(o, pkg, 0, d, KW[])
plt
# function _create_plot(pkg::QwtBackend, d::KW)
function _create_backend_figure(plt::Plot{QwtBackend})
fixcolors(plt.plotargs)
dumpdict(plt.plotargs,"\n\n!!! plot")
o = Qwt.plot(zeros(0,0); plt.plotargs..., show=false)
# plt = Plot(o, pkg, 0, d, KW[])
# plt
end
function _add_series(::QwtBackend, plt::Plot, d::KW)

View File

@ -14,10 +14,9 @@ end
# ---------------------------------------------------------------------------
function _create_plot(pkg::[PkgName]AbstractBackend, d::KW)
# TODO: create the window/canvas/context that is the plot within the backend (call it `o`)
# TODO: initialize the plot... title, xlabel, bgcolor, etc
Plot(nothing, pkg, 0, d, KW[])
function _create_backend_figure(plt::Plot{[PkgName]Backend})
# TODO: create the window/figure for this backend
nothing
end

View File

@ -181,15 +181,17 @@ end
# -------------------------------
function _create_plot(pkg::UnicodePlotsBackend, d::KW)
plt = Plot(nothing, pkg, 0, d, KW[])
# function _create_plot(pkg::UnicodePlotsBackend, d::KW)
# plt = Plot(nothing, pkg, 0, d, KW[])
function _create_backend_figure(plt::Plot{UnicodePlotsBackend})
# do we want to give a new default size?
if !haskey(plt.plotargs, :size) || plt.plotargs[:size] == _plotDefaults[:size]
plt.plotargs[:size] = (60,20)
end
nothing
plt
# plt
end
function _add_series(::UnicodePlotsBackend, plt::Plot, d::KW)

View File

@ -102,11 +102,12 @@ end
# ---------------------------------------------------------------------------
function _create_plot(pkg::WinstonBackend, d::KW)
wplt = Winston.FramedPlot(title = d[:title], xlabel = d[:xlabel], ylabel = d[:ylabel])
Plot(wplt, pkg, 0, d, KW[])
function _create_backend_figure(plt::Plot{WinstonBackend})
Winston.FramedPlot(
title = plt.plotargs[:title],
xlabel = plt.plotargs[:xlabel],
ylabel = plt.plotargs[:ylabel]
)
end
copy_remove(d::KW, s::Symbol) = delete!(copy(d), s)

View File

@ -23,7 +23,6 @@ vertices(shape::Shape) = collect(zip(shape.x, shape.y))
function shape_coords(shape::Shape)
# unzip(shape.vertices)
shape.x, shape.y
end
@ -31,14 +30,10 @@ function shape_coords(shapes::AVec{Shape})
length(shapes) == 0 && return zeros(0), zeros(0)
xs = map(get_xs, shapes)
ys = map(get_ys, shapes)
# x, y = shapes[1].x, shapes[1].y #unzip(shapes[1].vertices)
x, y = map(copy, shape_coords(shapes[1]))
for shape in shapes[2:end]
# tmpx, tmpy = unzip(shape.vertices)
nanappend!(x, shape.x)
nanappend!(y, shape.y)
# x = vcat(x, NaN, tmpx)
# y = vcat(y, NaN, tmpy)
end
x, y
end
@ -57,9 +52,6 @@ function weave(x,y; ordering = Vector[x,y])
try
push!(ret, shift!(o))
end
# try
# push!(ret, shift!(y))
# end
end
done = isempty(x) && isempty(y)
end

View File

@ -48,7 +48,10 @@ function plot(args...; kw...)
preprocessArgs!(d)
plotargs = merge(d, getPlotArgs(pkg, d, 1))
plt = _create_plot(pkg, plotargs) # create a new, blank plot
# plt = _create_plot(pkg, plotargs) # create a new, blank plot
plt = Plot(nothing, pkg, 0, plt.plotargs, KW[])
plt.o = _create_backend_figure(plt)
# now update the plot
_plot!(plt, d, args...)

View File

@ -1,4 +1,6 @@
### WARNING: this file is deprecated ###
# ------------------------------------------------------------
Base.string(subplt::Subplot) = "Subplot{$(subplt.backend) p=$(subplt.p) n=$(subplt.n)}"