plotly / plotly/plotly.R

Set default button in rangeselector

Offen
#1,836 0 Kommentare 3 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

Vorherrschende Sprache
R
Sterne
2.7k
Forks
641
PR-Merge-Kennzahlen
Keine gemergten PRs in 30 T.

Beschreibung

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?

Beitragsleitfaden

Beitragsleitfaden öffnen

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

Rechercherichtung

Reproduziere das airquality-reprex mit plot_ly(), layout(), xaxis und rangeselector-Schaltflächen und vergleiche dann den Workaround für den benutzerdefinierten Bereich mit dem angeforderten Verhalten der Standardschaltfläche. Verfolge, wie die rangeselector-Schaltflächen und der xaxis-Bereich verarbeitet werden. Als erledigt gilt es, wenn eine Schaltfläche den initialen Bereich festlegen kann, ohne dass Balkendiagramme abgeschnitten werden, und das bestehende Beispiel weiterhin funktioniert.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
r
Bereich
data-visualization
Issue-Typ
Feature
Schwierigkeit
4/5
Geschätzter Aufwand
3-5 Tage
Aktivitätsstatus
Veraltet
Klarheit
Größtenteils klar
Anfängerfreundlichkeit
35/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.