[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
This commit is contained in:
Rajat Dabade 2023-12-20 17:36:13 +05:30 committed by GitHub
parent 6b2f03d43f
commit f487c1956b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,5 +1,6 @@
import { ThresholdProps } from 'container/NewWidget/RightContainer/Threshold/types'; import { ThresholdProps } from 'container/NewWidget/RightContainer/Threshold/types';
import { convertValue } from 'lib/getConvertedValue'; import { convertValue } from 'lib/getConvertedValue';
import { isFinite } from 'lodash-es';
import { QueryDataV3 } from 'types/api/widgets/getQuery'; import { QueryDataV3 } from 'types/api/widgets/getQuery';
function findMinMaxValues(data: QueryDataV3[]): [number, number] { function findMinMaxValues(data: QueryDataV3[]): [number, number] {
@ -9,9 +10,10 @@ function findMinMaxValues(data: QueryDataV3[]): [number, number] {
entry.series?.forEach((series) => { entry.series?.forEach((series) => {
series.values.forEach((valueObj) => { series.values.forEach((valueObj) => {
const value = parseFloat(valueObj.value); const value = parseFloat(valueObj.value);
if (!value) return; if (isFinite(value)) {
min = Math.min(min, value); min = Math.min(min, value);
max = Math.max(max, value); max = Math.max(max, value);
}
}); });
}); });
}); });
@ -82,5 +84,10 @@ export const getYAxisScale = (
if (areAllSeriesEmpty(series)) return { auto: true }; if (areAllSeriesEmpty(series)) return { auto: true };
const [min, max] = getRange(thresholds, series, yAxisUnit); 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] }; return { auto: false, range: [min, max] };
}; };