plotly / plotly/plotly.R

Tooltip along the length of a segment

Open
#1,832 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
R
Stars
2.7k
Forks
641
PR merge metrics
No merged PRs in 30d

Description

I posted about this here in RStudio community in mid-June but didn't get any responses.

Edit Aug17: Stopped using x-unified hovermode, added new video to show the problem more clearly. Also posted another RStudio community post.

Maybe this feature exists, but I'm missing it? I would like to have a tooltip that extends across the entire length of a segment from add_segments().

Example:

library(plotly)
my_data <- data.frame(
  x = c(1, 6), xend = c(5, 10),
  y = c(1, 2), yend = c(1, 2),
  text = c("First", "Second")
)

plot_ly(my_data, x = ~x, xend = ~xend, y = ~y, yend = ~yend, 
        text = ~text, hoverinfo = "text") %>%
  add_segments()

This will put a tooltip at the beginning and the end of the segment, but users will tend to put their cursor near the middle of the segment and expect a tooltip to appear. Even more importantly, users won't get a tooltip if they are zoomed into the middle of a segment.

demonstration of the problem


I've been getting around this problem by using add_lines() instead, but this is terribly inefficient when I'm trying to plot thousands of these segments at once, and it doesn't solve the zooming problem. E.g.

my_data <- data.frame(
  x = c(seq(1, 5, length.out = 10), NA,
         seq(6, 10, length.out = 10)),
  y = c(rep(1, 10), NA, 
         rep(2, 10)),
  text = c(rep("First", 10), NA,
           rep("Second", 10))
)

plot_ly(my_data, x = ~x,y = ~y,
        text = ~text, hoverinfo = "text") %>%
  add_lines() %>%
  layout(hovermode = "x unified")

demonstration of problem work-around

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at the R entry point add_segments() and compare it with the add_lines() workaround shown in the examples. Reproduce hover behavior at segment endpoints, the middle, and after zooming; done means a segment's tooltip appears across its full length without requiring the workaround.

Written by the indexing model from the issue text.

Assessment

Tech stack
plotly, r
Domain
data-visualization
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.