plotly / plotly/plotly.js

enable formatting numbers with natural language suffixes, k(ilo), M(illion), B(illion)

Ouverte
#6,091 3 commentaires 5 réactions 0 personnes assignées Voir sur GitHub

Personne n'a encore pris cette issue.

feature P3
Langage dominant
JavaScript
Étoiles
18.3k
Forks
2k
Merge moyen
2 j 12 h
PR mergées (30 j)
28

Description

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()

image

Similar requests elsewhere:
https://github.com/plotly/plotly.py/issues/1222

https://stackoverflow.com/questions/68005050/b-billions-instead-of-g-giga-in-python-plotly-customdata-si-prefix-d3

https://stackoverflow.com/questions/17037023/how-to-get-localizable-or-customizable-si-codes-with-d3-format

https://community.plotly.com/t/custom-si-unit-prefixes/29739/4

https://stackoverflow.com/questions/40774677/d3-formatting-tick-value-to-show-b-billion-instead-of-g-giga

https://github.com/d3/d3/issues/2241

https://stackoverflow.com/questions/64313173/how-to-hover-number-formatting-to-k-or-m-accordingly-in-r-plotly-pie-charts-and

https://github.com/d3/d3-format/issues/71

https://github.com/d3/d3-format/pull/81

https://github.com/d3/d3-format/pull/96

Guide de contribution

Ouvrir le guide de contribution

Par où commencer

  1. Lisez l'issue en entier, puis le guide de contribution du projet.
  2. Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
  3. Forkez le dépôt et travaillez sur une branche.
  4. Ouvrez une pull request qui référence le numéro de l'issue.

Piste de recherche

Commencez par suivre la manière dont les valeurs de hovertemplate, en particulier %{y}, %{text} et %{customdata[0]}, sont formatées, ainsi que la manière dont d3-format est utilisé pour les axes et les hovers par défaut. Comparez le comportement existant avec l’exemple, puis définissez des tests montrant que les données personnalisées suivent le formatage par défaut, sauf si un spécificateur de format explicite est fourni, y compris les suffixes en langage naturel demandés.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Évaluation

Stack technique
d3, javascript
Domaine
data-visualization
Type d'issue
Fonctionnalité
Difficulté
4/5
Temps estimé
3-5 jours
Activité
À l'abandon
Clarté
Plutôt claire
Accessibilité débutants
32/100

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.