enable formatting numbers with natural language suffixes, k(ilo), M(illion), B(illion)
Chưa có ai nhận issue này.
- Ngôn ngữ chính
- JavaScript
- Star
- 18.3k
- Fork
- 2k
- Merge trung bình
- 2 ngày 12 giờ
- Pull request đã merge (30 ngày)
- 28
Mô tả
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
Hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Hướng nghiên cứu
Bắt đầu bằng cách theo dõi cách các giá trị của hovertemplate, đặc biệt là %{y}, %{text} và %{customdata[0]}, được định dạng, cũng như cách d3-format được sử dụng cho các trục và hover mặc định. So sánh hành vi hiện có với ví dụ, sau đó xác định các bài kiểm thử cho thấy dữ liệu tùy chỉnh tuân theo định dạng mặc định, trừ khi một bộ chỉ định định dạng rõ ràng được cung cấp, bao gồm cả các hậu tố ngôn ngữ tự nhiên được yêu cầu.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Đánh giá
- Công nghệ
- d3, javascript
- Lĩnh vực
- data-visualization
- Loại issue
- Tính năng
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức độ hoạt động
- Đình trệ
- Độ rõ ràng
- Khá rõ ràng
- Mức phù hợp với người mới
- 32/100