recipe postprocessing for aliases and magic args

This commit is contained in:
Thomas Breloff 2016-08-19 19:04:10 -04:00
parent 333714911c
commit 011f51fbd9
3 changed files with 48 additions and 4 deletions

View File

@ -688,7 +688,7 @@ function preprocessArgs!(d::KW)
a = d[:arrow] a = d[:arrow]
d[:arrow] = if a == true d[:arrow] = if a == true
arrow() arrow()
elseif a == false elseif a in (false, nothing, :none)
nothing nothing
elseif !(typeof(a) <: Arrow) elseif !(typeof(a) <: Arrow)
arrow(wraptuple(a)...) arrow(wraptuple(a)...)
@ -698,9 +698,9 @@ function preprocessArgs!(d::KW)
end end
if get(d, :arrow, false) == true # if get(d, :arrow, false) == true
d[:arrow] = arrow() # d[:arrow] = arrow()
end # end
# legends # legends
if haskey(d, :legend) if haskey(d, :legend)

View File

@ -95,6 +95,7 @@ function _process_userrecipe(plt::Plot, kw_list::Vector{KW}, recipedata::RecipeD
# when the arg tuple is empty, that means there's nothing left to recursively # when the arg tuple is empty, that means there's nothing left to recursively
# process... finish up and add to the kw_list # process... finish up and add to the kw_list
kw = recipedata.d kw = recipedata.d
preprocessArgs!(kw)
_preprocess_userrecipe(kw) _preprocess_userrecipe(kw)
warnOnUnsupported_scales(plt.backend, kw) warnOnUnsupported_scales(plt.backend, kw)
@ -183,6 +184,7 @@ function _process_plotrecipe(plt::Plot, kw::KW, kw_list::Vector{KW}, still_to_pr
st = kw[:seriestype] = get(_typeAliases, st, st) st = kw[:seriestype] = get(_typeAliases, st, st)
datalist = RecipesBase.apply_recipe(kw, Val{st}, plt) datalist = RecipesBase.apply_recipe(kw, Val{st}, plt)
for data in datalist for data in datalist
preprocessArgs!(data.d)
if data.d[:seriestype] == st if data.d[:seriestype] == st
error("Plot recipe $st returned the same seriestype: $(data.d)") error("Plot recipe $st returned the same seriestype: $(data.d)")
end end
@ -389,6 +391,10 @@ function _process_seriesrecipe(plt::Plot, d::KW)
# assuming there was no error, recursively apply the series recipes # assuming there was no error, recursively apply the series recipes
for data in datalist for data in datalist
if isa(data, RecipeData) if isa(data, RecipeData)
preprocessArgs!(data.d)
if data.d[:seriestype] == st
error("The seriestype didn't change in series recipe $st. This will cause a StackOverflow.")
end
_process_seriesrecipe(plt, data.d) _process_seriesrecipe(plt, data.d)
else else
warn("Unhandled recipe: $(data)") warn("Unhandled recipe: $(data)")

View File

@ -85,6 +85,44 @@ facts("Axes") do
end end
# tests for preprocessing recipes
# facts("recipes") do
# user recipe
# type T end
# @recipe function f(::T)
# line := (3,0.3,:red)
# marker := (20,0.5,:blue,:o)
# bg := :yellow
# rand(10)
# end
# plot(T())
# plot recipe
# @recipe function f(::Type{Val{:hiplt}},plt::Plot)
# line := (3,0.3,:red)
# marker := (20,0.5,:blue,:o)
# t := :path
# bg:=:green
# ()
# end
# plot(rand(10),t=:hiplt)
# series recipe
# @recipe function f(::Type{Val{:hi}},x,y,z)
# line := (3,0.3,:red)
# marker := (20,0.5,:blue,:o)
# t := :path
# ()
# end
# plot(rand(10),t=:hiplt)
# end
FactCheck.exitstatus() FactCheck.exitstatus()