mirror of
https://github.com/grafana/grafana.git
synced 2024-11-25 18:30:41 -06:00
Implement decibel and percentunit units.
Add tests to exercise new units as well.
This commit is contained in:
parent
70269c8196
commit
dc5c3a3939
@ -245,10 +245,10 @@ function($, _) {
|
||||
|
||||
// Formatter which always appends a fixed unit string to the value. No
|
||||
// scaling of the value is performed.
|
||||
kbn.formatBuilders.fixedUnit = function(unit, separator) {
|
||||
kbn.formatBuilders.fixedUnit = function(unit) {
|
||||
return function(size, decimals) {
|
||||
if (size === null) { return ""; }
|
||||
return kbn.toFixed(size, decimals) + (separator || ' ') + unit;
|
||||
return kbn.toFixed(size, decimals) + ' ' + unit;
|
||||
};
|
||||
};
|
||||
|
||||
@ -301,10 +301,20 @@ function($, _) {
|
||||
///// VALUE FORMATS /////
|
||||
|
||||
// Dimensionless Units
|
||||
kbn.valueFormats.none = kbn.toFixed;
|
||||
kbn.valueFormats.short = kbn.formatBuilders.scaledUnits(1000, ['', ' K', ' Mil', ' Bil', ' Tri', ' Quadr', ' Quint', ' Sext', ' Sept']);
|
||||
kbn.valueFormats.ppm = kbn.formatBuilders.fixedUnit('ppm');
|
||||
kbn.valueFormats.percent = kbn.formatBuilders.fixedUnit('%', '');
|
||||
kbn.valueFormats.none = kbn.toFixed;
|
||||
kbn.valueFormats.short = kbn.formatBuilders.scaledUnits(1000, ['', ' K', ' Mil', ' Bil', ' Tri', ' Quadr', ' Quint', ' Sext', ' Sept']);
|
||||
kbn.valueFormats.dB = kbn.formatBuilders.fixedUnit('dB');
|
||||
kbn.valueFormats.ppm = kbn.formatBuilders.fixedUnit('ppm');
|
||||
|
||||
kbn.valueFormats.percent = function(size, decimals) {
|
||||
if (size === null) { return ""; }
|
||||
return kbn.toFixed(size, decimals) + '%';
|
||||
};
|
||||
|
||||
kbn.valueFormats.percentunit = function(size, decimals) {
|
||||
if (size === null) { return ""; }
|
||||
return kbn.toFixed(100*size, decimals) + '%';
|
||||
};
|
||||
|
||||
// Data
|
||||
kbn.valueFormats.bits = kbn.formatBuilders.binarySIPrefix('b');
|
||||
@ -442,6 +452,7 @@ function($, _) {
|
||||
{text: 'none' , value: 'none' },
|
||||
{text: 'short', value: 'short' },
|
||||
{text: 'scaled percentage (0-100)', value: 'percent' },
|
||||
{text: 'unit percentage (0.0-1.0)', value: 'percentunit'},
|
||||
{text: 'ppm', value: 'ppm' },
|
||||
{text: 'decibel', value: 'dB' },
|
||||
]
|
||||
|
@ -26,6 +26,14 @@ define([
|
||||
|
||||
describeValueFormat('none', 2.75e-10, 0, 10, '3e-10');
|
||||
describeValueFormat('none', 0, 0, 2, '0');
|
||||
describeValueFormat('dB', 10, 1000, 2, '10.00 dB');
|
||||
|
||||
describeValueFormat('percent', 0, 0, 0, '0%');
|
||||
describeValueFormat('percent', 53, 0, 1, '53.0%');
|
||||
describeValueFormat('percentunit', 0.0, 0, 0, '0%');
|
||||
describeValueFormat('percentunit', 0.278, 0, 1, '27.8%');
|
||||
describeValueFormat('percentunit', 1.0, 0, 0, '100%');
|
||||
|
||||
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