diff --git a/src/Plots.jl b/src/Plots.jl index 899de166..6746edc1 100644 --- a/src/Plots.jl +++ b/src/Plots.jl @@ -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") diff --git a/src/backends.jl b/src/backends.jl index 8d76e2c8..cb5ccdad 100644 --- a/src/backends.jl +++ b/src/backends.jl @@ -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 diff --git a/src/backends/bokeh.jl b/src/backends/bokeh.jl index 39048d3b..91044421 100644 --- a/src/backends/bokeh.jl +++ b/src/backends/bokeh.jl @@ -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 diff --git a/src/backends/gadfly.jl b/src/backends/gadfly.jl index 8f7756e8..b4f806e4 100644 --- a/src/backends/gadfly.jl +++ b/src/backends/gadfly.jl @@ -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 diff --git a/src/backends/glvisualize.jl b/src/backends/glvisualize.jl index b77667c7..832262cd 100644 --- a/src/backends/glvisualize.jl +++ b/src/backends/glvisualize.jl @@ -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 diff --git a/src/backends/gr.jl b/src/backends/gr.jl index 9df82384..056cec38 100644 --- a/src/backends/gr.jl +++ b/src/backends/gr.jl @@ -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) diff --git a/src/backends/immerse.jl b/src/backends/immerse.jl index a896b5ce..14d5ac0a 100644 --- a/src/backends/immerse.jl +++ b/src/backends/immerse.jl @@ -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 diff --git a/src/backends/pgfplots.jl b/src/backends/pgfplots.jl index acb8306b..ee6072da 100644 --- a/src/backends/pgfplots.jl +++ b/src/backends/pgfplots.jl @@ -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 diff --git a/src/backends/plotly.jl b/src/backends/plotly.jl index 7c4466c5..4eb0d0d8 100644 --- a/src/backends/plotly.jl +++ b/src/backends/plotly.jl @@ -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) diff --git a/src/backends/plotlyjs.jl b/src/backends/plotlyjs.jl index 8a9a7b5a..f1d0c449 100644 --- a/src/backends/plotlyjs.jl +++ b/src/backends/plotlyjs.jl @@ -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 diff --git a/src/backends/pyplot.jl b/src/backends/pyplot.jl index 3b81e493..0eceaa06 100644 --- a/src/backends/pyplot.jl +++ b/src/backends/pyplot.jl @@ -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 # ----------------------------------------------------------------- diff --git a/src/backends/qwt.jl b/src/backends/qwt.jl index 2fa0cd9b..4cf82e2d 100644 --- a/src/backends/qwt.jl +++ b/src/backends/qwt.jl @@ -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) diff --git a/src/backends/template.jl b/src/backends/template.jl index 96282735..203f0aad 100644 --- a/src/backends/template.jl +++ b/src/backends/template.jl @@ -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 diff --git a/src/backends/unicodeplots.jl b/src/backends/unicodeplots.jl index 5cf26fda..f50d741a 100644 --- a/src/backends/unicodeplots.jl +++ b/src/backends/unicodeplots.jl @@ -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) diff --git a/src/backends/winston.jl b/src/backends/winston.jl index fe6222e7..29347e81 100644 --- a/src/backends/winston.jl +++ b/src/backends/winston.jl @@ -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) diff --git a/src/components.jl b/src/components.jl index 969ccda2..84867249 100644 --- a/src/components.jl +++ b/src/components.jl @@ -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 diff --git a/src/plot.jl b/src/plot.jl index 8b77a3f6..e2305a6f 100644 --- a/src/plot.jl +++ b/src/plot.jl @@ -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...) diff --git a/src/subplot.jl b/src/subplot.jl index 34e2035c..67baa993 100644 --- a/src/subplot.jl +++ b/src/subplot.jl @@ -1,4 +1,6 @@ +### WARNING: this file is deprecated ### + # ------------------------------------------------------------ Base.string(subplt::Subplot) = "Subplot{$(subplt.backend) p=$(subplt.p) n=$(subplt.n)}"