Skip to content

Commit

Permalink
enable inheritance for derived theme elements; closes #3549 (#3550)
Browse files Browse the repository at this point in the history
  • Loading branch information
clauswilke authored Oct 9, 2019
1 parent 9b667b9 commit f16f16f
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
2 changes: 1 addition & 1 deletion R/theme.r
Original file line number Diff line number Diff line change
Expand Up @@ -655,7 +655,7 @@ combine_elements <- function(e1, e2) {
}

# If e1 has any NULL properties, inherit them from e2
n <- vapply(e1[names(e2)], is.null, logical(1))
n <- names(e1)[vapply(e1, is.null, logical(1))]
e1[n] <- e2[n]

# Calculate relative sizes
Expand Down
23 changes: 23 additions & 0 deletions tests/testthat/test-theme.r
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,29 @@ test_that("calculating theme element inheritance works", {
# Check that a theme_blank in a parent node gets passed along to children
t <- theme_grey() + theme(text = element_blank())
expect_identical(calc_element('axis.title.x', t), element_blank())

# Check that inheritance from derived class works
element_dummyrect <- function(dummy) { # like element_rect but w/ dummy argument
structure(list(
fill = NULL, colour = NULL, dummy = dummy, size = NULL,
linetype = NULL, inherit.blank = FALSE
), class = c("element_dummyrect", "element_rect", "element"))
}

e <- calc_element(
"panel.background",
theme(
rect = element_rect(fill = "white", colour = "black", size = 0.5, linetype = 1),
panel.background = element_dummyrect(dummy = 5))
)

expect_identical(
e,
structure(list(
fill = "white", colour = "black", dummy = 5, size = 0.5, linetype = 1,
inherit.blank = FALSE
), class = c("element_dummyrect", "element_rect", "element"))
)
})

test_that("complete and non-complete themes interact correctly with each other", {
Expand Down

0 comments on commit f16f16f

Please sign in to comment.