Skip to content
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

Apply recipes to keyword arguments #4453

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

gustaphe
Copy link
Collaborator

There are some keyword arguments which it makes sense to interpret as "on a data axis" - meaning that it would be useful to query the recipe pipeline for how to interpret user provided types.

Some such arguments that I have identified are

  • lims
  • ticks
  • annotation coordinates
  • ribbon/error/fillto
  • marker_z and friends
  • colorbar lims and ticks
  • marker_size (this one is questionable)

So far, a number of these have been hardcoded for Unitful and Dates, which are two of the most obvious use cases, but if a user wanted to be able to set limits in their own data type they would have to either override unexported Plots functions or handle the conversion to Tuple{Float, Float} themselves. With this PR, a type recipe is enough.

@gustaphe gustaphe added the extension new behaviour label Oct 12, 2022
src/axes.jl Outdated
@@ -81,6 +81,7 @@ end
function attr!(axis::Axis, args...; kw...)
# first process args
plotattributes = axis.plotattributes
dummy_attributes = Dict{Symbol, Any}(:plot_object=>first(axis.sps).plt)
Copy link
Member

Choose a reason for hiding this comment

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

What are those needed for?

Copy link
Collaborator Author

@gustaphe gustaphe Oct 12, 2022

Choose a reason for hiding this comment

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

Good question. RecipesPipeline._apply_type_recipe has

function _apply_type_recipe(plotattributes, v, letter)
plt = plotattributes[:plot_object]
preprocess_axis_args!(plt, plotattributes, letter)
rdvec = RecipesBase.apply_recipe(plotattributes, typeof(v), v)
warn_on_recipe_aliases!(plotattributes[:plot_object], plotattributes, :type, v)
postprocess_axis_args!(plt, plotattributes, letter)
return rdvec[1].args[1]
end

where it asks the first argument for :plot_object, which it then uses for pre- and postprocessing. Perhaps the function should instead be extended to accept an Axis object instead or something, this just seemed like the minimum intrusion operation to me.

@codecov
Copy link

codecov bot commented Oct 12, 2022

Codecov Report

Base: 80.60% // Head: 79.88% // Decreases project coverage by -0.72% ⚠️

Coverage data is based on head (2c90439) compared to base (e9fb3b3).
Patch coverage: 100.00% of modified lines in pull request are covered.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #4453      +/-   ##
==========================================
- Coverage   80.60%   79.88%   -0.73%     
==========================================
  Files          30       40      +10     
  Lines        7466     8196     +730     
==========================================
+ Hits         6018     6547     +529     
- Misses       1448     1649     +201     
Impacted Files Coverage Δ
src/unitful.jl 88.70% <ø> (+0.52%) ⬆️
src/axes.jl 83.43% <100.00%> (+0.36%) ⬆️
src/precompilation.jl
RecipesPipeline/src/plot_recipe.jl 96.00% <0.00%> (ø)
RecipesBase/src/RecipesBase.jl 81.48% <0.00%> (ø)
RecipesPipeline/src/utils.jl 62.66% <0.00%> (ø)
RecipesPipeline/src/series_recipe.jl 93.10% <0.00%> (ø)
RecipesPipeline/src/recipes.jl 18.75% <0.00%> (ø)
RecipesPipeline/src/type_recipe.jl 94.11% <0.00%> (ø)
RecipesPipeline/src/user_recipe.jl 67.50% <0.00%> (ø)
... and 4 more

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
extension new behaviour
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants