enable formatting numbers with natural language suffixes, k(ilo), M(illion), B(illion)
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- JavaScript
- Sterne
- 18.3k
- Forks
- 2k
- Ø Merge
- 2 T. 12 Std.
- Gemergte PRs (30 T.)
- 28
Beschreibung
Plotly doesn't currently let me format numbers, e.g. in hover templates, in "human" or "business" form, by which I mean essentially SI representation but with the suffix replacements k->k(ilo) M->M(illion), G->B(illion), T->T(trillion),.... (by pure luck, this is really just one necessary replacement in the range I've listed).
The reason seems to be that plotly relies on d3-format, which claims to "format numbers for human consumption" but misses the one format non-technically trained humans can actually consume at ease.
However, oddly plotly does use the "human readable" form by default for the X and Y columns in default hover displays, even when they're included in the hover templates manually as %{y}, but not for custom data included via %{customdata[0]} (see the MWE below). This in some sense makes this a bug: You want to include two columns of data in the same way, using the same format specifier, but you get different results.
Instead of waiting on d3, I would like to make this feature request: I believe plotly should default for custom data to the same formatting it uses by default elsewhere (including axes labels), unless a format specifier is explicitly listed, thus increasing consistency.
Example: Despite using text=y and hovertemplate ='%{y}<br>%{text}', I get different representations:
import plotly.graph_objects as go
y = [2, 100000, 2000000, 2000000000]
fig = go.Figure(go.Scatter(
x = [1,2,3,4],
y = y,
text = y,
hovertemplate ='%{y}<br>%{text}'
))
fig.show()

Similar requests elsewhere:
https://github.com/plotly/plotly.py/issues/1222
https://community.plotly.com/t/custom-si-unit-prefixes/29739/4
https://github.com/d3/d3/issues/2241
https://github.com/d3/d3-format/issues/71
Beitragsleitfaden
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Rechercherichtung
Beginne damit nachzuverfolgen, wie Werte von hovertemplate, insbesondere %{y}, %{text} und %{customdata[0]}, formatiert werden und wie d3-format für Achsen und standardmäßige Hovers verwendet wird. Vergleiche das bestehende Verhalten mit dem Beispiel und definiere anschließend Tests, die zeigen, dass benutzerdefinierte Daten der Standardformatierung folgen, sofern kein expliziter Formatspezifizierer angegeben ist, einschließlich der angeforderten Suffixe in natürlicher Sprache.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- d3, javascript
- Bereich
- data-visualization
- Issue-Typ
- Feature
- Schwierigkeit
- 4/5
- Geschätzter Aufwand
- 3-5 Tage
- Aktivitätsstatus
- Veraltet
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 32/100