@@ -7,15 +7,16 @@ test_that("all keys can be drawn without 'params'", {
7
7
8
8
# Render every key
9
9
# If we're to develop new legend keys, we can keep appending this pattern
10
- # for new keys and layout should adjust automatically
10
+ # for new keys and layout should adjust automatically.
11
+ # This is also an implicit test whether the key can be constructed without errors
11
12
keys <- list (
12
13
point = draw_key_point(GeomPoint $ use_defaults(NULL ), params , size ),
13
14
abline = draw_key_abline(GeomAbline $ use_defaults(NULL ), params , size ),
14
15
rect = draw_key_rect(GeomRect $ use_defaults(NULL ), params , size ),
15
16
polygon = draw_key_polygon(GeomPolygon $ use_defaults(NULL ), params , size ),
16
17
blank = draw_key_blank(GeomBlank $ use_defaults(NULL ), params , size ),
17
18
boxplot = draw_key_boxplot(GeomBoxplot $ use_defaults(NULL ), params , size ),
18
- crosssbar = draw_key_crossbar(GeomCrossbar $ use_defaults(NULL ), params , size ),
19
+ crossbar = draw_key_crossbar(GeomCrossbar $ use_defaults(NULL ), params , size ),
19
20
path = draw_key_path(GeomPath $ use_defaults(NULL ), params , size ),
20
21
vpath = draw_key_vpath(GeomPath $ use_defaults(NULL ), params , size ),
21
22
dotplot = draw_key_dotplot(GeomDotplot $ use_defaults(NULL ), params , size ),
@@ -28,8 +29,14 @@ test_that("all keys can be drawn without 'params'", {
28
29
timeseries = draw_key_timeseries(GeomPath $ use_defaults(NULL ), params , size )
29
30
)
30
31
32
+ # Test that we've covered all exported keys above
33
+ nse <- getNamespaceExports(asNamespace(" ggplot2" ))
34
+ nse <- grep(" ^draw_key" , nse , value = TRUE )
35
+ nse <- gsub(" ^draw_key_" , " " , nse )
36
+ expect_in(nse , names(keys ))
37
+
38
+ # Add title to every key
31
39
template <- gtable(width = unit(size , " mm" ), heights = unit(c(1 , size ), c(" lines" , " mm" )))
32
- # Add names
33
40
keys <- Map(
34
41
function (key , name ) {
35
42
text <- textGrob(name , gp = gpar(fontsize = 8 ))
@@ -38,12 +45,14 @@ test_that("all keys can be drawn without 'params'", {
38
45
key = keys , name = names(keys )
39
46
)
40
47
48
+ # Set layout
41
49
n <- length(keys )
42
50
nrow <- ceiling(n / 5 )
43
51
ncol <- ceiling(n / nrow )
44
52
mtx <- matrix (list (zeroGrob()), nrow = nrow , ncol = ncol )
45
53
mtx [seq_along(keys )] <- keys
46
54
55
+ # Render as gtable
47
56
gt <- gtable_matrix(
48
57
name = " layout" , grobs = mtx ,
49
58
widths = unit(rep(size , ncol(mtx )), " mm" ),
@@ -54,5 +63,4 @@ test_that("all keys can be drawn without 'params'", {
54
63
gt <- gtable_add_row_space(gt , unit(1 , " cm" ))
55
64
56
65
expect_doppelganger(" all legend keys" , gt )
57
-
58
66
})
0 commit comments