Library to scale and format numbers with common units. In very early stages of development, probably not generally useful yet.
bower install https://github.com/Netuitive/kbn#master
gulp
gulp production
kbn.findUnitFormat(unit)
Given a string will attempt to find a unit.
kbn.formatValue(value, unit)
Given a value and unit will scale the value by the unit, round to 4 significant digits, and return a string representation of the value with the scaled units.
Supported unit codes recognized by the formatValue api call.
code | unit | |
---|---|---|
general |
||
short | short | |
percent | percent (0-100) | |
percentunit | percent (0.0-1.0) | |
humidity | Humidity (%H) | |
ppm | ppm | |
dB | decibel | |
data |
||
bits | bits | |
bytes | bytes | |
kbytes | kilobytes | |
mbytes | megabytes | |
gbytes | gigabytes | |
pps | packets/sec | |
bps | bits/sec | |
Bps | bytes/sec | |
time |
||
hertz | Hertz (1/s) | |
ns | nanoseconds (ns) | |
µs | microseconds (µs) | |
ms | milliseconds (ms) | |
s | seconds (s) | |
m | minutes (m) | |
h | hours (h) | |
d | days (d) | |
throughput |
||
ops | ops/sec (ops) | |
rps | reads/sec (rps) | |
wps | writes/sec (wps) | |
iops | I/O ops/sec (iops) | |
memory |
||
fps | faults/sec (fps) | |
Pps | pages/sec (Pps) | |
currency |
||
currencyUSD | Dollars ($) | |
currencyGBP | Pounds (£) | |
currencyEUR | Euro (€) | |
currencyJPY | Yen (¥) | |
length |
||
lengthmm | millimetre (mm) | |
lengthm | meter (m) | |
lengthkm | kilometer (km) | |
lengthmi | mile (mi) | |
velocity |
||
velocityms | m/s | |
velocitykmh | km/h | |
velocitymph | mph | |
velocityknot | knot (kn) | |
volume |
||
mlitre | millilitre | |
litre | litre | |
m3 | cubic metre | |
energy |
||
watt | watt (W) | |
kwatt | kilowatt (kW) | |
watth | watt-hour (Wh) | |
kwatth | kilowatt-hour (kWh) | |
joule | joule (J) | |
ev | electron volt (eV) | |
amp | Ampere (A) | |
volt | Volt (V) | |
temperature |
||
celsius | Celcius (°C) | |
farenheit | Farenheit (°F) | |
kelvin | Kelvin (K) | |
pressure |
||
pressurembar | Millibars | |
pressurehpa | Hectopascals | |
pressurehg | Inches of mercury | |
pressurepsi | PSI |
originally imported from Graphana: https://github.com/grafana/grafana/blob/8ee0e5d11f8427b5a68aab69c73c6d4809bdf5bb/public/app/core/utils/kbn.js