@@ -142,12 +142,10 @@ test_that("calculating theme element inheritance works", {
142
142
expect_identical(calc_element(' axis.title.x' , t ), element_blank())
143
143
144
144
# Check that inheritance from derived class works
145
- element_dummyrect <- function (dummy ) { # like element_rect but w/ dummy argument
146
- structure(list (
147
- fill = NULL , colour = NULL , dummy = dummy , linewidth = NULL ,
148
- linetype = NULL , inherit.blank = FALSE
149
- ), class = c(" element_dummyrect" , " element_rect" , " element" ))
150
- }
145
+ element_dummyrect <- S7 :: new_class(
146
+ " element_dummyrect" , parent = element_rect ,
147
+ properties = c(element_rect @ properties , list (dummy = S7 :: class_any ))
148
+ )
151
149
152
150
e <- calc_element(
153
151
" panel.background" ,
@@ -160,10 +158,10 @@ test_that("calculating theme element inheritance works", {
160
158
161
159
expect_identical(
162
160
e ,
163
- structure( list (
161
+ element_dummyrect (
164
162
fill = " white" , colour = " black" , dummy = 5 , linewidth = 0.5 , linetype = 1 ,
165
163
inherit.blank = TRUE # this is true because we're requesting a complete theme
166
- ), class = c( " element_dummyrect " , " element_rect " , " element " ))
164
+ )
167
165
)
168
166
169
167
# Check that blank elements are skipped in inheritance tree if and only if elements
@@ -283,9 +281,10 @@ test_that("theme validation happens at build stage", {
283
281
test_that(" incorrect theme specifications throw meaningful errors" , {
284
282
expect_snapshot_error(add_theme(theme_grey(), theme(line = element_rect())))
285
283
expect_snapshot_error(calc_element(" line" , theme(line = element_rect())))
286
- register_theme_elements(element_tree = list (test = el_def(" element_rect" )))
284
+ register_theme_elements(element_tree = list (test = el_def(element_rect )))
287
285
expect_snapshot_error(calc_element(" test" , theme_gray() + theme(test = element_rect())))
288
286
expect_snapshot_error(set_theme(" foo" ))
287
+ reset_theme_settings()
289
288
})
290
289
291
290
test_that(" element tree can be modified" , {
@@ -305,7 +304,7 @@ test_that("element tree can be modified", {
305
304
306
305
# things work once we add a new element to the element tree
307
306
register_theme_elements(
308
- element_tree = list (blablabla = el_def(" element_text" , " text" ))
307
+ element_tree = list (blablabla = el_def(element_text , " text" ))
309
308
)
310
309
expect_silent(ggplotGrob(p ))
311
310
@@ -334,13 +333,13 @@ test_that("element tree can be modified", {
334
333
expect_identical(e1 @ colour , " red" ) # not inherited from element_text
335
334
336
335
# existing elements can be overwritten
337
- ed <- el_def(" element_rect" , " rect" )
336
+ ed <- el_def(element_rect , " rect" )
338
337
register_theme_elements(
339
338
element_tree = list (axis.title = ed )
340
339
)
341
340
expect_identical(get_element_tree()$ axis.title , ed )
342
341
343
- reset_theme_settings(reset_current = FALSE ) # revert back to defaults
342
+ reset_theme_settings() # revert back to defaults
344
343
})
345
344
346
345
test_that(" all elements in complete themes have inherit.blank=TRUE" , {
@@ -424,7 +423,7 @@ test_that("current theme can be updated with new elements", {
424
423
# element tree gets merged properly
425
424
register_theme_elements(
426
425
abcde = element_text(color = " blue" , hjust = 0 , vjust = 1 ),
427
- element_tree = list (abcde = el_def(" element_text" , " text" ))
426
+ element_tree = list (abcde = el_def(element_text , " text" ))
428
427
)
429
428
430
429
e1 <- calc_element(" abcde" , plot_theme(b2 ))
@@ -647,7 +646,7 @@ test_that("complete_theme completes a theme", {
647
646
# Registered elements are included
648
647
register_theme_elements(
649
648
test = element_text(),
650
- element_tree = list (test = el_def(" element_text" , " text" ))
649
+ element_tree = list (test = el_def(element_text , " text" ))
651
650
)
652
651
new <- complete_theme(default = gray )
653
652
expect_s3_class(new $ test , " ggplot2::element_text" )
@@ -959,15 +958,11 @@ test_that("Legends can on all sides of the plot with custom justification", {
959
958
})
960
959
961
960
test_that(" Strips can render custom elements" , {
962
- element_test <- function (... ) {
963
- el <- element_text(... )
964
- class(el ) <- c(' element_test' , ' element_text' , ' element' )
965
- el
966
- }
967
- element_grob.element_test <- function (element , label = " " , x = NULL , y = NULL , ... ) {
968
- rectGrob(width = unit(1 , " cm" ), height = unit(1 , " cm" ))
969
- }
970
- registerS3method(" element_grob" , " element_test" , element_grob.element_test )
961
+ element_test <- S7 :: new_class(" element_test" , element_text )
962
+ S7 :: method(element_grob , element_test ) <-
963
+ function (element , label = " " , x = NULL , y = NULL , ... ) {
964
+ rectGrob(width = unit(1 , " cm" ), height = unit(1 , " cm" ))
965
+ }
971
966
972
967
df <- data_frame(x = 1 : 3 , y = 1 : 3 , a = letters [1 : 3 ])
973
968
plot <- ggplot(df , aes(x , y )) +
0 commit comments