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,
plot!, plot!,
subplot, # subplot,
subplot!, # subplot!,
current, current,
default, default,
@ -177,7 +177,7 @@ include("themes.jl")
include("plot.jl") include("plot.jl")
include("series_args.jl") include("series_args.jl")
include("series_new.jl") include("series_new.jl")
include("subplot.jl") # include("subplot.jl")
include("layouts.jl") include("layouts.jl")
include("recipes.jl") include("recipes.jl")
include("animation.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") subplot!(pkg::AbstractBackend, subplt::Subplot; kw...) = error("subplot!($pkg, subplt; kw...) is not implemented")
# don't do anything as a default # don't do anything as a default
_create_backend_figure(plt::Plot) = nothing
_before_add_series(plt::Plot) = nothing _before_add_series(plt::Plot) = nothing
_add_annotations{X,Y,V}(plt::Plot, anns::AVec{Tuple{X,Y,V}}) = nothing _add_annotations{X,Y,V}(plt::Plot, anns::AVec{Tuple{X,Y,V}}) = nothing
_update_plot_pos_size(plt::AbstractPlot, d::KW) = 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: create the window/canvas/context that is the plot within the backend (call it `o`)
# TODO: initialize the plot... title, xlabel, bgcolor, etc # TODO: initialize the plot... title, xlabel, bgcolor, etc
datacolumns = Bokeh.BokehDataSet[] datacolumns = Bokeh.BokehDataSet[]
tools = Bokeh.tools() tools = Bokeh.tools()
filename = tempname() * ".html" filename = tempname() * ".html"
title = d[:title] title = plt.plotargs[:title]
w, h = d[:size] w, h = plt.plotargs[:size]
xaxis_type = d[:xscale] == :log10 ? :log : :auto xaxis_type = plt.plotargs[:xscale] == :log10 ? :log : :auto
yaxis_type = d[:yscale] == :log10 ? :log : :auto yaxis_type = plt.plotargs[:yscale] == :log10 ? :log : :auto
# legend = d[:legend] ? xxxx : nothing # legend = plt.plotargs[:legend] ? xxxx : nothing
legend = nothing legend = nothing
extra_args = KW() # TODO: we'll put extra settings (xlim, etc) here 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 end

View File

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

View File

@ -82,14 +82,16 @@ immutable GLScreenWrapper
window window
end end
function _create_plot(pkg::GLVisualizeBackend, d::KW) # 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_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: initialize the plot... title, xlabel, bgcolor, etc
# TODO: this should be moved to the display method? # TODO: this should be moved to the display method?
w=GLVisualize.glscreen() w=GLVisualize.glscreen()
@async GLVisualize.renderloop(w) @async GLVisualize.renderloop(w)
Plot(GLScreenWrapper(w), pkg, 0, d, KW[]) GLScreenWrapper(w)
# Plot(GLScreenWrapper(w), pkg, 0, d, KW[])
end end

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -102,11 +102,12 @@ end
# --------------------------------------------------------------------------- # ---------------------------------------------------------------------------
function _create_backend_figure(plt::Plot{WinstonBackend})
function _create_plot(pkg::WinstonBackend, d::KW) Winston.FramedPlot(
wplt = Winston.FramedPlot(title = d[:title], xlabel = d[:xlabel], ylabel = d[:ylabel]) title = plt.plotargs[:title],
xlabel = plt.plotargs[:xlabel],
Plot(wplt, pkg, 0, d, KW[]) ylabel = plt.plotargs[:ylabel]
)
end end
copy_remove(d::KW, s::Symbol) = delete!(copy(d), s) 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) function shape_coords(shape::Shape)
# unzip(shape.vertices)
shape.x, shape.y shape.x, shape.y
end end
@ -31,14 +30,10 @@ function shape_coords(shapes::AVec{Shape})
length(shapes) == 0 && return zeros(0), zeros(0) length(shapes) == 0 && return zeros(0), zeros(0)
xs = map(get_xs, shapes) xs = map(get_xs, shapes)
ys = map(get_ys, 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])) x, y = map(copy, shape_coords(shapes[1]))
for shape in shapes[2:end] for shape in shapes[2:end]
# tmpx, tmpy = unzip(shape.vertices)
nanappend!(x, shape.x) nanappend!(x, shape.x)
nanappend!(y, shape.y) nanappend!(y, shape.y)
# x = vcat(x, NaN, tmpx)
# y = vcat(y, NaN, tmpy)
end end
x, y x, y
end end
@ -57,9 +52,6 @@ function weave(x,y; ordering = Vector[x,y])
try try
push!(ret, shift!(o)) push!(ret, shift!(o))
end end
# try
# push!(ret, shift!(y))
# end
end end
done = isempty(x) && isempty(y) done = isempty(x) && isempty(y)
end end

View File

@ -48,7 +48,10 @@ function plot(args...; kw...)
preprocessArgs!(d) preprocessArgs!(d)
plotargs = merge(d, getPlotArgs(pkg, d, 1)) 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 # now update the plot
_plot!(plt, d, args...) _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)}" Base.string(subplt::Subplot) = "Subplot{$(subplt.backend) p=$(subplt.p) n=$(subplt.n)}"