dygraphs
dygraphs copied to clipboard
Extend labelsKMB for milli, micro, nano
The option "labelsKMB" in dygraphs 2.1.0 allows automatic labeling with kilo, mega and giga prefixes. It would be great if that could be extended to milli (m), micro (µ) and nano (n).
Or is there maybe another option that allows this already?
By the way: the right unit prefix for kilo would be a lower case k (https://en.wikipedia.org/wiki/Unit_prefix).
Yes, please! 0.1m is just wrong as in the example, 1000 is k
not K
, 1024 may be K
(but never k
) but preferred is Ki
, 1048576 ought to be Mi
, etc.
So, ideally, you’d have these:
y Yocto‑ (10⁻²⁴) (1000⁻⁸)
z Zepto‑ (10⁻²¹) (1000⁻⁷)
a Atto‑ (10⁻¹⁸) (1000⁻⁶)
f Femto‑ (10⁻¹⁵) (1000⁻⁵)
p Piko‑ (10⁻¹²) (1000⁻⁴)
n Nano‑ (10⁻⁹) (1000⁻³)
µ Mikro‑ (10⁻⁶) (1000⁻²)
m Milli‑ (10⁻³) (1000⁻¹)
k Kilo‑ (10³) (1000¹)
M Mega‑ (10⁶) (1000²)
G Giga‑ (10⁹) (1000³)
T Tera‑ (10¹²) (1000⁴)
P Peta‑ (10¹⁵) (1000⁵)
E Exa‑ (10¹⁸) (1000⁶)
Z Zetta‑ (10²¹) (1000⁷)
Y Yotta‑ (10²⁴) (1000⁸)
Ki Kibi‑ (2¹⁰) (1024¹)
Mi Mebi‑ (2²⁰) (1024²)
Gi Gibi‑ (2³⁰) (1024³)
Ti Tebi‑ (2⁴⁰) (1024⁴)
Pi Pebi‑ (2⁵⁰) (1024⁵)
Ei Exbi‑ (2⁶⁰) (1024⁶)
Zi Zebi‑ (2⁷⁰) (1024⁷)
Yi Yobi‑ (2⁸⁰) (1024⁸)
But a “legacy” mode for 2ˣ-based units in which they use K/M/G/T/P/E/Z/Y would be acceptable as option, and this is the only place where an upper-case K is okay.
The demo also shows Q, whatever that is supposed to be, it’s not a præfix.
I think https://github.com/mirabilos/dygraphs/compare/6d28d02b257402b8b1eba943b1d0d3ad6b008a2b...mirabilos:dygraphs:pr-units should do it, but I need to learn how to build and unit-test this first, then adapt the tests. (I’m an experienced developer, but more on the assembly/C level and playing with js for this library here.)
I also found that labelsKMG2 does weird things for “small” values (like milli), which danvk already noted, but in addition probably 10-based instead of 2-based. This is fixed.
I made using both options together activate the “legacy/deprecated” mode with K/M/G… for 1024-based and even using m/µ/n… there (the normal labelsKMG2 after this patch honours IEC 60027-2 and therefore has no “small” præficēs).
Comments?