Skip to content

Element subclass inheritance - #5486

Merged
teunbrand merged 4 commits into
tidyverse:mainfrom
teunbrand:element_subclass
Nov 7, 2023
Merged

teunbrand merged 4 commits into
tidyverse:mainfrom
teunbrand:element_subclass

Conversation

@teunbrand

Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
@teunbrand
teunbrand requested a review from thomasp85 November 7, 2023 10:17

@thomasp85 thomasp85 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM

@teunbrand

Copy link
Copy Markdown
Collaborator Author

That was fast, thanks Thomas!

@teunbrand
teunbrand merged commit 567006c into tidyverse:main Nov 7, 2023
@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