changed recipe to plotrecipe and improved it
This commit is contained in:
parent
5a520aadc0
commit
cdc0d22b01
@ -144,8 +144,8 @@ export
|
||||
arcdiagram,
|
||||
chorddiagram,
|
||||
|
||||
@kw,
|
||||
@recipe,
|
||||
# @kw,
|
||||
@plotrecipe,
|
||||
|
||||
translate,
|
||||
translate!,
|
||||
|
||||
@ -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
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user