changed recipe to plotrecipe and improved it
This commit is contained in:
parent
5a520aadc0
commit
cdc0d22b01
@ -144,8 +144,8 @@ export
|
|||||||
arcdiagram,
|
arcdiagram,
|
||||||
chorddiagram,
|
chorddiagram,
|
||||||
|
|
||||||
@kw,
|
# @kw,
|
||||||
@recipe,
|
@plotrecipe,
|
||||||
|
|
||||||
translate,
|
translate,
|
||||||
translate!,
|
translate!,
|
||||||
|
|||||||
@ -32,8 +32,18 @@ macro kw(k, v)
|
|||||||
esc(:(get!(d, $k, $v)))
|
esc(:(get!(d, $k, $v)))
|
||||||
end
|
end
|
||||||
|
|
||||||
macro recipe(args...)
|
macro plotrecipe(args, expr)
|
||||||
expr = args[end]
|
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)
|
for (i,e) in enumerate(expr.args)
|
||||||
if isa(e,Expr) && e.head == :(=>)
|
if isa(e,Expr) && e.head == :(=>)
|
||||||
k, v = e.args[1:2]
|
k, v = e.args[1:2]
|
||||||
@ -41,19 +51,19 @@ macro recipe(args...)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
e = esc(quote
|
# now build a function definition for _apply_recipe, wrapping the return value in a tuple if needed
|
||||||
function Plots._apply_recipe(d::KW, $(args[1:end-1]...); kw...)
|
esc(quote
|
||||||
$expr
|
function Plots._apply_recipe(d::KW, $(args.args...); kw...)
|
||||||
|
ret = $expr
|
||||||
|
if typeof(ret) <: Tuple
|
||||||
|
ret
|
||||||
|
else
|
||||||
|
(ret,)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
# @show e
|
|
||||||
# dump(e,10)
|
|
||||||
e
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# macro force_kw(k, v)
|
|
||||||
# esc(:(d[$k] = $v))
|
|
||||||
# end
|
|
||||||
|
|
||||||
# ---------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user