From 057577dcc563781af81a9ae260c07498fd0f9e61 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torkel=20=C3=96degaard?= Date: Tue, 16 Apr 2019 10:39:12 +0200 Subject: [PATCH] Heatmap: Fixed auto decimals when bucket name is not number but contains dots, fixes #13019 (#16609) --- public/app/core/specs/ticks.test.ts | 9 +++++++++ public/app/core/utils/ticks.ts | 4 ++++ 2 files changed, 13 insertions(+) diff --git a/public/app/core/specs/ticks.test.ts b/public/app/core/specs/ticks.test.ts index 73d0e96cbd2..51713625745 100644 --- a/public/app/core/specs/ticks.test.ts +++ b/public/app/core/specs/ticks.test.ts @@ -22,4 +22,13 @@ describe('ticks', () => { expect(dec.scaledDecimals).toBe(3); }); }); + + describe('getStringPrecision()', () => { + it('"3.12" should return 2', () => { + expect(ticks.getStringPrecision('3.12')).toBe(2); + }); + it('"asd" should return 0', () => { + expect(ticks.getStringPrecision('asd.asd')).toBe(0); + }); + }); }); diff --git a/public/app/core/utils/ticks.ts b/public/app/core/utils/ticks.ts index 7efe6123a5e..81380269a99 100644 --- a/public/app/core/utils/ticks.ts +++ b/public/app/core/utils/ticks.ts @@ -201,6 +201,10 @@ export function getPrecision(num: number): number { * Get decimal precision of number stored as a string ("3.14" => 2) */ export function getStringPrecision(num: string): number { + if (isNaN((num as unknown) as number)) { + return 0; + } + const dotIndex = num.indexOf('.'); if (dotIndex === -1) { return 0;