From b64677e14acd2b2339cf912333808e7d1f19e6cc Mon Sep 17 00:00:00 2001 From: Thomas Breloff Date: Fri, 22 Apr 2016 08:56:54 -0400 Subject: [PATCH] changed kw splatting to passing in KW: _add_series and _create_plot; removed plotly tests --- src/backends/bokeh.jl | 12 ++-------- src/backends/gadfly.jl | 6 ++--- src/backends/glvisualize.jl | 6 ++--- src/backends/gr.jl | 6 ++--- src/backends/immerse.jl | 7 ++---- src/backends/pgfplots.jl | 6 ++--- src/backends/plotly.jl | 6 ++--- src/backends/plotlyjs.jl | 6 ++--- src/backends/pyplot.jl | 10 ++++---- src/backends/qwt.jl | 7 +++--- src/backends/template.jl | 6 ++--- src/backends/unicodeplots.jl | 7 +++--- src/backends/winston.jl | 7 ++---- src/plot.jl | 4 ++-- src/subplot.jl | 44 ++---------------------------------- test/runtests.jl | 3 ++- 16 files changed, 36 insertions(+), 107 deletions(-) diff --git a/src/backends/bokeh.jl b/src/backends/bokeh.jl index 672f24e9..e518a554 100644 --- a/src/backends/bokeh.jl +++ b/src/backends/bokeh.jl @@ -64,11 +64,7 @@ end # --------------------------------------------------------------------------- -function _create_plot(pkg::BokehBackend; kw...) - d = KW(kw) - - # dumpdict(d, "plot", true) - +function _create_plot(pkg::BokehBackend, 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 @@ -88,11 +84,7 @@ function _create_plot(pkg::BokehBackend; kw...) end -function _add_series(::BokehBackend, plt::Plot; kw...) - d = KW(kw) - - # dumpdict(d, "plot!", true) - +function _add_series(::BokehBackend, plt::Plot, d::KW) bdata = Dict{Symbol, Vector}(:x => collect(d[:x]), :y => collect(d[:y])) glyph = Bokeh.Bokehjs.Glyph( diff --git a/src/backends/gadfly.jl b/src/backends/gadfly.jl index 27fd275d..4028c86d 100644 --- a/src/backends/gadfly.jl +++ b/src/backends/gadfly.jl @@ -523,22 +523,20 @@ end # --------------------------------------------------------------------------- # create a blank Gadfly.Plot object -function _create_plot(pkg::GadflyBackend; kw...) - d = KW(kw) +function _create_plot(pkg::GadflyBackend, d::KW) gplt = createGadflyPlotObject(d) Plot(gplt, pkg, 0, d, KW[]) end # plot one data series -function _add_series(::GadflyBackend, plt::Plot; kw...) +function _add_series(::GadflyBackend, plt::Plot, d::KW) # first clear out the temporary layer gplt = getGadflyContext(plt) if gplt.layers[1].geom.tag == :remove gplt.layers = gplt.layers[2:end] end - d = KW(kw) addGadflySeries!(plt, d) push!(plt.seriesargs, d) plt diff --git a/src/backends/glvisualize.jl b/src/backends/glvisualize.jl index e40ecf59..aea9c176 100644 --- a/src/backends/glvisualize.jl +++ b/src/backends/glvisualize.jl @@ -15,8 +15,7 @@ immutable GLScreenWrapper window end -function _create_plot(pkg::GLVisualizeBackend; kw...) - d = KW(kw) +function _create_plot(pkg::GLVisualizeBackend, 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 @@ -27,8 +26,7 @@ function _create_plot(pkg::GLVisualizeBackend; kw...) end -function _add_series(::GLVisualizeBackend, plt::Plot; kw...) - d = KW(kw) +function _add_series(::GLVisualizeBackend, plt::Plot, d::KW) # TODO: add one series to the underlying package push!(plt.seriesargs, d) # TODO: this should be moved to the display method? diff --git a/src/backends/gr.jl b/src/backends/gr.jl index 9f073864..74ecfa4c 100644 --- a/src/backends/gr.jl +++ b/src/backends/gr.jl @@ -701,13 +701,11 @@ function gr_display(subplt::Subplot{GRBackend}) end end -function _create_plot(pkg::GRBackend; kw...) - d = KW(kw) +function _create_plot(pkg::GRBackend, d::KW) Plot(nothing, pkg, 0, d, KW[]) end -function _add_series(::GRBackend, plt::Plot; kw...) - d = KW(kw) +function _add_series(::GRBackend, plt::Plot, d::KW) push!(plt.seriesargs, d) plt end diff --git a/src/backends/immerse.jl b/src/backends/immerse.jl index 0352534b..23c76361 100644 --- a/src/backends/immerse.jl +++ b/src/backends/immerse.jl @@ -19,9 +19,7 @@ end # create a blank Gadfly.Plot object -function _create_plot(pkg::ImmerseBackend; kw...) - d = KW(kw) - +function _create_plot(pkg::ImmerseBackend, d::KW) # create the underlying Gadfly.Plot object gplt = createGadflyPlotObject(d) @@ -31,8 +29,7 @@ end # plot one data series -function _add_series(::ImmerseBackend, plt::Plot; kw...) - d = KW(kw) +function _add_series(::ImmerseBackend, plt::Plot, d::KW) addGadflySeries!(plt, d) push!(plt.seriesargs, d) plt diff --git a/src/backends/pgfplots.jl b/src/backends/pgfplots.jl index b9ddcd03..09e0f545 100644 --- a/src/backends/pgfplots.jl +++ b/src/backends/pgfplots.jl @@ -12,16 +12,14 @@ end # --------------------------------------------------------------------------- -function _create_plot(pkg::PGFPlotsBackend; kw...) - d = KW(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: initialize the plot... title, xlabel, bgcolor, etc Plot(nothing, pkg, 0, d, KW[]) end -function _add_series(::PGFPlotsBackend, plt::Plot; kw...) - d = KW(kw) +function _add_series(::PGFPlotsBackend, plt::Plot, d::KW) # TODO: add one series to the underlying package push!(plt.seriesargs, d) plt diff --git a/src/backends/plotly.jl b/src/backends/plotly.jl index ef6cda8c..5150fe3a 100644 --- a/src/backends/plotly.jl +++ b/src/backends/plotly.jl @@ -37,16 +37,14 @@ end # --------------------------------------------------------------------------- -function _create_plot(pkg::PlotlyBackend; kw...) - d = KW(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: initialize the plot... title, xlabel, bgcolor, etc Plot(nothing, pkg, 0, d, KW[]) end -function _add_series(::PlotlyBackend, plt::Plot; kw...) - d = KW(kw) +function _add_series(::PlotlyBackend, plt::Plot, d::KW) # TODO: add one series to the underlying package push!(plt.seriesargs, d) plt diff --git a/src/backends/plotlyjs.jl b/src/backends/plotlyjs.jl index 82287dc6..0277ffd5 100644 --- a/src/backends/plotlyjs.jl +++ b/src/backends/plotlyjs.jl @@ -20,8 +20,7 @@ end # --------------------------------------------------------------------------- -function _create_plot(pkg::PlotlyJSBackend; kw...) - d = KW(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: initialize the plot... title, xlabel, bgcolor, etc # o = PlotlyJS.Plot(PlotlyJS.GenericTrace[], PlotlyJS.Layout(), @@ -34,8 +33,7 @@ function _create_plot(pkg::PlotlyJSBackend; kw...) end -function _add_series(::PlotlyJSBackend, plt::Plot; kw...) - d = KW(kw) +function _add_series(::PlotlyJSBackend, plt::Plot, d::KW) syncplot = plt.o # add to the data array diff --git a/src/backends/pyplot.jl b/src/backends/pyplot.jl index 2f3b85e1..1b0f811b 100644 --- a/src/backends/pyplot.jl +++ b/src/backends/pyplot.jl @@ -257,10 +257,8 @@ end # --------------------------------------------------------------------------- -function _create_plot(pkg::PyPlotBackend; kw...) +function _create_plot(pkg::PyPlotBackend, d::KW) # create the figure - d = KW(kw) - # standalone plots will create a figure, but not if part of a subplot (do it later) if haskey(d, :subplot) wrap = nothing @@ -284,9 +282,8 @@ end # --------------------------------------------------------------------------- -function _add_series(pkg::PyPlotBackend, plt::Plot; kw...) - d = KW(kw) +function _add_series(pkg::PyPlotBackend, plt::Plot, d::KW) # 3D plots have a different underlying Axes object in PyPlot lt = d[:linetype] if lt in _3dTypes && isempty(plt.o.kwargs) @@ -743,7 +740,8 @@ function subplot(plts::AVec{Plot{PyPlotBackend}}, layout::SubplotLayout, d::KW) n = sum([plt.n for plt in plts]) pkg = PyPlotBackend() - newplts = Plot{PyPlotBackend}[_create_plot(pkg; subplot=true, plt.plotargs...) for plt in plts] + plt.plotargs[:subplot] = true + newplts = Plot{PyPlotBackend}[_create_plot(pkg, plt.plotargs) for plt in plts] subplt = Subplot(nothing, newplts, PyPlotBackend(), p, n, layout, d, true, false, false, (r,c) -> (nothing,nothing)) diff --git a/src/backends/qwt.jl b/src/backends/qwt.jl index cc7da44a..2728c8a5 100644 --- a/src/backends/qwt.jl +++ b/src/backends/qwt.jl @@ -77,8 +77,7 @@ function adjustQwtKeywords(plt::Plot{QwtBackend}, iscreating::Bool; kw...) d end -function _create_plot(pkg::QwtBackend; kw...) - d = KW(kw) +function _create_plot(pkg::QwtBackend, d::KW) fixcolors(d) dumpdict(d,"\n\n!!! plot") o = Qwt.plot(zeros(0,0); d..., show=false) @@ -86,8 +85,8 @@ function _create_plot(pkg::QwtBackend; kw...) plt end -function _add_series(::QwtBackend, plt::Plot; kw...) - d = adjustQwtKeywords(plt, false; kw...) +function _add_series(::QwtBackend, plt::Plot, d::KW) + d = adjustQwtKeywords(plt, false; d...) fixcolors(d) dumpdict(d,"\n\n!!! plot!") Qwt.oplot(plt.o; d...) diff --git a/src/backends/template.jl b/src/backends/template.jl index 90870fde..96282735 100644 --- a/src/backends/template.jl +++ b/src/backends/template.jl @@ -14,16 +14,14 @@ end # --------------------------------------------------------------------------- -function _create_plot(pkg::[PkgName]AbstractBackend; kw...) - d = KW(kw) +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[]) end -function _add_series(::[PkgName]AbstractBackend, plt::Plot; kw...) - d = KW(kw) +function _add_series(::[PkgName]AbstractBackend, plt::Plot, d::KW) # TODO: add one series to the underlying package push!(plt.seriesargs, d) plt diff --git a/src/backends/unicodeplots.jl b/src/backends/unicodeplots.jl index 8c3b5d2d..ce5c3a99 100644 --- a/src/backends/unicodeplots.jl +++ b/src/backends/unicodeplots.jl @@ -119,8 +119,8 @@ end # ------------------------------- -function _create_plot(pkg::UnicodePlotsBackend; kw...) - plt = Plot(nothing, pkg, 0, KW(kw), KW[]) +function _create_plot(pkg::UnicodePlotsBackend, d::KW) + plt = Plot(nothing, pkg, 0, d, KW[]) # do we want to give a new default size? if !haskey(plt.plotargs, :size) || plt.plotargs[:size] == _plotDefaults[:size] @@ -130,8 +130,7 @@ function _create_plot(pkg::UnicodePlotsBackend; kw...) plt end -function _add_series(::UnicodePlotsBackend, plt::Plot; kw...) - d = KW(kw) +function _add_series(::UnicodePlotsBackend, plt::Plot, d::KW) if d[:linetype] in (:sticks, :bar) d = barHack(; d...) elseif d[:linetype] == :hist diff --git a/src/backends/winston.jl b/src/backends/winston.jl index fd55fd8f..dc9fc138 100644 --- a/src/backends/winston.jl +++ b/src/backends/winston.jl @@ -40,8 +40,7 @@ end # --------------------------------------------------------------------------- -function _create_plot(pkg::WinstonBackend; kw...) - d = KW(kw) +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[]) @@ -64,9 +63,7 @@ function getWinstonItems(plt::Plot) window, canvas, wplt end -function _add_series(::WinstonBackend, plt::Plot; kw...) - d = KW(kw) - +function _add_series(::WinstonBackend, plt::Plot, d::KW) window, canvas, wplt = getWinstonItems(plt) # until we call it normally, do the hack diff --git a/src/plot.jl b/src/plot.jl index d7b2cfba..7594533a 100644 --- a/src/plot.jl +++ b/src/plot.jl @@ -50,7 +50,7 @@ function plot(args...; kw...) plotargs = merge(d, getPlotArgs(pkg, d, 1)) dumpdict(plotargs, "Plot args") - plt = _create_plot(pkg; plotargs...) # create a new, blank plot + plt = _create_plot(pkg, plotargs) # create a new, blank plot delete!(d, :background_color) plot!(plt, args...; d...) # add to it @@ -186,7 +186,7 @@ function _add_series(plt::Plot, d::KW, ::Void, args...; dumpdict(di, "Series $i") - _add_series(plt.backend, plt; di...) + _add_series(plt.backend, plt, di) end end diff --git a/src/subplot.jl b/src/subplot.jl index 1f59a702..554cdd2c 100644 --- a/src/subplot.jl +++ b/src/subplot.jl @@ -64,7 +64,7 @@ function subplot(args...; kw...) di = getPlotArgs(pkg, d, i) di[:subplot] = true dumpdict(di, "Plot args (subplot $i)") - push!(plts, _create_plot(pkg; di...)) + push!(plts, _create_plot(pkg, di)) end # create the object and do the plotting @@ -200,53 +200,13 @@ function subplot!(subplt::Subplot, args...; kw...) subplt.initialized = _create_subplot(subplt, true) end - # # handle grouping - # group = get(d, :group, nothing) - # if group == nothing - # groupargs = [] - # else - # groupargs = [extractGroupArgs(d[:group], args...)] - # delete!(d, :group) - # end - groupby = if haskey(d, :group) extractGroupArgs(d[:group], args...) else nothing end - # dumpdict(d, "after", true) - # @show groupby map(typeof, args) _add_series_subplot(subplt, d, groupby, args...) - - # process_inputs(subplt, d, groupargs..., args...) - # - # # TODO: filter the data - # - # kwList, xmeta, ymeta = build_series_args(subplt, d) - # # kwList, xmeta, ymeta = build_series_args(subplt, groupargs..., args...; d...) - # - # # TODO: something useful with meta info? - # - # for (i,di) in enumerate(kwList) - # - # subplt.n += 1 - # plt = getplot(subplt) - # plt.n += 1 - # - # # cleanup the dictionary that we pass into the plot! command - # di[:show] = false - # di[:subplot] = true - # for k in (:title, :xlabel, :xticks, :xlims, :xscale, :xflip, - # :ylabel, :yticks, :ylims, :yscale, :yflip) - # delete!(di, k) - # end - # dumpdict(di, "subplot! kwList $i") - # dumpdict(plt.plotargs, "plt.plotargs before plotting") - # - # _add_series_subplot(plt; di...) - # end - _postprocess_subplot(subplt, d) # show it automatically? @@ -269,7 +229,7 @@ function _add_series_subplot(plt::Plot, d::KW) setTicksFromStringVector(d, d, :y, :yticks) # this is the actual call to the backend - _add_series(plt.backend, plt; d...) + _add_series(plt.backend, plt, d) _add_annotations(plt, d) warnOnUnsupportedScales(plt.backend, d) diff --git a/test/runtests.jl b/test/runtests.jl index 137a8dd6..cc0b0fca 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -37,7 +37,8 @@ facts("Plotly") do @fact plotly() --> Plots.PlotlyBackend() @fact backend() --> Plots.PlotlyBackend() - image_comparison_facts(:plotly, only=[1,3,4,7,8,9,10,11,12,14,15,20,22,23,27], eps=img_eps) + # # until png generation is reliable on OSX, just test on linux + # @linux_only image_comparison_facts(:plotly, only=[1,3,4,7,8,9,10,11,12,14,15,20,22,23,27], eps=img_eps) end FactCheck.exitstatus()