forked from animint/animint2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test-renderer1-many-facets.R
65 lines (58 loc) · 2.17 KB
/
test-renderer1-many-facets.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
library(testthat)
acontext("many facets")
n.circles <- 40
df <- data.frame(x=0, y=0, a_facet=1:n.circles)
gg <- a_plot()+
a_geom_point(a_aes(x, y), data=df)+
a_theme_bw()+
a_theme(panel.margin=grid::unit(0, "cm"))
viz <-
list(horizontal=gg+
a_theme_animint(width=n.circles * 30 + 50)+
a_facet_grid(. ~ a_facet),
vertical=gg+
a_theme_animint(height=n.circles * 30 + 50)+
a_facet_grid(a_facet ~ .))
info <- animint2HTML(viz)
test_that("points have positive positions", {
circle.list <-
getNodeSet(info$html, '//circle')
expect_equal(length(circle.list), n.circles * 2)
xy.vec <- as.numeric(sapply(circle.list, function(circle){
xmlAttrs(circle)[c("cx", "cy")]
}))
expect_true(all(0 < xy.vec))
})
test_that("no horizontal space between border_rects", {
rect.list <- getNodeSet(
info$html, '//svg[@id="plot_horizontal"]//rect[@class="border_rect"]')
expect_equal(length(rect.list), n.circles)
first <- xmlAttrs(rect.list[[1]])
first.right <- as.numeric(first[["x"]])+as.numeric(first[["width"]])
second <- xmlAttrs(rect.list[[2]])
second.left <- as.numeric(second[["x"]])
expect_equal(first.right, second.left)
})
test_that("no vertical space between border_rects", {
rect.list <- getNodeSet(
info$html, '//svg[@id="plot_vertical"]//rect[@class="border_rect"]')
expect_equal(length(rect.list), n.circles)
first <- xmlAttrs(rect.list[[1]])
first.bottom <- as.numeric(first[["y"]])+as.numeric(first[["height"]])
second <- xmlAttrs(rect.list[[2]])
second.top <- as.numeric(second[["y"]])
expect_equal(first.bottom, second.top)
})
test_that("right strips all at the same x position", {
text.list <- getNodeSet(
info$html, '//svg[@id="plot_vertical"]//g[@class="rightStrip"]//text')
expect_equal(length(text.list), n.circles)
translate.vec <- sapply(text.list, function(x)xmlAttrs(x)[["transform"]])
translate.mat <- str_match_perl(translate.vec, translatePattern)
x.vec <- as.numeric(translate.mat[, "x"])
expected.val <- x.vec[[1]]
expected.vec <- rep(expected.val, length(x.vec))
## print(rbind(computed=x.vec,
## expected=expected.vec))
expect_equal(x.vec, expected.vec)
})