plotly / plotly/plotly.R

Tooltip along the length of a segment

未关闭
#1,832 2 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

主要语言
R
星标
2.7k
派生
641
PR 合并指标
30 天内没有已合并 PR

描述

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

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

调研方向

从 R 入口 add_segments() 开始,并将其与示例中展示的 add_lines() 变通方案进行比较。复现 segment 端点、中间位置以及缩放后的悬停行为;当 segment 的 tooltip 能够在其整个长度上显示且不需要变通方案时,即视为完成。

由索引模型根据 Issue 内容生成。

评估

技术栈
plotly, r
领域
data-visualization
Issue 类型
功能
难度
4/5
预计耗时
3-5 天
活跃度
停滞
描述清晰度
基本清楚
新手友好度
38/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。