enable formatting numbers with natural language suffixes, k(ilo), M(illion), B(illion)
まだ誰も着手していません。
- 主要言語
- JavaScript
- スター
- 18.3k
- フォーク
- 2k
- 平均マージ
- 2日 12時間
- マージ済み PR(30日)
- 28
説明
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
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
まず、hovertemplate の値、特に %{y}、%{text}、%{customdata[0]} がどのようにフォーマットされるか、また軸とデフォルトのホバーに d3-format がどのように使用されているかを追跡します。既存の動作を例と比較し、明示的なフォーマット指定子が指定されていない場合はカスタムデータがデフォルトのフォーマットに従うことを示すテストを定義します。要求された自然言語のサフィックスも含めます。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- d3, javascript
- 領域
- data-visualization
- issue の種類
- 機能追加
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 32/100