plotly / plotly/plotly.R

Set default button in rangeselector

Aperta
#1,836 0 commenti 3 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Lingua principale
R
Stelle
2.7k
Fork
641
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Descrizione

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?

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Direzione di ricerca

Riproduci il reprex di airquality usando plot_ly(), layout(), xaxis e i pulsanti di rangeselector, quindi confronta la soluzione alternativa per l’intervallo personalizzato con il comportamento richiesto del pulsante predefinito. Traccia il modo in cui vengono gestiti i pulsanti di rangeselector e l’intervallo di xaxis. Il lavoro è completato quando un pulsante può definire l’intervallo iniziale senza che i grafici a barre vengano tagliati e l’esempio esistente continui a funzionare.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
r
Ambito
data-visualization
Tipo di issue
Funzionalità
Difficoltà
4/5
Tempo stimato
3-5 giorni
Stato di attività
Ferma
Chiarezza
Abbastanza chiara
Idoneità per principianti
35/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.