changed kw splatting to passing in KW: _add_series and _create_plot; removed plotly tests

This commit is contained in:
Thomas Breloff 2016-04-22 08:56:54 -04:00
parent c910445634
commit b64677e14a
16 changed files with 36 additions and 107 deletions

View File

@ -64,11 +64,7 @@ end
# --------------------------------------------------------------------------- # ---------------------------------------------------------------------------
function _create_plot(pkg::BokehBackend; kw...) function _create_plot(pkg::BokehBackend, d::KW)
d = KW(kw)
# dumpdict(d, "plot", true)
# 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
@ -88,11 +84,7 @@ function _create_plot(pkg::BokehBackend; kw...)
end end
function _add_series(::BokehBackend, plt::Plot; kw...) function _add_series(::BokehBackend, plt::Plot, d::KW)
d = KW(kw)
# dumpdict(d, "plot!", true)
bdata = Dict{Symbol, Vector}(:x => collect(d[:x]), :y => collect(d[:y])) bdata = Dict{Symbol, Vector}(:x => collect(d[:x]), :y => collect(d[:y]))
glyph = Bokeh.Bokehjs.Glyph( glyph = Bokeh.Bokehjs.Glyph(

View File

@ -523,22 +523,20 @@ end
# --------------------------------------------------------------------------- # ---------------------------------------------------------------------------
# create a blank Gadfly.Plot object # create a blank Gadfly.Plot object
function _create_plot(pkg::GadflyBackend; kw...) function _create_plot(pkg::GadflyBackend, d::KW)
d = KW(kw)
gplt = createGadflyPlotObject(d) gplt = createGadflyPlotObject(d)
Plot(gplt, pkg, 0, d, KW[]) Plot(gplt, pkg, 0, d, KW[])
end end
# plot one data series # 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 # first clear out the temporary layer
gplt = getGadflyContext(plt) gplt = getGadflyContext(plt)
if gplt.layers[1].geom.tag == :remove if gplt.layers[1].geom.tag == :remove
gplt.layers = gplt.layers[2:end] gplt.layers = gplt.layers[2:end]
end end
d = KW(kw)
addGadflySeries!(plt, d) addGadflySeries!(plt, d)
push!(plt.seriesargs, d) push!(plt.seriesargs, d)
plt plt

View File

@ -15,8 +15,7 @@ immutable GLScreenWrapper
window window
end end
function _create_plot(pkg::GLVisualizeBackend; kw...) function _create_plot(pkg::GLVisualizeBackend, d::KW)
d = KW(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
@ -27,8 +26,7 @@ function _create_plot(pkg::GLVisualizeBackend; kw...)
end end
function _add_series(::GLVisualizeBackend, plt::Plot; kw...) function _add_series(::GLVisualizeBackend, plt::Plot, d::KW)
d = KW(kw)
# TODO: add one series to the underlying package # TODO: add one series to the underlying package
push!(plt.seriesargs, d) push!(plt.seriesargs, d)
# TODO: this should be moved to the display method? # TODO: this should be moved to the display method?

View File

@ -701,13 +701,11 @@ function gr_display(subplt::Subplot{GRBackend})
end end
end end
function _create_plot(pkg::GRBackend; kw...) function _create_plot(pkg::GRBackend, d::KW)
d = KW(kw)
Plot(nothing, pkg, 0, d, KW[]) Plot(nothing, pkg, 0, d, KW[])
end end
function _add_series(::GRBackend, plt::Plot; kw...) function _add_series(::GRBackend, plt::Plot, d::KW)
d = KW(kw)
push!(plt.seriesargs, d) push!(plt.seriesargs, d)
plt plt
end end

View File

@ -19,9 +19,7 @@ end
# create a blank Gadfly.Plot object # create a blank Gadfly.Plot object
function _create_plot(pkg::ImmerseBackend; kw...) function _create_plot(pkg::ImmerseBackend, d::KW)
d = KW(kw)
# create the underlying Gadfly.Plot object # create the underlying Gadfly.Plot object
gplt = createGadflyPlotObject(d) gplt = createGadflyPlotObject(d)
@ -31,8 +29,7 @@ end
# plot one data series # plot one data series
function _add_series(::ImmerseBackend, plt::Plot; kw...) function _add_series(::ImmerseBackend, plt::Plot, d::KW)
d = KW(kw)
addGadflySeries!(plt, d) addGadflySeries!(plt, d)
push!(plt.seriesargs, d) push!(plt.seriesargs, d)
plt plt

View File

@ -12,16 +12,14 @@ end
# --------------------------------------------------------------------------- # ---------------------------------------------------------------------------
function _create_plot(pkg::PGFPlotsBackend; kw...) function _create_plot(pkg::PGFPlotsBackend, d::KW)
d = KW(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; kw...) function _add_series(::PGFPlotsBackend, plt::Plot, d::KW)
d = KW(kw)
# TODO: add one series to the underlying package # TODO: add one series to the underlying package
push!(plt.seriesargs, d) push!(plt.seriesargs, d)
plt plt

View File

@ -37,16 +37,14 @@ end
# --------------------------------------------------------------------------- # ---------------------------------------------------------------------------
function _create_plot(pkg::PlotlyBackend; kw...) function _create_plot(pkg::PlotlyBackend, d::KW)
d = KW(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; kw...) function _add_series(::PlotlyBackend, plt::Plot, d::KW)
d = KW(kw)
# TODO: add one series to the underlying package # TODO: add one series to the underlying package
push!(plt.seriesargs, d) push!(plt.seriesargs, d)
plt plt

View File

@ -20,8 +20,7 @@ end
# --------------------------------------------------------------------------- # ---------------------------------------------------------------------------
function _create_plot(pkg::PlotlyJSBackend; kw...) function _create_plot(pkg::PlotlyJSBackend, d::KW)
d = KW(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(),
@ -34,8 +33,7 @@ function _create_plot(pkg::PlotlyJSBackend; kw...)
end end
function _add_series(::PlotlyJSBackend, plt::Plot; kw...) function _add_series(::PlotlyJSBackend, plt::Plot, d::KW)
d = KW(kw)
syncplot = plt.o syncplot = plt.o
# add to the data array # add to the data array

View File

@ -257,10 +257,8 @@ end
# --------------------------------------------------------------------------- # ---------------------------------------------------------------------------
function _create_plot(pkg::PyPlotBackend; kw...) function _create_plot(pkg::PyPlotBackend, d::KW)
# create the figure # create the figure
d = KW(kw)
# standalone plots will create a figure, but not if part of a subplot (do it later) # standalone plots will create a figure, but not if part of a subplot (do it later)
if haskey(d, :subplot) if haskey(d, :subplot)
wrap = nothing 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 # 3D plots have a different underlying Axes object in PyPlot
lt = d[:linetype] lt = d[:linetype]
if lt in _3dTypes && isempty(plt.o.kwargs) 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]) n = sum([plt.n for plt in plts])
pkg = PyPlotBackend() 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)) subplt = Subplot(nothing, newplts, PyPlotBackend(), p, n, layout, d, true, false, false, (r,c) -> (nothing,nothing))

