Commit bcf88f61 by Torkel Ödegaard Committed by GitHub

Merge pull request #14867 from grafana/value-format-fixes2

Updated singlestat to use new value format function signature
parents b1f5a232 37c5ced0
...@@ -22,7 +22,7 @@ import { binarySIPrefix, currency, decimalSIPrefix } from './symbolFormatters'; ...@@ -22,7 +22,7 @@ import { binarySIPrefix, currency, decimalSIPrefix } from './symbolFormatters';
export const getCategories = (): ValueFormatCategory[] => [ export const getCategories = (): ValueFormatCategory[] => [
{ {
name: 'none', name: 'Misc',
formats: [ formats: [
{ name: 'none', id: 'none', fn: toFixed }, { name: 'none', id: 'none', fn: toFixed },
{ {
...@@ -41,7 +41,7 @@ export const getCategories = (): ValueFormatCategory[] => [ ...@@ -41,7 +41,7 @@ export const getCategories = (): ValueFormatCategory[] => [
], ],
}, },
{ {
name: 'acceleration', name: 'Acceleration',
formats: [ formats: [
{ name: 'Meters/sec²', id: 'accMS2', fn: toFixedUnit('m/sec²') }, { name: 'Meters/sec²', id: 'accMS2', fn: toFixedUnit('m/sec²') },
{ name: 'Feet/sec²', id: 'accFS2', fn: toFixedUnit('f/sec²') }, { name: 'Feet/sec²', id: 'accFS2', fn: toFixedUnit('f/sec²') },
...@@ -49,7 +49,7 @@ export const getCategories = (): ValueFormatCategory[] => [ ...@@ -49,7 +49,7 @@ export const getCategories = (): ValueFormatCategory[] => [
], ],
}, },
{ {
name: 'angle', name: 'Angle',
formats: [ formats: [
{ name: 'Degrees (°)', id: 'degree', fn: toFixedUnit('°') }, { name: 'Degrees (°)', id: 'degree', fn: toFixedUnit('°') },
{ name: 'Radians', id: 'radian', fn: toFixedUnit('rad') }, { name: 'Radians', id: 'radian', fn: toFixedUnit('rad') },
...@@ -57,7 +57,7 @@ export const getCategories = (): ValueFormatCategory[] => [ ...@@ -57,7 +57,7 @@ export const getCategories = (): ValueFormatCategory[] => [
], ],
}, },
{ {
name: 'area', name: 'Area',
formats: [ formats: [
{ name: 'Square Meters (m²)', id: 'areaM2', fn: toFixedUnit('m²') }, { name: 'Square Meters (m²)', id: 'areaM2', fn: toFixedUnit('m²') },
{ name: 'Square Feet (ft²)', id: 'areaF2', fn: toFixedUnit('ft²') }, { name: 'Square Feet (ft²)', id: 'areaF2', fn: toFixedUnit('ft²') },
...@@ -65,7 +65,7 @@ export const getCategories = (): ValueFormatCategory[] => [ ...@@ -65,7 +65,7 @@ export const getCategories = (): ValueFormatCategory[] => [
], ],
}, },
{ {
name: 'computation throughput', name: 'Computation',
formats: [ formats: [
{ name: 'FLOP/s', id: 'flops', fn: decimalSIPrefix('FLOP/s') }, { name: 'FLOP/s', id: 'flops', fn: decimalSIPrefix('FLOP/s') },
{ name: 'MFLOP/s', id: 'mflops', fn: decimalSIPrefix('FLOP/s', 2) }, { name: 'MFLOP/s', id: 'mflops', fn: decimalSIPrefix('FLOP/s', 2) },
...@@ -76,7 +76,7 @@ export const getCategories = (): ValueFormatCategory[] => [ ...@@ -76,7 +76,7 @@ export const getCategories = (): ValueFormatCategory[] => [
], ],
}, },
{ {
name: 'concentration', name: 'Concentration',
formats: [ formats: [
{ name: 'parts-per-million (ppm)', id: 'ppm', fn: toFixedUnit('ppm') }, { name: 'parts-per-million (ppm)', id: 'ppm', fn: toFixedUnit('ppm') },
{ name: 'parts-per-billion (ppb)', id: 'conppb', fn: toFixedUnit('ppb') }, { name: 'parts-per-billion (ppb)', id: 'conppb', fn: toFixedUnit('ppb') },
...@@ -93,7 +93,7 @@ export const getCategories = (): ValueFormatCategory[] => [ ...@@ -93,7 +93,7 @@ export const getCategories = (): ValueFormatCategory[] => [
], ],
}, },
{ {
name: 'currency', name: 'Currency',
formats: [ formats: [
{ name: 'Dollars ($)', id: 'currencyUSD', fn: currency('$') }, { name: 'Dollars ($)', id: 'currencyUSD', fn: currency('$') },
{ name: 'Pounds (£)', id: 'currencyGBP', fn: currency('£') }, { name: 'Pounds (£)', id: 'currencyGBP', fn: currency('£') },
...@@ -113,7 +113,7 @@ export const getCategories = (): ValueFormatCategory[] => [ ...@@ -113,7 +113,7 @@ export const getCategories = (): ValueFormatCategory[] => [
], ],
}, },
{ {
name: 'data (IEC)', name: 'Data (IEC)',
formats: [ formats: [
{ name: 'bits', id: 'bits', fn: binarySIPrefix('b') }, { name: 'bits', id: 'bits', fn: binarySIPrefix('b') },
{ name: 'bytes', id: 'bytes', fn: binarySIPrefix('B') }, { name: 'bytes', id: 'bytes', fn: binarySIPrefix('B') },
...@@ -123,7 +123,7 @@ export const getCategories = (): ValueFormatCategory[] => [ ...@@ -123,7 +123,7 @@ export const getCategories = (): ValueFormatCategory[] => [
], ],
}, },
{ {
name: 'data (Metric)', name: 'Data (Metric)',
formats: [ formats: [
{ name: 'bits', id: 'decbits', fn: decimalSIPrefix('d') }, { name: 'bits', id: 'decbits', fn: decimalSIPrefix('d') },
{ name: 'bytes', id: 'decbytes', fn: decimalSIPrefix('B') }, { name: 'bytes', id: 'decbytes', fn: decimalSIPrefix('B') },
...@@ -133,7 +133,7 @@ export const getCategories = (): ValueFormatCategory[] => [ ...@@ -133,7 +133,7 @@ export const getCategories = (): ValueFormatCategory[] => [
], ],
}, },
{ {
name: 'data rate', name: 'Data Rate',
formats: [ formats: [
{ name: 'packets/sec', id: 'pps', fn: decimalSIPrefix('pps') }, { name: 'packets/sec', id: 'pps', fn: decimalSIPrefix('pps') },
{ name: 'bits/sec', id: 'bps', fn: decimalSIPrefix('bps') }, { name: 'bits/sec', id: 'bps', fn: decimalSIPrefix('bps') },
...@@ -147,7 +147,7 @@ export const getCategories = (): ValueFormatCategory[] => [ ...@@ -147,7 +147,7 @@ export const getCategories = (): ValueFormatCategory[] => [
], ],
}, },
{ {
name: 'date & time', name: 'Date & Time',
formats: [ formats: [
{ name: 'YYYY-MM-DD HH:mm:ss', id: 'dateTimeAsIso', fn: dateTimeAsIso }, { name: 'YYYY-MM-DD HH:mm:ss', id: 'dateTimeAsIso', fn: dateTimeAsIso },
{ name: 'DD/MM/YYYY h:mm:ss a', id: 'dateTimeAsUS', fn: dateTimeAsUS }, { name: 'DD/MM/YYYY h:mm:ss a', id: 'dateTimeAsUS', fn: dateTimeAsUS },
...@@ -155,7 +155,7 @@ export const getCategories = (): ValueFormatCategory[] => [ ...@@ -155,7 +155,7 @@ export const getCategories = (): ValueFormatCategory[] => [
], ],
}, },
{ {
name: 'energy', name: 'Energy',
formats: [ formats: [
{ name: 'Watt (W)', id: 'watt', fn: decimalSIPrefix('W') }, { name: 'Watt (W)', id: 'watt', fn: decimalSIPrefix('W') },
{ name: 'Kilowatt (kW)', id: 'kwatt', fn: decimalSIPrefix('W', 1) }, { name: 'Kilowatt (kW)', id: 'kwatt', fn: decimalSIPrefix('W', 1) },
...@@ -182,7 +182,7 @@ export const getCategories = (): ValueFormatCategory[] => [ ...@@ -182,7 +182,7 @@ export const getCategories = (): ValueFormatCategory[] => [
], ],
}, },
{ {
name: 'flow', name: 'Flow',
formats: [ formats: [
{ name: 'Gallons/min (gpm)', id: 'flowgpm', fn: toFixedUnit('gpm') }, { name: 'Gallons/min (gpm)', id: 'flowgpm', fn: toFixedUnit('gpm') },
{ name: 'Cubic meters/sec (cms)', id: 'flowcms', fn: toFixedUnit('cms') }, { name: 'Cubic meters/sec (cms)', id: 'flowcms', fn: toFixedUnit('cms') },
...@@ -194,7 +194,7 @@ export const getCategories = (): ValueFormatCategory[] => [ ...@@ -194,7 +194,7 @@ export const getCategories = (): ValueFormatCategory[] => [
], ],
}, },
{ {
name: 'force', name: 'Force',
formats: [ formats: [
{ name: 'Newton-meters (Nm)', id: 'forceNm', fn: decimalSIPrefix('Nm') }, { name: 'Newton-meters (Nm)', id: 'forceNm', fn: decimalSIPrefix('Nm') },
{ name: 'Kilonewton-meters (kNm)', id: 'forcekNm', fn: decimalSIPrefix('Nm', 1) }, { name: 'Kilonewton-meters (kNm)', id: 'forcekNm', fn: decimalSIPrefix('Nm', 1) },
...@@ -203,7 +203,7 @@ export const getCategories = (): ValueFormatCategory[] => [ ...@@ -203,7 +203,7 @@ export const getCategories = (): ValueFormatCategory[] => [
], ],
}, },
{ {
name: 'hash rate', name: 'Hash Rate',
formats: [ formats: [
{ name: 'hashes/sec', id: 'Hs', fn: decimalSIPrefix('H/s') }, { name: 'hashes/sec', id: 'Hs', fn: decimalSIPrefix('H/s') },
{ name: 'kilohashes/sec', id: 'KHs', fn: decimalSIPrefix('H/s', 1) }, { name: 'kilohashes/sec', id: 'KHs', fn: decimalSIPrefix('H/s', 1) },
...@@ -215,7 +215,7 @@ export const getCategories = (): ValueFormatCategory[] => [ ...@@ -215,7 +215,7 @@ export const getCategories = (): ValueFormatCategory[] => [
], ],
}, },
{ {
name: 'mass', name: 'Mass',
formats: [ formats: [
{ name: 'milligram (mg)', id: 'massmg', fn: decimalSIPrefix('g', -1) }, { name: 'milligram (mg)', id: 'massmg', fn: decimalSIPrefix('g', -1) },
{ name: 'gram (g)', id: 'massg', fn: decimalSIPrefix('g') }, { name: 'gram (g)', id: 'massg', fn: decimalSIPrefix('g') },
...@@ -234,7 +234,7 @@ export const getCategories = (): ValueFormatCategory[] => [ ...@@ -234,7 +234,7 @@ export const getCategories = (): ValueFormatCategory[] => [
], ],
}, },
{ {
name: 'pressure', name: 'Pressure',
formats: [ formats: [
{ name: 'Millibars', id: 'pressurembar', fn: decimalSIPrefix('bar', -1) }, { name: 'Millibars', id: 'pressurembar', fn: decimalSIPrefix('bar', -1) },
{ name: 'Bars', id: 'pressurebar', fn: decimalSIPrefix('bar') }, { name: 'Bars', id: 'pressurebar', fn: decimalSIPrefix('bar') },
...@@ -246,7 +246,7 @@ export const getCategories = (): ValueFormatCategory[] => [ ...@@ -246,7 +246,7 @@ export const getCategories = (): ValueFormatCategory[] => [
], ],
}, },
{ {
name: 'radiation', name: 'Radiation',
formats: [ formats: [
{ name: 'Becquerel (Bq)', id: 'radbq', fn: decimalSIPrefix('Bq') }, { name: 'Becquerel (Bq)', id: 'radbq', fn: decimalSIPrefix('Bq') },
{ name: 'curie (Ci)', id: 'radci', fn: decimalSIPrefix('Ci') }, { name: 'curie (Ci)', id: 'radci', fn: decimalSIPrefix('Ci') },
...@@ -260,7 +260,7 @@ export const getCategories = (): ValueFormatCategory[] => [ ...@@ -260,7 +260,7 @@ export const getCategories = (): ValueFormatCategory[] => [
], ],
}, },
{ {
name: 'temperature', name: 'Temperature',
formats: [ formats: [
{ name: 'Celsius (°C)', id: 'celsius', fn: toFixedUnit('°C') }, { name: 'Celsius (°C)', id: 'celsius', fn: toFixedUnit('°C') },
{ name: 'Farenheit (°F)', id: 'farenheit', fn: toFixedUnit('°F') }, { name: 'Farenheit (°F)', id: 'farenheit', fn: toFixedUnit('°F') },
...@@ -268,7 +268,7 @@ export const getCategories = (): ValueFormatCategory[] => [ ...@@ -268,7 +268,7 @@ export const getCategories = (): ValueFormatCategory[] => [
], ],
}, },
{ {
name: 'time', name: 'Time',
formats: [ formats: [
{ name: 'Hertz (1/s)', id: 'hertz', fn: decimalSIPrefix('Hz') }, { name: 'Hertz (1/s)', id: 'hertz', fn: decimalSIPrefix('Hz') },
{ name: 'nanoseconds (ns)', id: 'ns', fn: toNanoSeconds }, { name: 'nanoseconds (ns)', id: 'ns', fn: toNanoSeconds },
...@@ -287,7 +287,7 @@ export const getCategories = (): ValueFormatCategory[] => [ ...@@ -287,7 +287,7 @@ export const getCategories = (): ValueFormatCategory[] => [
], ],
}, },
{ {
name: 'throughput', name: 'Throughput',
formats: [ formats: [
{ name: 'ops/sec (ops)', id: 'ops', fn: simpleCountUnit('ops') }, { name: 'ops/sec (ops)', id: 'ops', fn: simpleCountUnit('ops') },
{ name: 'requests/sec (rps)', id: 'reqps', fn: simpleCountUnit('reqps') }, { name: 'requests/sec (rps)', id: 'reqps', fn: simpleCountUnit('reqps') },
...@@ -300,7 +300,7 @@ export const getCategories = (): ValueFormatCategory[] => [ ...@@ -300,7 +300,7 @@ export const getCategories = (): ValueFormatCategory[] => [
], ],
}, },
{ {
name: 'velocity', name: 'Velocity',
formats: [ formats: [
{ name: 'metres/second (m/s)', id: 'velocityms', fn: toFixedUnit('m/s') }, { name: 'metres/second (m/s)', id: 'velocityms', fn: toFixedUnit('m/s') },
{ name: 'kilometers/hour (km/h)', id: 'velocitykmh', fn: toFixedUnit('km/h') }, { name: 'kilometers/hour (km/h)', id: 'velocitykmh', fn: toFixedUnit('km/h') },
...@@ -309,7 +309,7 @@ export const getCategories = (): ValueFormatCategory[] => [ ...@@ -309,7 +309,7 @@ export const getCategories = (): ValueFormatCategory[] => [
] ]
}, },
{ {
name: 'volume', name: 'Volume',
formats: [ formats: [
{ name: 'millilitre (mL)', id: 'mlitre', fn: decimalSIPrefix('L', -1) }, { name: 'millilitre (mL)', id: 'mlitre', fn: decimalSIPrefix('L', -1) },
{ name: 'litre (L)', id: 'litre', fn: decimalSIPrefix('L') }, { name: 'litre (L)', id: 'litre', fn: decimalSIPrefix('L') },
...@@ -318,5 +318,5 @@ export const getCategories = (): ValueFormatCategory[] => [ ...@@ -318,5 +318,5 @@ export const getCategories = (): ValueFormatCategory[] => [
{ name: 'cubic decimetre', id: 'dm3', fn: toFixedUnit('dm³') }, { name: 'cubic decimetre', id: 'dm3', fn: toFixedUnit('dm³') },
{ name: 'gallons', id: 'gallons', fn: toFixedUnit('gal') }, { name: 'gallons', id: 'gallons', fn: toFixedUnit('gal') },
], ],
}, }
]; ];
...@@ -312,14 +312,20 @@ class SingleStatCtrl extends MetricsPanelCtrl { ...@@ -312,14 +312,20 @@ class SingleStatCtrl extends MetricsPanelCtrl {
const formatFunc = kbn.valueFormats[this.panel.format]; const formatFunc = kbn.valueFormats[this.panel.format];
data.value = lastPoint[1]; data.value = lastPoint[1];
data.valueRounded = data.value; data.valueRounded = data.value;
data.valueFormatted = formatFunc(data.value, this.dashboard.isTimezoneUtc()); data.valueFormatted = formatFunc(data.value, 0, 0, this.dashboard.isTimezoneUtc());
} else { } else {
data.value = this.series[0].stats[this.panel.valueName]; data.value = this.series[0].stats[this.panel.valueName];
data.flotpairs = this.series[0].flotpairs; data.flotpairs = this.series[0].flotpairs;
const decimalInfo = this.getDecimalsForValue(data.value); const decimalInfo = this.getDecimalsForValue(data.value);
const formatFunc = kbn.valueFormats[this.panel.format]; const formatFunc = kbn.valueFormats[this.panel.format];
data.valueFormatted = formatFunc(data.value, decimalInfo.decimals, decimalInfo.scaledDecimals);
data.valueFormatted = formatFunc(
data.value,
decimalInfo.decimals,
decimalInfo.scaledDecimals,
this.dashboard.isTimezoneUtc()
);
data.valueRounded = kbn.roundValue(data.value, decimalInfo.decimals); data.valueRounded = kbn.roundValue(data.value, decimalInfo.decimals);
} }
......
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