Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix wrong tooltip when ggplotly with geom_line(group=) #773

Merged
merged 3 commits into from
Nov 1, 2016

Conversation

zeehio
Copy link
Contributor

@zeehio zeehio commented Oct 28, 2016

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.

  # Tooltips with y == 10 should belong to Sample2 in this example
  mydata <- data.frame(id = paste0("Sample", rep(1:2, times = 4)),
                       x = rep(1:4, each = 2),
                       y = rep(c(1, 10), times = 4),
                       stringsAsFactors = FALSE)
  #        id x  y
  #1 Sample1 1  1
  #2 Sample2 1 10
  #3 Sample1 2  1
  #4 Sample2 2 10
  #5 Sample1 3  1
  #6 Sample2 3 10
  #7 Sample1 4  1
  #8 Sample2 4 10
  gplt <- ggplot(mydata) + geom_line(aes(x=x, y = y, group = id))
  pltly <- plotly::ggplotly(gplt)
  pltly
  y_equal_ten <- grepl("y: 10", pltly$x$data[[1]]$text)
  sample_2 <- grepl("id: Sample2", pltly$x$data[[1]]$text)
  expect_that(all(y_equal_ten == sample_2))

The tooltip in the image should show "id: Sample2"

image

Checked against current master:

plotly        4.5.5.9000 2016-10-28 Github (ropensci/plotly@32020c2)

@zeehio zeehio changed the title Plot with geom_line(group=) shows wrong tooltip Test case showing bug: Plot with geom_line(group=) shows wrong tooltip Oct 28, 2016
@zeehio
Copy link
Contributor Author

zeehio commented Oct 28, 2016

Closes #774

image

@zeehio zeehio changed the title Test case showing bug: Plot with geom_line(group=) shows wrong tooltip Fix wrong tooltip when ggplotly with geom_line(group=) Oct 28, 2016
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.
@zeehio zeehio force-pushed the fix_tooltip_on_geom_line_group branch from 4b949f8 to 4d3ac60 Compare October 31, 2016 07:22
@cpsievert
Copy link
Collaborator

Great work, thanks!

@cpsievert cpsievert merged commit 2e3f20d into plotly:master Nov 1, 2016
@zeehio zeehio deleted the fix_tooltip_on_geom_line_group branch November 1, 2016 20:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants