File tree 2 files changed +17
-3
lines changed
2 files changed +17
-3
lines changed Original file line number Diff line number Diff line change @@ -379,14 +379,14 @@ theme <- function(line,
379
379
380
380
381
381
# Combine plot defaults with current theme to get complete theme for a plot
382
- plot_theme <- function (x ) {
382
+ plot_theme <- function (x , default_theme = theme_get() ) {
383
383
complete <- attr(x $ theme , " complete" )
384
384
if (is.null(complete )) {
385
- theme_get()
385
+ default_theme
386
386
} else if (complete ) {
387
387
x $ theme
388
388
} else {
389
- defaults(x $ theme , theme_get() )
389
+ defaults(x $ theme , default_theme )
390
390
}
391
391
}
392
392
Original file line number Diff line number Diff line change @@ -163,6 +163,20 @@ test_that("Complete and non-complete themes interact correctly with ggplot objec
163
163
expect_false(attr(p $ plot $ theme , " complete" ))
164
164
expect_equal(p $ plot $ theme $ text $ colour , " red" )
165
165
expect_equal(p $ plot $ theme $ text $ face , " italic" )
166
+
167
+ # The final calculated plot theme should not blend a complete theme
168
+ # with the default theme
169
+ default_theme <- theme_gray() + theme(axis.text.x = element_text(colour = " red" ))
170
+
171
+ ptheme <- plot_theme(qplot(1 : 3 , 1 : 3 ) + theme_void(), default_theme )
172
+ expect_null(ptheme $ axis.text.x )
173
+
174
+ ptheme <- plot_theme(qplot(1 : 3 , 1 : 3 ) + theme_gray(), default_theme )
175
+ expect_true(is.null(ptheme $ axis.text.x $ colour ) || ptheme $ axis.text.x $ colour != " red" )
176
+
177
+ ptheme <- plot_theme(qplot(1 : 3 , 1 : 3 ) + theme(axis.text.y = element_text(colour = " blue" )), default_theme )
178
+ expect_equal(ptheme $ axis.text.x $ colour , " red" )
179
+ expect_equal(ptheme $ axis.text.y $ colour , " blue" )
166
180
})
167
181
168
182
test_that(" theme(validate=FALSE) means do not validate_element" , {
You can’t perform that action at this time.
0 commit comments