UNPKG

@mui/x-charts

Version:

The community edition of the Charts components (MUI X).

61 lines (60 loc) 2.21 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getExtremumY = exports.getExtremumX = void 0; const mergeMinMax = (acc, val) => [val[0] === null ? acc[0] : Math.min(acc[0], val[0]), val[1] === null ? acc[1] : Math.max(acc[1], val[1])]; const getExtremumX = params => { const { series, axis, isDefaultAxis, getFilters } = params; return Object.keys(series).filter(seriesId => { const axisId = series[seriesId].xAxisId ?? series[seriesId].xAxisKey; return axisId === axis.id || axisId === undefined && isDefaultAxis; }).reduce((acc, seriesId) => { const filter = getFilters?.({ currentAxisId: axis.id, isDefaultAxis, seriesXAxisId: series[seriesId].xAxisId ?? series[seriesId].xAxisKey, seriesYAxisId: series[seriesId].yAxisId ?? series[seriesId].yAxisKey }); const seriesMinMax = series[seriesId].data?.reduce((accSeries, d, dataIndex) => { if (filter && !filter(d, dataIndex)) { return accSeries; } return mergeMinMax(accSeries, [d.x, d.x]); }, [Infinity, -Infinity]); return mergeMinMax(acc, seriesMinMax ?? [Infinity, -Infinity]); }, [Infinity, -Infinity]); }; exports.getExtremumX = getExtremumX; const getExtremumY = params => { const { series, axis, isDefaultAxis, getFilters } = params; return Object.keys(series).filter(seriesId => { const axisId = series[seriesId].yAxisId ?? series[seriesId].yAxisKey; return axisId === axis.id || axisId === undefined && isDefaultAxis; }).reduce((acc, seriesId) => { const filter = getFilters?.({ currentAxisId: axis.id, isDefaultAxis, seriesXAxisId: series[seriesId].xAxisId ?? series[seriesId].xAxisKey, seriesYAxisId: series[seriesId].yAxisId ?? series[seriesId].yAxisKey }); const seriesMinMax = series[seriesId].data?.reduce((accSeries, d, dataIndex) => { if (filter && !filter(d, dataIndex)) { return accSeries; } return mergeMinMax(accSeries, [d.y, d.y]); }, [Infinity, -Infinity]); return mergeMinMax(acc, seriesMinMax ?? [Infinity, -Infinity]); }, [Infinity, -Infinity]); }; exports.getExtremumY = getExtremumY;