source: node_modules/recharts/es6/state/selectors/areaSelectors.js

Last change on this file was a762898, checked in by istevanoska <ilinastevanoska@…>, 5 months ago

Added visualizations

  • Property mode set to 100644
File size: 5.1 KB
Line 
1import { createSelector } from 'reselect';
2import { computeArea } from '../../cartesian/Area';
3import { selectAxisWithScale, selectStackGroups, selectTicksOfGraphicalItem, selectUnfilteredCartesianItems } from './axisSelectors';
4import { selectChartLayout } from '../../context/chartLayoutContext';
5import { selectChartDataWithIndexesIfNotInPanoramaPosition3 } from './dataSelectors';
6import { getBandSizeOfAxis, isCategoricalAxis } from '../../util/ChartUtils';
7import { getStackSeriesIdentifier } from '../../util/stacks/getStackSeriesIdentifier';
8import { selectChartBaseValue } from './rootPropsSelectors';
9import { selectXAxisIdFromGraphicalItemId, selectYAxisIdFromGraphicalItemId } from './graphicalItemSelectors';
10var selectXAxisWithScale = (state, graphicalItemId, isPanorama) => selectAxisWithScale(state, 'xAxis', selectXAxisIdFromGraphicalItemId(state, graphicalItemId), isPanorama);
11var selectXAxisTicks = (state, graphicalItemId, isPanorama) => selectTicksOfGraphicalItem(state, 'xAxis', selectXAxisIdFromGraphicalItemId(state, graphicalItemId), isPanorama);
12var selectYAxisWithScale = (state, graphicalItemId, isPanorama) => selectAxisWithScale(state, 'yAxis', selectYAxisIdFromGraphicalItemId(state, graphicalItemId), isPanorama);
13var selectYAxisTicks = (state, graphicalItemId, isPanorama) => selectTicksOfGraphicalItem(state, 'yAxis', selectYAxisIdFromGraphicalItemId(state, graphicalItemId), isPanorama);
14var 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});
20var 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 */
31var selectSynchronisedAreaSettings = createSelector([selectUnfilteredCartesianItems, pickAreaId], (graphicalItems, id) => graphicalItems.filter(item => item.type === 'area').find(item => item.id === id));
32var selectNumericalAxisType = state => {
33 var layout = selectChartLayout(state);
34 var isXAxisCategorical = isCategoricalAxis(layout, 'xAxis');
35 return isXAxisCategorical ? 'yAxis' : 'xAxis';
36};
37var selectNumericalAxisIdFromGraphicalItemId = (state, graphicalItemId) => {
38 var axisType = selectNumericalAxisType(state);
39 if (axisType === 'yAxis') {
40 return selectYAxisIdFromGraphicalItemId(state, graphicalItemId);
41 }
42 return selectXAxisIdFromGraphicalItemId(state, graphicalItemId);
43};
44var selectNumericalAxisStackGroups = (state, graphicalItemId, isPanorama) => selectStackGroups(state, selectNumericalAxisType(state), selectNumericalAxisIdFromGraphicalItemId(state, graphicalItemId), isPanorama);
45export 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});
64export 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});
Note: See TracBrowser for help on using the repository browser.