plotly / plotly/plotly.R

Set default button in rangeselector

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

还没有人认领这个 Issue。

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

描述

Stumbled across this topic on SO and wasn't entirely satisfied with the suggested workaround. Is this something that you might want to have a look at?

Here's a minimum reprex: say I wanted to plot daily ozone readings from the airquality dataset against time and add range selectors,

library(plotly)

dat = airquality
dat$Date = as.Date(paste(1973, dat$Month, dat$Day, sep = "-"))

p0 = plot_ly(dat, x = ~ Date, y = ~ Ozone, type = "bar")

p1 = p0 %>% layout(
  xaxis = list(
    rangeselector = list(
      buttons = list(
        list(
          count = 1
          , label = "1 mo"
          , step = "month"
          , stepmode = "backward"
        )
        , list(step = "all")
      )
    )
  )
)
p1

full

, then the default zoom level would always be set to full range. If I wanted the default range to cover the last month only, I could certainly circumvent that through specifying a custom range as suggested in the linked answer,

p1 %>% layout(
  xaxis = list(
    range = c(
      {
        dt = max(dat$Date)
        lubridate::month(dt) = lubridate::month(dt) - 1
        dt
      }
      , max(dat$Date)
    )
  )
)

partial

, which works nicely for point, line, etc. charts. Bar charts (not sure about other types), on the other hand, are being cut off at the first and last position. Now, I could also circumvent that by adding something like paste(dt, "10:00:00") and paste(max(dat$Date), "10:00:00") to my custom range, but I wonder whether this could be made a lot more user-friendly through enabling something like active = TRUE directly in the buttons definition?

贡献指南

打开贡献指南

从这里开始

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

调研方向

使用 plot_ly()、layout()、xaxis 和 rangeselector 按钮重现 airquality reprex,然后将自定义范围的变通方案与所请求的默认按钮行为进行比较。跟踪 rangeselector 按钮和 xaxis 范围的处理方式。完成标准是:按钮可以定义初始范围而不会截断条形图,并且现有示例仍能正常工作。

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

评估

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

把新 issue 发到你的邮箱

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