forked from animint/animint2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest-renderer3-path-key.R
56 lines (51 loc) · 1.6 KB
/
test-renderer3-path-key.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
acontext("path key")
path.list <- list()
N <- 100
x <- 1:N
point <- data.frame(
showSelected.i=1:2)
set.seed(1)
for(group.i in 1:2){
for(showSelected.i in point$showSelected.i){
path.list[[paste(group.i, showSelected.i)]] <-
data.frame(group.i, showSelected.i, x, y=rnorm(N, group.i))
}
}
path <- do.call(rbind, path.list)
viz <- list(
point=a_plot()+
a_geom_point(a_aes(showSelected.i, showSelected.i,
id=paste0("point", showSelected.i)),
clickSelects="showSelected.i",
size=10,
data=point),
transition=a_plot()+
ggtitle("should have animated transition")+
a_geom_path(a_aes(x, y, group=group.i, color=group.i,
key=group.i),
showSelected="showSelected.i",
data=path),
noTransition=a_plot()+
ggtitle("should NOT have animated transition")+
a_geom_path(a_aes(x, y, group=group.i, color=group.i,
key=paste(group.i, showSelected.i)),
showSelected="showSelected.i",
data=path),
first=list(showSelected.i="1"),
duration=list(showSelected.i=3000))
info <- animint2HTML(viz)
getD <- function(html=getHTML()){
node.list <- getNodeSet(html, '//g[@class="PANEL1"]//path')
node.mat <- sapply(node.list, xmlAttrs)
node.mat["d",]
}
test_that("transitions only for equivalent keys", {
d.before <- getD()
clickID("point2")
Sys.sleep(1)
d.during <- getD()
Sys.sleep(3)
d.after <- getD()
expect_identical(d.before == d.during, c(FALSE, FALSE, FALSE, FALSE))
expect_identical(d.during == d.after, c(FALSE, FALSE, TRUE, TRUE))
})