forked from animint/animint2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test-renderer4-geom-point-stroke.R
41 lines (31 loc) · 1.39 KB
/
test-renderer4-geom-point-stroke.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
acontext("a_geom_point_stroke")
stroke_in_R <- 5
p1 <- a_plot(mtcars, a_aes(wt, mpg)) +
a_geom_point(shape = 21, colour = "black", fill = "white",
size = 5, stroke = stroke_in_R)
p2 <- a_plot(mtcars, a_aes(wt, mpg, stroke=cyl)) +
a_geom_point(shape = 21, colour = "black", fill = "white", size = 5)
viz <- list(p1=p1, p2=p2)
info <- animint2HTML(viz)
test_that("points are rendered with stroke-width", {
stroke_vals <-
getStyleValue(info$html, '//g[@class="a_geom1_point_p1"]//circle',
"stroke-width")
# stroke-width is rendered for every point
expect_equal(length(stroke_vals), length(mtcars$wt))
stroke_vals_unique <- unique(stroke_vals)
expect_equal(length(stroke_vals_unique), 1)
stroke_width_val <- as.numeric(gsub("[^0-9]", "", stroke_vals_unique))
expect_equal(stroke_width_val, stroke_in_R)
})
test_that("a_aes(stroke) works", {
stroke_vals_2 <-
getStyleValue(info$html, '//g[@class="a_geom2_point_p2"]//circle',
"stroke-width")
expect_equal(length(stroke_vals_2), length(mtcars$wt))
stroke_vals_unique_2 <- unique(stroke_vals_2)
expect_equal(length(stroke_vals_unique_2), length(unique(mtcars$cyl)))
# Check that the values of the stroke are taken from mtcars$cyl
stroke_width_vals <- as.numeric(gsub("[^0-9]", "", stroke_vals_unique_2))
expect_identical(sort(stroke_width_vals), sort(unique(mtcars$cyl)))
})