|
1 | 1 | acontext("geom_point_stroke")
|
2 | 2 |
|
3 | 3 | stroke_in_R <- 5
|
4 |
| -p1 <- ggplot(mtcars, aes(wt, mpg)) + |
5 |
| - geom_point(shape = 21, colour = "black", fill = "white", |
6 |
| - size = 5, stroke = stroke_in_R) |
| 4 | +viz <- animint( |
| 5 | + param_stroke=ggplot(mtcars, aes( |
| 6 | + wt, mpg)) + |
| 7 | + geom_point( |
| 8 | + shape = 21, colour = "black", fill = "white", |
| 9 | + size = 5, stroke = stroke_in_R), |
| 10 | + aes_stroke=ggplot(mtcars, aes( |
| 11 | + wt, mpg, stroke=cyl)) + |
| 12 | + geom_point( |
| 13 | + shape = 21, colour = "black", fill = "white", size = 5)) |
7 | 14 |
|
8 |
| -p2 <- ggplot(mtcars, aes(wt, mpg, stroke=cyl)) + |
9 |
| - geom_point(shape = 21, colour = "black", fill = "white", size = 5) |
10 |
| - |
11 |
| -viz <- list(p1=p1, p2=p2) |
12 | 15 | info <- animint2HTML(viz)
|
13 | 16 |
|
14 |
| -test_that("points are rendered with stroke-width", { |
15 |
| - stroke_vals <- |
16 |
| - getStyleValue(info$html, '//g[@class="geom1_point_p1"]//circle', |
17 |
| - "stroke-width") |
18 |
| - # stroke-width is rendered for every point |
| 17 | +test_that("geom_point stroke param rendered with stroke-width", { |
| 18 | + stroke_vals <- getStyleValue( |
| 19 | + info$html, |
| 20 | + '//g[@class="geom1_point_param_stroke"]//circle', |
| 21 | + "stroke-width") |
19 | 22 | expect_equal(length(stroke_vals), length(mtcars$wt))
|
20 |
| - |
21 | 23 | stroke_vals_unique <- unique(stroke_vals)
|
22 | 24 | expect_equal(length(stroke_vals_unique), 1)
|
23 |
| - |
24 | 25 | stroke_width_val <- as.numeric(gsub("[^0-9]", "", stroke_vals_unique))
|
25 | 26 | expect_equal(stroke_width_val, stroke_in_R)
|
26 | 27 | })
|
27 | 28 |
|
28 | 29 | test_that("aes(stroke) works", {
|
29 |
| - stroke_vals_2 <- |
30 |
| - getStyleValue(info$html, '//g[@class="geom2_point_p2"]//circle', |
31 |
| - "stroke-width") |
32 |
| - |
33 |
| - expect_equal(length(stroke_vals_2), length(mtcars$wt)) |
34 |
| - |
35 |
| - stroke_vals_unique_2 <- unique(stroke_vals_2) |
36 |
| - expect_equal(length(stroke_vals_unique_2), length(unique(mtcars$cyl))) |
37 |
| - |
38 |
| - # Check that the values of the stroke are taken from mtcars$cyl |
39 |
| - stroke_width_vals <- as.numeric(gsub("[^0-9]", "", stroke_vals_unique_2)) |
| 30 | + stroke_vals_aes <- getStyleValue( |
| 31 | + info$html, |
| 32 | + '//g[@class="geom2_point_aes_stroke"]//circle', |
| 33 | + "stroke-width") |
| 34 | + expect_equal(length(stroke_vals_aes), length(mtcars$wt)) |
| 35 | + stroke_vals_unique_aes <- unique(stroke_vals_aes) |
| 36 | + expect_equal(length(stroke_vals_unique_aes), length(unique(mtcars$cyl))) |
| 37 | + stroke_width_vals <- as.numeric(gsub("[^0-9]", "", stroke_vals_unique_aes)) |
40 | 38 | expect_identical(sort(stroke_width_vals), sort(unique(mtcars$cyl)))
|
41 | 39 | })
|
0 commit comments