-
-
Notifications
You must be signed in to change notification settings - Fork 308
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Recipes do not react to keyword arguments properly #3263
Labels
Attributes
Plot, Block and Scene Attributes
bug
Collection
contains multiple issues
DataInspector
Legend & Colorbar
Makie
Backend independent issues (Makie core)
Comments
Also, |
staticfloat
changed the title
Recipes do not react to keyword arguments properly
Oct 11, 2023
scatterlines!()
ignores inspector_label
I am working around this locally with my own recipes using the following macro: """
@pltkwargs(names...)
A helper macro to aid in pulling values out of a `kwargs...` pair set, or the
`plt` object if not set in `kwargs`, finally defaulting to a default value if
not set in either. Syntax is `@pltkwargs name`, or `@pltkwargs name=default`
if you want to set a default value. If not set, the default is `nothing`.
Multiple bindings can be created at once, example:
function Makie.plot!(plt::SignalPlot{...}; kwargs...)
# This creates local variables named `label` and `color`, pulling the
# value out of `kwargs` if it exists, `plt` otherwise. If `label` is
# not found in either, it defaults to `"signal"`, if `color` is not
# found in either, it defaults to `nothing`.
@pltkwargs label="signal" color
...
lines!(plt, x, y; label, color)
end
"""
macro pltkwargs(names...)
declarations = []
for name in names
# Support `foo="something"` syntax for default values
if isa(name, Expr) && name.head == :(=)
name, default = name.args
else
default = nothing
end
push!(declarations, quote
if haskey($(esc(:kwargs)), $(QuoteNode(name)))
# If `name `exists in `kwargs`, use that
$(esc(name)) = getindex($(esc(:kwargs)), $(QuoteNode(name)))
else
# Otherwise, pull it out of `plt`. If it still doesn't exist, return `nothing`
$(esc(name)) = get($(esc(:plt)), $(QuoteNode(name)), $(esc(default)))
end
end)
end
return quote
$(declarations...)
end
end It is used like this: function Makie.plot!(plt::MyRecipe; kwargs...)
# @pltkwargs allows us to receive these values from our `kwargs`, or
# from our `plt` object (which inherits it from the theme).
@pltkwargs(
color, colormap, colorrange,
label="signal", inspectable=false,
linewidth, markersize,
)
# Pass through our kwargs to `scatter!()`
scatter!(plt, plt[1].xs, plt[1].ys;
color, colormap, colorrange, inspectable,
markersize, marker='X',
)
return plt
end If it seems useful, perhaps this macro can be adopted by core Makie, and used in its implementation to ease accepting values from either |
ffreyer
added
Collection
contains multiple issues
Attributes
Plot, Block and Scene Attributes
DataInspector
Legend & Colorbar
Makie
Backend independent issues (Makie core)
labels
Aug 26, 2024
4 tasks
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
Attributes
Plot, Block and Scene Attributes
bug
Collection
contains multiple issues
DataInspector
Legend & Colorbar
Makie
Backend independent issues (Makie core)
sd/beta-20
)I see that the
scatterlines!()
recipe does not pass through all keyword arguments that you might expect. In particular,inspector_label
gets ignored. While this should not be too difficult to patch, is there an accepted way to do the spiritual equivalent ofkwargs...
within a plot recipe?The text was updated successfully, but these errors were encountered: