Theme element dual inheritance#5175
Merged
teunbrand merged 5 commits intotidyverse:mainfrom Feb 21, 2023
Merged
Conversation
Merged
thomasp85
reviewed
Feb 9, 2023
| legend.key.width = el_def("unit", "legend.key.size"), | ||
| legend.text = el_def("element_text", "text"), | ||
| legend.text.align = el_def("character"), | ||
| legend.text.align = el_def("numeric"), |
Member
There was a problem hiding this comment.
Don't we want to accept both numeric and character? ie. both e.g. "center" and 0.5
Collaborator
Author
There was a problem hiding this comment.
Currently, giving a character(1) results in a grid-error, i.e. legend.text.align = "left" gets:
Error in valid.charjust(just) : invalid vertical justification
Whereas with this PR, the error will be:
! Thelegend.text.aligntheme element must be a <numeric> object.
Which is slightly more informative. I can see how allowing character justification might help here, but that might be a separate PR from this one.
Member
There was a problem hiding this comment.
huh... surprising - but agreed that it is separate from this
Collaborator
Author
|
Thanks for the review! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR aims to fix a problem I ran into during 2 previous PRs (#5167 and #4879). Instead of the pragmatic hotfixes in those PRs, this one addresses the root cause.
The problem is that
calc_element()could not be used to calculate any part of the theme that had dual<character/numeric>inheritance. Under the hood, an exception was made in the validation to allow character elements to also be numeric. This was the case forlegend.positionthat could be either"top"orc(0, 1), for example. This is all fine, however,calc_element()did not special-case the<character/numeric>dual inheritance, and would throw an error if you provide a numeric vector (see reprex).The solution in this PR is to properly give those elements that should support dual inheritance a dual class. By doing this, we no longer need to special-case in the validator, and
calc_element()gives the right answers. Also, we can letaspect.ratioinherit from<numeric>now, whereas previously it would throw uninformative errors from later in the plotting process.A demonstration of before this PR (backtraces omitted):
Whereas now:
Created on 2023-02-02 with reprex v2.0.2