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...)
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(

View File

@ -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

View File

@ -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?

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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))

View File

@ -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...)

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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)

View File

@ -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()