mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Add currency units from #1910.
This commit is contained in:
parent
0b3e33e226
commit
882a988143
@ -298,6 +298,18 @@ function($, _) {
|
||||
return kbn.formatBuilders.scaledUnits(1024, units);
|
||||
};
|
||||
|
||||
// Currency formatter for prefixing a symbol onto a number. Supports scaling
|
||||
// up to the trillions.
|
||||
kbn.formatBuilders.currency = function(symbol) {
|
||||
var units = ['', 'K', 'M', 'B', 'T'];
|
||||
var scaler = kbn.formatBuilders.scaledUnits(1000, units);
|
||||
return function(size, decimals, scaledDecimals) {
|
||||
if (size === null) { return ""; }
|
||||
var scaled = scaler(size, decimals, scaledDecimals);
|
||||
return symbol + scaled;
|
||||
};
|
||||
};
|
||||
|
||||
///// VALUE FORMATS /////
|
||||
|
||||
// Dimensionless Units
|
||||
@ -316,6 +328,10 @@ function($, _) {
|
||||
return kbn.toFixed(100*size, decimals) + '%';
|
||||
};
|
||||
|
||||
// Currencies
|
||||
kbn.valueFormats.currencyUSD = kbn.formatBuilders.currency('$');
|
||||
kbn.valueFormats.currencyGBP = kbn.formatBuilders.currency('£');
|
||||
|
||||
// Data
|
||||
kbn.valueFormats.bits = kbn.formatBuilders.binarySIPrefix('b');
|
||||
kbn.valueFormats.bytes = kbn.formatBuilders.binarySIPrefix('B');
|
||||
@ -471,6 +487,13 @@ function($, _) {
|
||||
{text: 'decibel', value: 'dB' },
|
||||
]
|
||||
},
|
||||
{
|
||||
text: 'currency',
|
||||
submenu: [
|
||||
{text: 'Dollars ($)', value: 'currencyUSD'},
|
||||
{text: 'Pounds (£)', value: 'currencyGBP'},
|
||||
]
|
||||
},
|
||||
{
|
||||
text: 'time',
|
||||
submenu: [
|
||||
|
@ -53,6 +53,10 @@ define([
|
||||
describeValueFormat('percentunit', 0.278, 0, 1, '27.8%');
|
||||
describeValueFormat('percentunit', 1.0, 0, 0, '100%');
|
||||
|
||||
describeValueFormat('currencyUSD', 7.42, 10000, 2, '$7.42');
|
||||
describeValueFormat('currencyUSD', 1532.82, 1000, 1, '$1.53K');
|
||||
describeValueFormat('currencyUSD', 18520408.7, 10000000, 0, '$19M');
|
||||
|
||||
describeValueFormat('bytes', -1.57e+308, -1.57e+308, 2, 'NA');
|
||||
|
||||
describeValueFormat('ns', 25, 1, 0, '25 ns');
|
||||
|
Loading…
Reference in New Issue
Block a user