changed recipe to plotrecipe and improved it

This commit is contained in:
Thomas Breloff 2016-05-05 11:51:50 -04:00
parent 5a520aadc0
commit cdc0d22b01
2 changed files with 23 additions and 13 deletions

View File

@ -144,8 +144,8 @@ export
arcdiagram,
chorddiagram,
@kw,
@recipe,
# @kw,
@plotrecipe,
translate,
translate!,

View File

@ -32,8 +32,18 @@ macro kw(k, v)
esc(:(get!(d, $k, $v)))
end
macro recipe(args...)
expr = args[end]
macro plotrecipe(args, expr)
if !isa(args, Expr)
error("The first argument to `@plotrecipe` should be a valid argument list for dispatch.")
end
# wrap the args in a tuple
if args.head != :tuple
args = Expr(:tuple, args)
end
# replace all the key => value lines with argument setting logic
# TODO: when this is moved out of Plots, also move the replacement of key aliases to just after the _apply_recipe calls
for (i,e) in enumerate(expr.args)
if isa(e,Expr) && e.head == :(=>)
k, v = e.args[1:2]
@ -41,19 +51,19 @@ macro recipe(args...)
end
end
e = esc(quote
function Plots._apply_recipe(d::KW, $(args[1:end-1]...); kw...)
$expr
# now build a function definition for _apply_recipe, wrapping the return value in a tuple if needed
esc(quote
function Plots._apply_recipe(d::KW, $(args.args...); kw...)
ret = $expr
if typeof(ret) <: Tuple
ret
else
(ret,)
end
end
end)
# @show e
# dump(e,10)
e
end
# macro force_kw(k, v)
# esc(:(d[$k] = $v))
# end
# ---------------------------------------------------------------------------