UNPKG

@mui/x-charts

Version:

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

54 lines (53 loc) 2.24 kB
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray"; import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray"; export var getExtremumX = function getExtremumX(params) { var _axis$data, _axis$data2; var axis = params.axis; var minX = Math.min.apply(Math, _toConsumableArray((_axis$data = axis.data) != null ? _axis$data : [])); var maxX = Math.max.apply(Math, _toConsumableArray((_axis$data2 = axis.data) != null ? _axis$data2 : [])); return [minX, maxX]; }; function getSeriesExtremums(getValues, stackedData) { if (stackedData.length === 0) { return [null, null]; } return stackedData.reduce(function (seriesAcc, stackedValue) { var _getValues = getValues(stackedValue), _getValues2 = _slicedToArray(_getValues, 2), base = _getValues2[0], value = _getValues2[1]; if (seriesAcc[0] === null) { return [Math.min(base, value), Math.max(base, value)]; } return [Math.min(base, value, seriesAcc[0]), Math.max(base, value, seriesAcc[1])]; }, getValues(stackedData[0])); } export var getExtremumY = function getExtremumY(params) { var series = params.series, axis = params.axis, isDefaultAxis = params.isDefaultAxis; return Object.keys(series).filter(function (seriesId) { return series[seriesId].yAxisKey === axis.id || isDefaultAxis && series[seriesId].yAxisKey === undefined; }).reduce(function (acc, seriesId) { var _series$seriesId = series[seriesId], area = _series$seriesId.area, stackedData = _series$seriesId.stackedData; var isArea = area !== undefined; var getValues = isArea ? function (d) { return d; } : function (d) { return [d[1], d[1]]; }; // Since this series is not used to display an area, we do not consider the base (the d[0]). var seriesExtremums = getSeriesExtremums(getValues, stackedData); if (acc[0] === null) { return seriesExtremums; } if (seriesExtremums[0] === null) { return acc; } var _seriesExtremums = _slicedToArray(seriesExtremums, 2), seriesMin = _seriesExtremums[0], seriesMax = _seriesExtremums[1]; return [Math.min(seriesMin, acc[0]), Math.max(seriesMax, acc[1])]; }, [null, null]); };