Skip to content

Commit 6f91b76

Browse files
committed
bugfix geom_point stroke param
1 parent b4eed26 commit 6f91b76

File tree

2 files changed

+24
-26
lines changed

2 files changed

+24
-26
lines changed

inst/htmljs/animint.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1444,7 +1444,7 @@ var animint = function (to_select, json_file) {
14441444
if (g_info.geom == "point") {
14451445
g_info.style_list = [
14461446
"opacity","stroke","stroke-width","stroke-dasharray","fill"];
1447-
style_on_funs["stroke-width"] = get_attr("stroke");
1447+
style_on_funs["stroke-width"] = get_stroke_width;
14481448
eActions = function (e) {
14491449
e.attr("cx", toXY("x", "x"))
14501450
.attr("cy", toXY("y", "y"))
Lines changed: 23 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,39 @@
11
acontext("geom_point_stroke")
22

33
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))
714

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)
1215
info <- animint2HTML(viz)
1316

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")
1922
expect_equal(length(stroke_vals), length(mtcars$wt))
20-
2123
stroke_vals_unique <- unique(stroke_vals)
2224
expect_equal(length(stroke_vals_unique), 1)
23-
2425
stroke_width_val <- as.numeric(gsub("[^0-9]", "", stroke_vals_unique))
2526
expect_equal(stroke_width_val, stroke_in_R)
2627
})
2728

2829
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))
4038
expect_identical(sort(stroke_width_vals), sort(unique(mtcars$cyl)))
4139
})

0 commit comments

Comments
 (0)