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

Element subclass inheritance #5486

Merged
merged 4 commits into from
Nov 7, 2023
Merged

Conversation

teunbrand
Copy link
Collaborator

This PR aims to fix #5457

Briefly, it checks if parent elements are a subclass of child elements and if they are, fill parent element with child values instead of completing missing/NULL child values with parent values.

Reprex from #5457:

devtools::load_all("~/packages/ggplot2")
#> ℹ Loading ggplot2
p <- ggplot(mpg, aes(displ, hwy)) +
  geom_point() +
  labs(x = "**displacement**")

p + theme(axis.title = ggtext::element_markdown())

Created on 2023-10-16 with reprex v2.0.2

@thomasp85
Copy link
Member

We agree this only has implications for when users actively use an extension package with a new element and overwrites an element in the theme tree, right?

@teunbrand
Copy link
Collaborator Author

Yes this shouldn't have any implications elsewhere. It is just so that sublasses propagate through theme inheritance.

To use an example from theme_grey(); let's say a user sets a custom axis.text = element_special_text(...), where element_special_text() produces an element_text subclass. Because theme_grey() has axis.text.x = element_text(...), axis.text.x.bottom would not acquire the special subclass, whereas with this PR, it does acquire the special subclass.

@teunbrand teunbrand added this to the ggplot2 3.5.0 milestone Nov 7, 2023
Copy link
Member

@thomasp85 thomasp85 left a comment

Choose a reason for hiding this comment

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

LGTM

@teunbrand
Copy link
Collaborator Author

That was fast, thanks Thomas!

@teunbrand teunbrand merged commit 567006c into tidyverse:main Nov 7, 2023
12 checks passed
@teunbrand teunbrand deleted the element_subclass branch November 7, 2023 11:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Should theme inheritance prefer the 'richer' element?
2 participants