-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Fix calculation of theme defaults #2080
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
Conversation
Tests fail due to assignments that relied on the problematic default theme inheritance that this PR got rid of. $ ag 'theme\$.+?<-' |
I don't think changing inheritance is necessary. All of these issues seems to come from the fact that |
I noticed that it was incompletely specified, but I think if you look closer the complete specification that would make the bug go away would imply that the elements themselves have no inheritance hierarchy. That is, even if you have To be clear, these are the options for what could be meant by complete:
This patch recognises the second definition, whereas your (@thomasp85) suggestion seems to imply the first. Also, if it is the first then the line that I removed/relocated would always be redundant as there wouldn't be any unspecified elements. |
Sorry to bother, but are there any news on this pull request? |
@crsh, I'll look into fixing the failing test case. The first time around, I expected to ask for help with a clearer question. I did not get to it. |
@has2k1 Do you see the failure if you run locally? |
Locally, I get many failures (with/without this PR maybe something to do with fonts) but not the particular one that fails on appveyor. |
@lionel- do you have any tools for debugging this sort of failure? |
Nothing user-oriented yet, we definitely should add some UI for this. IIRC, I generated a SVG from the faulty plot manually with We need a verbose |
R/theme.r
Outdated
@@ -380,7 +380,13 @@ theme <- function(line, | |||
|
|||
# Combine plot defaults with current theme to get complete theme for a plot | |||
plot_theme <- function(x) { | |||
defaults(x$theme, theme_get()) | |||
if (is.null(attr(x$theme, "complete"))) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When does this branch get triggered?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When using the default theme. The cases for the three branches respectively are.
ggplot(...) + geom_point()
ggplot(...) + geom_point() + theme_gray()
ggplot(...) + geom_point() + theme(...)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, got it. It might be slightly easier to read if you did:
complete <- attr(x$theme, "complete")
I get the same failing test that AppVeyor complains about. The title for |
@has2k1 can you reproduce those issues locally yourself? |
I cannot reproduce the failing test. Also, if I approximate the failing test with df <- data.frame(x = 1:3, y = 1:3, z = c("a", "b", "a"), a = 1)
plot <- ggplot(df, aes(x, y, colour = z)) +
geom_point() +
facet_wrap(~ a)
plot + ggtitle("theme_void") + theme_void() The title is still in the center. For the speculation (my system is linux), given that on |
For creating a test, I do not know how wise it would be to mess with the default theme (a global variable) in the test suit. |
d8c5f0d
to
d6a5066
Compare
@has2k1 it's fine. Just use |
a509a7d
to
981caef
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It sounds like @karawoo was saying that after this patch, the title is centred, but it should be left aligned. Can you please confirm?
tests/testthat/test-theme.r
Outdated
@@ -163,6 +163,20 @@ test_that("Complete and non-complete themes interact correctly with ggplot objec | |||
expect_false(attr(p$plot$theme, "complete")) | |||
expect_equal(p$plot$theme$text$colour, "red") | |||
expect_equal(p$plot$theme$text$face, "italic") | |||
|
|||
# The final calculated plot theme should not blend a complete theme |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you please make this a separate test?
Yeah, that's what I was seeing with the title. |
981caef
to
6a4472d
Compare
I've specified the title, subtiltle and caption text elements of |
@has2k1 looks like there are still changes to the tests. |
Since the tests where generated with I think there are two alternatives;
The first is what the last commit was aiming for, the 2nd though a good idea it changes the long standing status of |
If you believe the behaviour is correct, you need to check in updated visual tests. |
**Issue** At plot time, the calculation of theme elements always fell back to the default theme. As a consequence, the default theme would leak into complete themes where some of the elements were unspecified. **Solution** Be more specific when calculating the theme defaults. **Clean Up** `theme_void` was insufficiently specified. The solution exposed missing elements that had to be specified. Fixes tidyverse#2058 Fixes tidyverse#2079
When the theme element does not exist, there should be no assigment to any of it's attributes. There was only a single instance of this.
This makes theme_void have a similar overall layout to other themes. And move tests to separate function.
c454e51
to
01ecde4
Compare
I need some help, I cannot generate images that can pass visual tests on my system. |
What system are you using? vdiffr is currently broken on some Linux systems, I'm investigating. |
Indeed, I am on a linux system. |
Which one? |
Also could you provide the result of running these two commands please: gdtools::version_fontconfig()
gdtools::version_freetype() |
Gentoo Linux
|
@has2k1 would you be willing to update this? I can try and merge in the next week or so. |
Actually, don't worry, I can do it myself |
Issue
At plot time, the calculation of theme elements always fell back
to the default theme. As a consequence, the default theme would
leak into complete themes where some of the elements were
unspecified.
Solution
Be more specific when calculating the theme defaults.
Clean Up
theme_void
was insufficiently specified. The solution exposedmissing elements that had to be specified.
Fixes #2058
Fixes #2079