Commit 882a9881 by Greg Look

Add currency units from #1910.

parent 0b3e33e2
...@@ -298,6 +298,18 @@ function($, _) { ...@@ -298,6 +298,18 @@ function($, _) {
return kbn.formatBuilders.scaledUnits(1024, units); 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 ///// ///// VALUE FORMATS /////
// Dimensionless Units // Dimensionless Units
...@@ -316,6 +328,10 @@ function($, _) { ...@@ -316,6 +328,10 @@ function($, _) {
return kbn.toFixed(100*size, decimals) + '%'; return kbn.toFixed(100*size, decimals) + '%';
}; };
// Currencies
kbn.valueFormats.currencyUSD = kbn.formatBuilders.currency('$');
kbn.valueFormats.currencyGBP = kbn.formatBuilders.currency('£');
// Data // Data
kbn.valueFormats.bits = kbn.formatBuilders.binarySIPrefix('b'); kbn.valueFormats.bits = kbn.formatBuilders.binarySIPrefix('b');
kbn.valueFormats.bytes = kbn.formatBuilders.binarySIPrefix('B'); kbn.valueFormats.bytes = kbn.formatBuilders.binarySIPrefix('B');
...@@ -472,6 +488,13 @@ function($, _) { ...@@ -472,6 +488,13 @@ function($, _) {
] ]
}, },
{ {
text: 'currency',
submenu: [
{text: 'Dollars ($)', value: 'currencyUSD'},
{text: 'Pounds (£)', value: 'currencyGBP'},
]
},
{
text: 'time', text: 'time',
submenu: [ submenu: [
{text: 'Hertz (1/s)', value: 'hertz'}, {text: 'Hertz (1/s)', value: 'hertz'},
......
...@@ -53,6 +53,10 @@ define([ ...@@ -53,6 +53,10 @@ define([
describeValueFormat('percentunit', 0.278, 0, 1, '27.8%'); describeValueFormat('percentunit', 0.278, 0, 1, '27.8%');
describeValueFormat('percentunit', 1.0, 0, 0, '100%'); 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('bytes', -1.57e+308, -1.57e+308, 2, 'NA');
describeValueFormat('ns', 25, 1, 0, '25 ns'); describeValueFormat('ns', 25, 1, 0, '25 ns');
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment