mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Formatting: Fixes valueFormats for a value of 0 (#50719)
This commit is contained in:
parent
58e7769158
commit
f9d31d0612
@ -1,4 +1,4 @@
|
||||
import { currency } from './symbolFormatters';
|
||||
import { currency, SIPrefix } from './symbolFormatters';
|
||||
|
||||
describe('currency', () => {
|
||||
const symbol = '@';
|
||||
@ -8,6 +8,7 @@ describe('currency', () => {
|
||||
|
||||
it.each`
|
||||
value | expectedSuffix | expectedText
|
||||
${0} | ${''} | ${'0'}
|
||||
${999} | ${''} | ${'999'}
|
||||
${1000} | ${'K'} | ${'1'}
|
||||
${1000000} | ${'M'} | ${'1'}
|
||||
@ -33,6 +34,7 @@ describe('currency', () => {
|
||||
|
||||
it.each`
|
||||
value | expectedSuffix | expectedText
|
||||
${0} | ${'@'} | ${'0'}
|
||||
${999} | ${'@'} | ${'999'}
|
||||
${1000} | ${'K@'} | ${'1'}
|
||||
${1000000} | ${'M@'} | ${'1'}
|
||||
@ -53,3 +55,30 @@ describe('currency', () => {
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('SIPrefix', () => {
|
||||
const symbol = 'V';
|
||||
const fmtFunc = SIPrefix(symbol);
|
||||
|
||||
it.each`
|
||||
value | expectedSuffix | expectedText
|
||||
${0} | ${' V'} | ${'0'}
|
||||
${999} | ${' V'} | ${'999'}
|
||||
${1000} | ${' kV'} | ${'1'}
|
||||
${1000000} | ${' MV'} | ${'1'}
|
||||
${1000000000} | ${' GV'} | ${'1'}
|
||||
${1000000000000} | ${' TV'} | ${'1'}
|
||||
${1000000000000000} | ${' PV'} | ${'1'}
|
||||
${-1000000000000} | ${' TV'} | ${'-1'}
|
||||
${-1000000000} | ${' GV'} | ${'-1'}
|
||||
${-1000000} | ${' MV'} | ${'-1'}
|
||||
${-1000} | ${' kV'} | ${'-1'}
|
||||
${-999} | ${' V'} | ${'-999'}
|
||||
`('when called with value:{$value}', ({ value, expectedSuffix, expectedText }) => {
|
||||
const { prefix, suffix, text } = fmtFunc(value);
|
||||
|
||||
expect(prefix).toEqual(undefined);
|
||||
expect(suffix).toEqual(expectedSuffix);
|
||||
expect(text).toEqual(expectedText);
|
||||
});
|
||||
});
|
||||
|
@ -54,6 +54,7 @@ describe('valueFormats', () => {
|
||||
${'b'} | ${0} | ${1532.82} | ${'1533 b'}
|
||||
${'prefix:b'} | ${undefined} | ${1532.82} | ${'b1533'}
|
||||
${'suffix:d'} | ${undefined} | ${1532.82} | ${'1533 d'}
|
||||
${'si:µF'} | ${2} | ${0} | ${'0.00 µF'}
|
||||
${'si:µF'} | ${2} | ${1234} | ${'1.23 mF'}
|
||||
${'si:µF'} | ${2} | ${1234000000} | ${'1.23 kF'}
|
||||
${'si:µF'} | ${2} | ${1234000000000000} | ${'1.23 GF'}
|
||||
|
@ -143,7 +143,7 @@ export function scaledUnits(factor: number, extArray: string[], offset = 0): Val
|
||||
return { text: size.toLocaleString() };
|
||||
}
|
||||
|
||||
const siIndex = Math.floor(logb(factor, Math.abs(size)));
|
||||
const siIndex = size === 0 ? 0 : Math.floor(logb(factor, Math.abs(size)));
|
||||
const suffix = extArray[clamp(offset + siIndex, 0, extArray.length - 1)];
|
||||
|
||||
return {
|
||||
|
Loading…
Reference in New Issue
Block a user