forked from animint/animint2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest-renderer1-facets-strips.R
48 lines (43 loc) · 1.88 KB
/
test-renderer1-facets-strips.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
acontext("facet-strips")
p <- a_plot(mtcars, a_aes(mpg, wt)) +
a_geom_point(colour='grey50', size = 4) +
a_geom_point(a_aes(colour = cyl))
gridViz <-
list(gridPlot=p +
a_facet_grid(cyl~am, labeller = a_label_both))
wrapViz <-
list(wrapPlot=p +
a_facet_wrap(~cyl+am))
test_that("facet_grid() strip a_labels are placed correctly", {
info <- animint2HTML(gridViz)
top <- getNodeSet(info$html, "//g[@class='topStrip']")
# there should one be one 'top_strip' group (their children contain the vital info)
kids <- xmlChildren(top[[1]])
labs <- as.character(sapply(kids, xmlValue))
expect_equal(labs[labs != ""], c("am: 0", "am: 1"))
attrs <- lapply(kids, xmlAttrs)
styles <- as.character(sapply(attrs, "[[", "style"))
# remove leading and trailing white-space
styles <- sub("^\\s+|\\s+$", "", styles)
expect_equal(styles, rep("text-anchor: middle; font-size: 11px;", 2))
transforms <- as.character(sapply(attrs, "[[", "transform"))
# there should one be one 'right_strip' group (their children contain the vital info)
right <- getNodeSet(info$html, "//g[@class='rightStrip']")
kids <- xmlChildren(right[[1]])
labs <- as.character(sapply(kids, xmlValue))
expect_equal(labs[labs != ""], c("cyl: 4", "cyl: 6", "cyl: 8"))
attrs <- lapply(kids, xmlAttrs)
styles <- as.character(sapply(attrs, "[[", "style"))
# remove leading and trailing white-space
styles <- sub("^\\s+|\\s+$", "", styles)
expect_equal(styles, rep("text-anchor: middle; font-size: 11px;", 3))
transforms <- as.character(sapply(attrs, "[[", "transform"))
})
test_that("facet_wrap() strip a_labels are placed correctly", {
info <- animint2HTML(wrapViz)
top <- getNodeSet(info$html, "//g[@class='topStrip']")
kids <- xmlChildren(top[[1]])
labs <- as.character(sapply(kids, xmlValue))
expect_equal(labs, c("4, 0", "4, 1", "6, 0",
"6, 1", "8, 0", "8, 1"))
})