Skip to content

Commit 51876e1

Browse files
committed
test case for buggy geom_line(group=...) tooltip
This test case shows a plot with two lines where the tooltip does not contain the right text on all the points. The `group` aesthetic in `geom_line` is not properly set in the tooltip rendering mismatched "id: Sample2" tooltips on Sample1 data points and viceversa.
1 parent 32020c2 commit 51876e1

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

tests/testthat/test-ggplot-tooltip.R

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,27 @@ test_that("group domain is included in hovertext", {
6969
expect_true(all(grepl(pattern, txt)))
7070
})
7171

72+
test_that("tooltip elements are not crossed", {
73+
# Tooltips with y == 10 should belong to Sample2 in this example
74+
mydata <- data.frame(id = paste0("Sample", rep(1:2, times = 4)),
75+
x = rep(1:4, each = 2),
76+
y = rep(c(1, 10), times = 4),
77+
stringsAsFactors = FALSE)
78+
# id x y
79+
# 1 Sample1 1 1
80+
# 2 Sample2 1 10
81+
# 3 Sample1 2 1
82+
# 4 Sample2 2 10
83+
# 5 Sample1 3 1
84+
# 6 Sample2 3 10
85+
# 7 Sample1 4 1
86+
# 8 Sample2 4 10
87+
gplt <- ggplot(mydata) + geom_line(aes(x=x, y = y, group = id))
88+
pltly <- plotly::ggplotly(gplt)
89+
y_equal_ten <- grepl("y: 10", pltly$x$data[[1]]$text)
90+
sample_2 <- grepl("id: Sample2", pltly$x$data[[1]]$text)
91+
expect_equal(y_equal_ten, sample_2)
92+
})
7293

7394
labelDF <- data.frame(
7495
label = paste0(("label"), c(1:10)),

0 commit comments

Comments
 (0)