diff --git a/packages/grafana-data/src/utils/valueMappings.test.ts b/packages/grafana-data/src/utils/valueMappings.test.ts index e6bf474f76c..e9d04959725 100644 --- a/packages/grafana-data/src/utils/valueMappings.test.ts +++ b/packages/grafana-data/src/utils/valueMappings.test.ts @@ -123,9 +123,12 @@ describe('isNumeric', () => { it.each` value | expected ${123} | ${true} + ${0} | ${true} ${'123'} | ${true} + ${'0'} | ${true} ${' 123'} | ${true} ${' 123 '} | ${true} + ${' 0 '} | ${true} ${-123.4} | ${true} ${'-123.4'} | ${true} ${0.41} | ${true} diff --git a/packages/grafana-data/src/utils/valueMappings.ts b/packages/grafana-data/src/utils/valueMappings.ts index e7b2721784f..3839683c615 100644 --- a/packages/grafana-data/src/utils/valueMappings.ts +++ b/packages/grafana-data/src/utils/valueMappings.ts @@ -97,11 +97,8 @@ const isNullValueMap = (mapping: ValueMap): boolean => { return mapping.value.toLowerCase() === 'null'; }; -// Ref https://stackoverflow.com/a/42356340 -export function isNumeric(num: any) { - if (num === true) { - return false; - } +// Ref https://stackoverflow.com/a/58550111 - return Boolean(Number(num)); +export function isNumeric(num: any) { + return (typeof num === 'number' || (typeof num === 'string' && num.trim() !== '')) && !isNaN(num as number); }