Date tickformats automatically replaces newline \n with <br>. Causing the same value on the second line to repeat.

Offen
#2,115 1 Kommentar 1 Reaktion 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

Bewertung

Schwierigkeit
3/5
Geschätzter Aufwand
1-2 Tage
Anfängerfreundlichkeit
45/100
Issue-Typ
Bug
Klarheit
Größtenteils klar
Aktivitätsstatus
Veraltet
Tech-Stack
javascript, r

Rechercherichtung

Beginnen Sie mit dem minimalen R-Beispiel in issue #2115 und untersuchen Sie dessen Ausgabe mit plotly_json(), wobei Sie sich darauf konzentrieren, wie das x-Achsen-tickformat \n konvertiert. Vergleichen Sie das Ergebnis mit dem verlinkten JavaScript- und Python-Verhalten; die Aufgabe ist abgeschlossen, wenn R \n beibehält, sodass wiederholte Datumswerte entsprechend dem dokumentierten Verhalten angezeigt werden.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Beschreibung

Custom date tickformat does not respect the newline character \n and automatically replaces it by a break-tag <br />. This has the consequence that values after the specified newline get repeated for each tick-label even though the value is the same.

As this python plotly documentation mentions:

Date axis tick labels have the special property that any portion after the first instance of '\n' in tickformat will appear on a second line only once per unique value, as with the year numbers in the example below. To have the year number appear on every tick label, '<br>' should be used instead of '\n'.

Ploty python and javascript respect the \n but not R.

Minimal example:

library(plotly)
#> loading comments I have committed for this reprex
dt <- data.frame(
    x = as.Date(c('2013-02-04', '2013-04-05', '2013-06-06', '2013-08-07', '2013-10-02')),
    y = c(1,4,5,6,2)
  )
plot_ly(data = dt, x = ~x, y = ~y, type = 'scatter', mode = 'lines') %>%
  layout(xaxis = list(tickformat = '%a %e %b \n %Y'))

Created on 2022-03-31 by the reprex package (v2.0.1)

In specting the above object with plotly_json() and search for tickformat reveals that the format has been updated to: %a %e %b <br /> %Y.

This reprex is an example taken from the javascript documentation where the example shows the correct behaviour of only showing the year 2013 once.

image

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

Beitragsleitfaden

Beitragsleitfaden öffnen

Erste Schritte

  1. Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
  3. Forken Sie das Repository und arbeiten Sie in einem Branch.
  4. Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.

Mehr aus plotly/plotly.R

Alle Issues in plotly/plotly.R

Ähnliche Issues

Weitere Issues zu R

Neue Issues direkt in Ihr Postfach

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