Repository navigation
Rework of .element_tree to an R6 Class, permitting user-defined new theme elements. - #2305
Closed
nhamilton1980 wants to merge 11 commits into
Closed
nhamilton1980 wants to merge 11 commits into
nhamilton1980 wants to merge 11 commits into
Conversation
added 5 commits
October 22, 2017 13:47
This is not a huge update, but it is meaningful in my opinion.
I have completely re-worked the element tree, now based of R6 Class, which permits user-defined theme elements, for use in package extentions.
Checks have been implemented so that these user-defined theme elements DO NOT CLASH with the set of protected theme elements, that is to say, those that are otherwise required for the base ggplot2 functionality. What this boils down to, is that the base ggplot2 element tree structure is protected, whilst still permitting users to extend this structure.
With this update, people will be able to create their own extensions to ggplot2, and design their own theme elements for whatever reason. I have added this functionality, primarily so I can re-work some of the painful aspects of the ggtern package, which depends on dozens and dozens of new theme elements to function correctly.
Previously, the .element_tree object was hidden and not-exported. There was no way to extend this tree, which was presumably to stop people meddling around with something that is so fundamental, with potentially catastrophic consequences to the plot routines. This is a totally valid, and understanable concern, however, by integrating a 'fixed' and 'variable' tree in the proposed R6 class that has been included within this update the following outcomes have resulted:
1. The now publicly-visible tree (accessed via get_elements() function) is the combination of these fixed and variable components. If the both the fixed and variable trees are 'sane', then the combination will also be sane. Sanity checks are conducted when the user attempts to add a new theme element.
2. Given the above, the base tree can be protected and preserved, innoculated from the variable tree. Any proposed new elements (ie those that the user wants to add to the 'variable' tree) can be checked against the 'fixed' tree first, to make sure such elements are not reserved.
3. New elements can be added easily via the exported add_element(k,v) function, where k is the 'key' (non-clashing name of the desired element to be added to the tree) and 'v' is the value (instance of the el_def(...)) theme element definition.
4. Ultimately, from the perspective of the end user nothing has changed, essentially only one tree exists, none of the previous functionality has been altered, the same methods of indexing (ie .element_tree[[elname]]) behave as previously used within ggplot2, however. This change will only be appreciated by package developers like myself.
5. The guts of the validate_element routine has been incorporated within the R6 class.
Anyway, this update will enable ggtern to make a number of changes, reducing package fragility and complexity. I am sure other package developers will benefit too.
Any questions, please email me.
Regards,
Nicholas E. Hamilton
UNSW Sydney.
[email protected]
.element_tree to an R6 Class, permitting user-defined new theme elements.
Member
|
Unfortunately, I have no capability to review such a large and wide reaching pull request. If you are still interested in this, I'd recommend starting with an issue so we can talk through the problem first. |
Author
|
This is a little disappointing, however, as suggested I have started an issue here: #2540 |
|
This old issue has been automatically locked. If you believe you have found a related problem, please file a new issue (with reprex) and link to this issue. https://reprex.tidyverse.org/ |
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
Dear Hadley / Winston & Other Devs,
This is not a huge update, but it is meaningful in my opinion.
I have completely re-worked the element tree, now based of R6 Class, which permits user-defined theme elements, for use in package extentions.
Checks have been implemented so that these user-defined theme elements DO NOT CLASH with the set of protected theme elements, that is to say, those that are otherwise required for the base
ggplot2functionality. What this boils down to, is that the baseggplot2element tree structure is protected, whilst still permitting users to extend this structure.With this update, people will be able to create their own extensions to
ggplot2, and design their own theme elements for whatever reason. I have added this functionality, primarily so I can re-work some of the painful aspects of theggternpackage, which depends on dozens and dozens of new theme elements to function correctly.Previously, the
.element_treeobject was hidden and not-exported. There was no way to extend this tree, which was presumably to stop people meddling around with something that is so fundamental, with potentially catastrophic consequences to the plot routines. This is a totally valid, and understandable concern, however, by integrating a 'fixed' and 'variable' tree in the proposedR6class that has been included within this update the following outcomes have resulted:get_elements()function) is the combination of these fixed and variable components. If the both the fixed and variable trees are 'sane', then the combination will also be sane. Sanity checks are conducted when the user attempts to add a new theme element.add_element(k,v)function, where k is the 'key' (non-clashing name of the desired element to be added to the tree) and 'v' is the value (instance of theel_def(...)) theme element definition..element_tree[[elname]]) behave as previously used withinggplot2, however. This change will only be appreciated by package developers like myself.validate_element(...)routine has been incorporated within theR6class.Anyway, this update will enable
ggternto make a number of changes, reducing package fragility and complexity. It is almost certain that other package developers will benefit too.Any questions, please email me, or comment below.
Regards,
Nicholas E. Hamilton
UNSW Sydney.
[email protected]