Skip to content

Commit

Permalink
adds whitelists for Makie arguments to supplement the internals black…
Browse files Browse the repository at this point in the history
…list
  • Loading branch information
rdboyes committed Jun 26, 2024
1 parent f16427d commit 762ab10
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 5 deletions.
20 changes: 20 additions & 0 deletions src/attributes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -163,3 +163,23 @@ const _internal_geom_options = Symbol[
:ymax,
:ymin
]

# for each supported plot type, get the keyword args that it accepts

const _accepted_options_by_type = Dict(
:BoxPlot => Makie.attribute_names(Plot{Makie.boxplot}),
:Scatter => Makie.attribute_names(Plot{Makie.scatter}),
:BarPlot => Makie.attribute_names(Plot{Makie.barplot}),
:Contour => Makie.attribute_names(Plot{Makie.contour}),
:Density => Makie.attribute_names(Plot{Makie.density}),
:Rangebars => Makie.attribute_names(Plot{Makie.rangebars}),
:Hist => Makie.attribute_names(Plot{Makie.hist}),
:HLines => Makie.attribute_names(Plot{Makie.hlines}),
:VLines => Makie.attribute_names(Plot{Makie.vlines}),
:Lines => Makie.attribute_names(Plot{Makie.lines}),
:Band => Makie.attribute_names(Plot{Makie.band}),
:Text => Makie.attribute_names(Plot{Makie.text}),
:Heatmap => Makie.attribute_names(Plot{Makie.heatmap}),
:Violin => Makie.attribute_names(Plot{Makie.violin}),
:Stairs => Makie.attribute_names(Plot{Makie.stairs})
)
16 changes: 11 additions & 5 deletions src/draw.jl
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,18 @@ function Makie.SpecApi.Axis(plot::GGPlot)

args_dict_makie = Dict{Symbol, Any}()

supported_kwargs = get(_accepted_options_by_type, geom.visual, nothing)

for (arg, value) in args_dict
if !(Symbol(arg) in _internal_geom_options)
ex_type = get(_makie_expected_type, arg, Any)
converted_value = try_convert(ex_type, value, arg, geom.args["geom_name"])
makie_attr = get(ggplot_to_makie_geom, arg, arg)
args_dict_makie[Symbol(makie_attr)] = converted_value
if isnothing(supported_kwargs) || Symbol(makie_attr) in supported_kwargs
args_dict_makie[Symbol(makie_attr)] = converted_value
else
@warn "Dropping unsupported argument: $makie_attr"
end
end
end

Expand All @@ -95,7 +101,7 @@ function Makie.SpecApi.Axis(plot::GGPlot)
if length(intersect(keys(given_aes), geom.grouping_aes)) == 0 && isnothing(plot.facet_options)
# if there are no grouping_aes given and no facets required, we only need one PlotSpec
required_aes_data = [p.makie_function(p.raw) for p in [given_aes[a] for a in Symbol.(required_aes)]]
optional_aes_data = [a => p.makie_function(p.raw) for (a, p) in given_aes if (!(String(a) in required_aes) && !(a in _internal_geom_options))]
optional_aes_data = [a => p.makie_function(p.raw) for (a, p) in given_aes if (!(String(a) in required_aes) && (isnothing(supported_kwargs) || a in supported_kwargs))]

args = Tuple([geom.visual, required_aes_data...])
kwargs = merge(args_dict_makie, Dict(optional_aes_data))
Expand All @@ -111,7 +117,7 @@ function Makie.SpecApi.Axis(plot::GGPlot)
# push each one to the overall plot_list
for sub in subgroup_given_aes
required_aes_data = [p.makie_function(p.raw) for p in [sub[a] for a in Symbol.(required_aes)]]
optional_aes_data = [a => p.makie_function(p.raw) for (a, p) in sub if (!(String(a) in required_aes) && !(a in _internal_geom_options))]
optional_aes_data = [a => p.makie_function(p.raw) for (a, p) in sub if (!(String(a) in required_aes) && (isnothing(supported_kwargs) || a in supported_kwargs))]

args = Tuple([geom.visual, required_aes_data...])
kwargs = merge(args_dict_makie, Dict(optional_aes_data))
Expand All @@ -135,7 +141,7 @@ function Makie.SpecApi.Axis(plot::GGPlot)

for (index, sub) in enumerate(subgroup_given_aes)
required_aes_data = [p.makie_function(p.raw) for p in [sub[a] for a in Symbol.(required_aes)]]
optional_aes_data = [a => p.makie_function(p.raw) for (a, p) in sub if (!(String(a) in required_aes) && !(a in _internal_geom_options))]
optional_aes_data = [a => p.makie_function(p.raw) for (a, p) in sub if (!(String(a) in required_aes) && (isnothing(supported_kwargs) || a in supported_kwargs))]

args = Tuple([geom.visual, required_aes_data...])
kwargs = merge(args_dict_makie, Dict(optional_aes_data))
Expand All @@ -155,7 +161,7 @@ function Makie.SpecApi.Axis(plot::GGPlot)

for (sub, facet_name) in zip(subgroup_given_aes, facet_names)
required_aes_data = [p.makie_function(p.raw) for p in [sub[a] for a in Symbol.(required_aes)]]
optional_aes_data = [a => p.makie_function(p.raw) for (a, p) in sub if (!(String(a) in required_aes) && !(a in _internal_geom_options))]
optional_aes_data = [a => p.makie_function(p.raw) for (a, p) in sub if (!(String(a) in required_aes) && (isnothing(supported_kwargs) || a in supported_kwargs))]

args = Tuple([geom.visual, required_aes_data...])
kwargs = merge(args_dict_makie, Dict(optional_aes_data))
Expand Down

2 comments on commit 762ab10

@rdboyes
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/109856

Tip: Release Notes

Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.

@JuliaRegistrator register

Release notes:

## Breaking changes

- blah

To add them here just re-invoke and the PR will be updated.

Tagging

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.7.7 -m "<description of version>" 762ab104b4e7c5f1d5c8d002b6f142ee8823608a
git push origin v0.7.7

Please sign in to comment.