| [a762898] | 1 | "use strict";
|
|---|
| 2 |
|
|---|
| 3 | Object.defineProperty(exports, "__esModule", {
|
|---|
| 4 | value: true
|
|---|
| 5 | });
|
|---|
| 6 | exports.selectGraphicalItemStackedData = exports.selectArea = void 0;
|
|---|
| 7 | var _reselect = require("reselect");
|
|---|
| 8 | var _Area = require("../../cartesian/Area");
|
|---|
| 9 | var _axisSelectors = require("./axisSelectors");
|
|---|
| 10 | var _chartLayoutContext = require("../../context/chartLayoutContext");
|
|---|
| 11 | var _dataSelectors = require("./dataSelectors");
|
|---|
| 12 | var _ChartUtils = require("../../util/ChartUtils");
|
|---|
| 13 | var _getStackSeriesIdentifier = require("../../util/stacks/getStackSeriesIdentifier");
|
|---|
| 14 | var _rootPropsSelectors = require("./rootPropsSelectors");
|
|---|
| 15 | var _graphicalItemSelectors = require("./graphicalItemSelectors");
|
|---|
| 16 | var selectXAxisWithScale = (state, graphicalItemId, isPanorama) => (0, _axisSelectors.selectAxisWithScale)(state, 'xAxis', (0, _graphicalItemSelectors.selectXAxisIdFromGraphicalItemId)(state, graphicalItemId), isPanorama);
|
|---|
| 17 | var selectXAxisTicks = (state, graphicalItemId, isPanorama) => (0, _axisSelectors.selectTicksOfGraphicalItem)(state, 'xAxis', (0, _graphicalItemSelectors.selectXAxisIdFromGraphicalItemId)(state, graphicalItemId), isPanorama);
|
|---|
| 18 | var selectYAxisWithScale = (state, graphicalItemId, isPanorama) => (0, _axisSelectors.selectAxisWithScale)(state, 'yAxis', (0, _graphicalItemSelectors.selectYAxisIdFromGraphicalItemId)(state, graphicalItemId), isPanorama);
|
|---|
| 19 | var selectYAxisTicks = (state, graphicalItemId, isPanorama) => (0, _axisSelectors.selectTicksOfGraphicalItem)(state, 'yAxis', (0, _graphicalItemSelectors.selectYAxisIdFromGraphicalItemId)(state, graphicalItemId), isPanorama);
|
|---|
| 20 | var selectBandSize = (0, _reselect.createSelector)([_chartLayoutContext.selectChartLayout, selectXAxisWithScale, selectYAxisWithScale, selectXAxisTicks, selectYAxisTicks], (layout, xAxis, yAxis, xAxisTicks, yAxisTicks) => {
|
|---|
| 21 | if ((0, _ChartUtils.isCategoricalAxis)(layout, 'xAxis')) {
|
|---|
| 22 | return (0, _ChartUtils.getBandSizeOfAxis)(xAxis, xAxisTicks, false);
|
|---|
| 23 | }
|
|---|
| 24 | return (0, _ChartUtils.getBandSizeOfAxis)(yAxis, yAxisTicks, false);
|
|---|
| 25 | });
|
|---|
| 26 | var pickAreaId = (_state, id) => id;
|
|---|
| 27 |
|
|---|
| 28 | /*
|
|---|
| 29 | * There is a race condition problem because we read some data from props and some from the state.
|
|---|
| 30 | * The state is updated through a dispatch and is one render behind,
|
|---|
| 31 | * and so we have this weird one tick render where the displayedData in one selector have the old dataKey
|
|---|
| 32 | * but the new dataKey in another selector.
|
|---|
| 33 | *
|
|---|
| 34 | * A proper fix is to either move everything into the state, or read the dataKey always from props
|
|---|
| 35 | * - but this is a smaller change.
|
|---|
| 36 | */
|
|---|
| 37 | var selectSynchronisedAreaSettings = (0, _reselect.createSelector)([_axisSelectors.selectUnfilteredCartesianItems, pickAreaId], (graphicalItems, id) => graphicalItems.filter(item => item.type === 'area').find(item => item.id === id));
|
|---|
| 38 | var selectNumericalAxisType = state => {
|
|---|
| 39 | var layout = (0, _chartLayoutContext.selectChartLayout)(state);
|
|---|
| 40 | var isXAxisCategorical = (0, _ChartUtils.isCategoricalAxis)(layout, 'xAxis');
|
|---|
| 41 | return isXAxisCategorical ? 'yAxis' : 'xAxis';
|
|---|
| 42 | };
|
|---|
| 43 | var selectNumericalAxisIdFromGraphicalItemId = (state, graphicalItemId) => {
|
|---|
| 44 | var axisType = selectNumericalAxisType(state);
|
|---|
| 45 | if (axisType === 'yAxis') {
|
|---|
| 46 | return (0, _graphicalItemSelectors.selectYAxisIdFromGraphicalItemId)(state, graphicalItemId);
|
|---|
| 47 | }
|
|---|
| 48 | return (0, _graphicalItemSelectors.selectXAxisIdFromGraphicalItemId)(state, graphicalItemId);
|
|---|
| 49 | };
|
|---|
| 50 | var selectNumericalAxisStackGroups = (state, graphicalItemId, isPanorama) => (0, _axisSelectors.selectStackGroups)(state, selectNumericalAxisType(state), selectNumericalAxisIdFromGraphicalItemId(state, graphicalItemId), isPanorama);
|
|---|
| 51 | var selectGraphicalItemStackedData = exports.selectGraphicalItemStackedData = (0, _reselect.createSelector)([selectSynchronisedAreaSettings, selectNumericalAxisStackGroups], (areaSettings, stackGroups) => {
|
|---|
| 52 | var _stackGroups$stackId;
|
|---|
| 53 | if (areaSettings == null || stackGroups == null) {
|
|---|
| 54 | return undefined;
|
|---|
| 55 | }
|
|---|
| 56 | var {
|
|---|
| 57 | stackId
|
|---|
| 58 | } = areaSettings;
|
|---|
| 59 | var stackSeriesIdentifier = (0, _getStackSeriesIdentifier.getStackSeriesIdentifier)(areaSettings);
|
|---|
| 60 | if (stackId == null || stackSeriesIdentifier == null) {
|
|---|
| 61 | return undefined;
|
|---|
| 62 | }
|
|---|
| 63 | var groups = (_stackGroups$stackId = stackGroups[stackId]) === null || _stackGroups$stackId === void 0 ? void 0 : _stackGroups$stackId.stackedData;
|
|---|
| 64 | var found = groups === null || groups === void 0 ? void 0 : groups.find(v => v.key === stackSeriesIdentifier);
|
|---|
| 65 | if (found == null) {
|
|---|
| 66 | return undefined;
|
|---|
| 67 | }
|
|---|
| 68 | return found.map(item => [item[0], item[1]]);
|
|---|
| 69 | });
|
|---|
| 70 | var selectArea = exports.selectArea = (0, _reselect.createSelector)([_chartLayoutContext.selectChartLayout, selectXAxisWithScale, selectYAxisWithScale, selectXAxisTicks, selectYAxisTicks, selectGraphicalItemStackedData, _dataSelectors.selectChartDataWithIndexesIfNotInPanoramaPosition3, selectBandSize, selectSynchronisedAreaSettings, _rootPropsSelectors.selectChartBaseValue], (layout, xAxis, yAxis, xAxisTicks, yAxisTicks, stackedData, _ref, bandSize, areaSettings, chartBaseValue) => {
|
|---|
| 71 | var {
|
|---|
| 72 | chartData,
|
|---|
| 73 | dataStartIndex,
|
|---|
| 74 | dataEndIndex
|
|---|
| 75 | } = _ref;
|
|---|
| 76 | if (areaSettings == null || layout !== 'horizontal' && layout !== 'vertical' || xAxis == null || yAxis == null || xAxisTicks == null || yAxisTicks == null || xAxisTicks.length === 0 || yAxisTicks.length === 0 || bandSize == null) {
|
|---|
| 77 | return undefined;
|
|---|
| 78 | }
|
|---|
| 79 | var {
|
|---|
| 80 | data
|
|---|
| 81 | } = areaSettings;
|
|---|
| 82 | var displayedData;
|
|---|
| 83 | if (data && data.length > 0) {
|
|---|
| 84 | displayedData = data;
|
|---|
| 85 | } else {
|
|---|
| 86 | displayedData = chartData === null || chartData === void 0 ? void 0 : chartData.slice(dataStartIndex, dataEndIndex + 1);
|
|---|
| 87 | }
|
|---|
| 88 | if (displayedData == null) {
|
|---|
| 89 | return undefined;
|
|---|
| 90 | }
|
|---|
| 91 | return (0, _Area.computeArea)({
|
|---|
| 92 | layout,
|
|---|
| 93 | xAxis,
|
|---|
| 94 | yAxis,
|
|---|
| 95 | xAxisTicks,
|
|---|
| 96 | yAxisTicks,
|
|---|
| 97 | dataStartIndex,
|
|---|
| 98 | areaSettings,
|
|---|
| 99 | stackedData,
|
|---|
| 100 | displayedData,
|
|---|
| 101 | chartBaseValue,
|
|---|
| 102 | bandSize
|
|---|
| 103 | });
|
|---|
| 104 | }); |
|---|