UNPKG

@mui/x-charts

Version:

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

45 lines 2.29 kB
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray"; import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray"; var getBaseExtremum = function getBaseExtremum(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]; }; var getValueExtremum = function getValueExtremum(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$stac = series[seriesId].stackedData.reduce(function (seriesAcc, values) { return [Math.min.apply(Math, _toConsumableArray(values).concat(_toConsumableArray(seriesAcc[0] === null ? [] : [seriesAcc[0]]))), Math.max.apply(Math, _toConsumableArray(values).concat(_toConsumableArray(seriesAcc[1] === null ? [] : [seriesAcc[1]])))]; }, series[seriesId].stackedData[0]), _series$seriesId$stac2 = _slicedToArray(_series$seriesId$stac, 2), seriesMin = _series$seriesId$stac2[0], seriesMax = _series$seriesId$stac2[1]; return [acc[0] === null ? seriesMin : Math.min(seriesMin, acc[0]), acc[1] === null ? seriesMax : Math.max(seriesMax, acc[1])]; }, [null, null]); }; export var getExtremumX = function getExtremumX(params) { // Notice that bar should be all horizontal or all vertical. // Don't think it's a problem for now var isHorizontal = Object.keys(params.series).some(function (seriesId) { return params.series[seriesId].layout === 'horizontal'; }); if (isHorizontal) { return getValueExtremum(params); } return getBaseExtremum(params); }; export var getExtremumY = function getExtremumY(params) { var isHorizontal = Object.keys(params.series).some(function (seriesId) { return params.series[seriesId].layout === 'horizontal'; }); if (isHorizontal) { return getBaseExtremum(params); } return getValueExtremum(params); };