From f487c1956b5eaaf27b80d8891fd9096dfee323e9 Mon Sep 17 00:00:00 2001 From: Rajat Dabade Date: Wed, 20 Dec 2023 17:36:13 +0530 Subject: [PATCH] [Fix]: range issue in uplot charts (#4262) * fix: range issue in uplot charts * refactor: updated logic to strickly check is parsed value is number * refactor: safe check for number value --- frontend/src/lib/uPlotLib/utils/getYAxisScale.ts | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/frontend/src/lib/uPlotLib/utils/getYAxisScale.ts b/frontend/src/lib/uPlotLib/utils/getYAxisScale.ts index 309210ff1f..503abd5790 100644 --- a/frontend/src/lib/uPlotLib/utils/getYAxisScale.ts +++ b/frontend/src/lib/uPlotLib/utils/getYAxisScale.ts @@ -1,5 +1,6 @@ import { ThresholdProps } from 'container/NewWidget/RightContainer/Threshold/types'; import { convertValue } from 'lib/getConvertedValue'; +import { isFinite } from 'lodash-es'; import { QueryDataV3 } from 'types/api/widgets/getQuery'; function findMinMaxValues(data: QueryDataV3[]): [number, number] { @@ -9,9 +10,10 @@ function findMinMaxValues(data: QueryDataV3[]): [number, number] { entry.series?.forEach((series) => { series.values.forEach((valueObj) => { const value = parseFloat(valueObj.value); - if (!value) return; - min = Math.min(min, value); - max = Math.max(max, value); + if (isFinite(value)) { + min = Math.min(min, value); + max = Math.max(max, value); + } }); }); }); @@ -82,5 +84,10 @@ export const getYAxisScale = ( if (areAllSeriesEmpty(series)) return { auto: true }; const [min, max] = getRange(thresholds, series, yAxisUnit); + + // Min and Max value can be same if the value is same for all the series + if (min === max) { + return { auto: true }; + } return { auto: false, range: [min, max] }; };