Kaynağa Gözat

Heatmap: Fixed auto decimals when bucket name is not number but contains dots, fixes #13019 (#16609)

Torkel Ödegaard 6 yıl önce
ebeveyn
işleme
057577dcc5

+ 9 - 0
public/app/core/specs/ticks.test.ts

@@ -22,4 +22,13 @@ describe('ticks', () => {
       expect(dec.scaledDecimals).toBe(3);
       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);
+    });
+  });
 });
 });

+ 4 - 0
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)
  * Get decimal precision of number stored as a string ("3.14" => 2)
  */
  */
 export function getStringPrecision(num: string): number {
 export function getStringPrecision(num: string): number {
+  if (isNaN((num as unknown) as number)) {
+    return 0;
+  }
+
   const dotIndex = num.indexOf('.');
   const dotIndex = num.indexOf('.');
   if (dotIndex === -1) {
   if (dotIndex === -1) {
     return 0;
     return 0;