View File

@ -77,8 +77,7 @@ function adjustQwtKeywords(plt::Plot{QwtBackend}, iscreating::Bool; kw...)
d d
end end
function _create_plot(pkg::QwtBackend; kw...) function _create_plot(pkg::QwtBackend, d::KW)
d = KW(kw)
fixcolors(d) fixcolors(d)
dumpdict(d,"\n\n!!! plot") dumpdict(d,"\n\n!!! plot")
o = Qwt.plot(zeros(0,0); d..., show=false) o = Qwt.plot(zeros(0,0); d..., show=false)
@ -86,8 +85,8 @@ function _create_plot(pkg::QwtBackend; kw...)
plt plt
end end
function _add_series(::QwtBackend, plt::Plot; kw...) function _add_series(::QwtBackend, plt::Plot, d::KW)
d = adjustQwtKeywords(plt, false; kw...) d = adjustQwtKeywords(plt, false; d...)
fixcolors(d) fixcolors(d)
dumpdict(d,"\n\n!!! plot!") dumpdict(d,"\n\n!!! plot!")
Qwt.oplot(plt.o; d...) Qwt.oplot(plt.o; d...)

View File

@ -14,16 +14,14 @@ end
# --------------------------------------------------------------------------- # ---------------------------------------------------------------------------
function _create_plot(pkg::[PkgName]AbstractBackend; kw...) function _create_plot(pkg::[PkgName]AbstractBackend, d::KW)
d = KW(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(::[PkgName]AbstractBackend, plt::Plot; kw...) function _add_series(::[PkgName]AbstractBackend, plt::Plot, d::KW)
d = KW(kw)
# TODO: add one series to the underlying package # TODO: add one series to the underlying package
push!(plt.seriesargs, d) push!(plt.seriesargs, d)
plt plt

View File

@ -119,8 +119,8 @@ end
# ------------------------------- # -------------------------------
function _create_plot(pkg::UnicodePlotsBackend; kw...) function _create_plot(pkg::UnicodePlotsBackend, d::KW)
plt = Plot(nothing, pkg, 0, KW(kw), KW[]) plt = Plot(nothing, pkg, 0, d, KW[])
# 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]
@ -130,8 +130,7 @@ function _create_plot(pkg::UnicodePlotsBackend; kw...)
plt plt
end end
function _add_series(::UnicodePlotsBackend, plt::Plot; kw...) function _add_series(::UnicodePlotsBackend, plt::Plot, d::KW)
d = KW(kw)
if d[:linetype] in (:sticks, :bar) if d[:linetype] in (:sticks, :bar)
d = barHack(; d...) d = barHack(; d...)
elseif d[:linetype] == :hist elseif d[:linetype] == :hist

View File

@ -40,8 +40,7 @@ end
# --------------------------------------------------------------------------- # ---------------------------------------------------------------------------
function _create_plot(pkg::WinstonBackend; kw...) function _create_plot(pkg::WinstonBackend, d::KW)
d = KW(kw)
wplt = Winston.FramedPlot(title = d[:title], xlabel = d[:xlabel], ylabel = d[:ylabel]) wplt = Winston.FramedPlot(title = d[:title], xlabel = d[:xlabel], ylabel = d[:ylabel])
Plot(wplt, pkg, 0, d, KW[]) Plot(wplt, pkg, 0, d, KW[])
@ -64,9 +63,7 @@ function getWinstonItems(plt::Plot)
window, canvas, wplt window, canvas, wplt
end end
function _add_series(::WinstonBackend, plt::Plot; kw...) function _add_series(::WinstonBackend, plt::Plot, d::KW)
d = KW(kw)
window, canvas, wplt = getWinstonItems(plt) window, canvas, wplt = getWinstonItems(plt)
# until we call it normally, do the hack # until we call it normally, do the hack

View File

@ -50,7 +50,7 @@ function plot(args...; kw...)
plotargs = merge(d, getPlotArgs(pkg, d, 1)) plotargs = merge(d, getPlotArgs(pkg, d, 1))
dumpdict(plotargs, "Plot args") 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) delete!(d, :background_color)
plot!(plt, args...; d...) # add to it plot!(plt, args...; d...) # add to it
@ -186,7 +186,7 @@ function _add_series(plt::Plot, d::KW, ::Void, args...;
dumpdict(di, "Series $i") dumpdict(di, "Series $i")
_add_series(plt.backend, plt; di...) _add_series(plt.backend, plt, di)
end end
end end

View File

@ -64,7 +64,7 @@ function subplot(args...; kw...)
di = getPlotArgs(pkg, d, i) di = getPlotArgs(pkg, d, i)
di[:subplot] = true di[:subplot] = true
dumpdict(di, "Plot args (subplot $i)") dumpdict(di, "Plot args (subplot $i)")
push!(plts, _create_plot(pkg; di...)) push!(plts, _create_plot(pkg, di))
end end
# create the object and do the plotting # create the object and do the plotting
@ -200,53 +200,13 @@ function subplot!(subplt::Subplot, args...; kw...)
subplt.initialized = _create_subplot(subplt, true) subplt.initialized = _create_subplot(subplt, true)
end 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) groupby = if haskey(d, :group)
extractGroupArgs(d[:group], args...) extractGroupArgs(d[:group], args...)
else else
nothing nothing
end end
# dumpdict(d, "after", true)
# @show groupby map(typeof, args)
_add_series_subplot(subplt, d, groupby, 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) _postprocess_subplot(subplt, d)
# show it automatically? # show it automatically?
@ -269,7 +229,7 @@ function _add_series_subplot(plt::Plot, d::KW)
setTicksFromStringVector(d, d, :y, :yticks) setTicksFromStringVector(d, d, :y, :yticks)
# this is the actual call to the backend # this is the actual call to the backend
_add_series(plt.backend, plt; d...) _add_series(plt.backend, plt, d)
_add_annotations(plt, d) _add_annotations(plt, d)
warnOnUnsupportedScales(plt.backend, d) warnOnUnsupportedScales(plt.backend, d)

View File

@ -37,7 +37,8 @@ facts("Plotly") do
@fact plotly() --> Plots.PlotlyBackend() @fact plotly() --> Plots.PlotlyBackend()
@fact backend() --> 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 end
FactCheck.exitstatus() FactCheck.exitstatus()