Skip to content

Commit

Permalink
fix(Highcharts plugin): fix getXAxisThresholdValue helper (#463)
Browse files Browse the repository at this point in the history
fix(Highcharts plugin): fix getXAxisThresholdValue helper
  • Loading branch information
korvin89 committed Apr 11, 2024
1 parent c98191a commit b5b112c
Showing 1 changed file with 13 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import type {Highcharts} from '../../../../types';

const VALUES_LIMIT = 1000;

export const getXAxisThresholdValue = (
graphs: Record<string, any>[],
operation: 'min' | 'max',
Expand All @@ -10,8 +12,18 @@ export const getXAxisThresholdValue = (
return [...acc, ...data.map((point: Highcharts.Point) => point.x)];
}, [] as number[]);
const fn = operation === 'min' ? Math.min : Math.max;
let index = 0;
let limited = xAxisValues.slice(0, VALUES_LIMIT);
let xAxisValue;

const xAxisValue = fn(...xAxisValues);
do {
if (typeof xAxisValue === 'number') {
limited.push(xAxisValue);
}
xAxisValue = fn(...limited);
index += 1;
limited = xAxisValues.slice(index * VALUES_LIMIT, index * VALUES_LIMIT + VALUES_LIMIT);
} while (limited.length);

return isFinite(xAxisValue) ? xAxisValue : null;
};

0 comments on commit b5b112c

Please sign in to comment.