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