source: node_modules/recharts/es6/state/selectors/lineSelectors.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: 3.1 KB
Line 
1import { createSelector } from 'reselect';
2import { computeLinePoints } from '../../cartesian/Line';
3import { selectChartDataWithIndexesIfNotInPanoramaPosition4 } from './dataSelectors';
4import { selectChartLayout } from '../../context/chartLayoutContext';
5import { selectAxisWithScale, selectTicksOfGraphicalItem, selectUnfilteredCartesianItems } from './axisSelectors';
6import { getBandSizeOfAxis, isCategoricalAxis } from '../../util/ChartUtils';
7var selectXAxisWithScale = (state, xAxisId, _yAxisId, isPanorama) => selectAxisWithScale(state, 'xAxis', xAxisId, isPanorama);
8var selectXAxisTicks = (state, xAxisId, _yAxisId, isPanorama) => selectTicksOfGraphicalItem(state, 'xAxis', xAxisId, isPanorama);
9var selectYAxisWithScale = (state, _xAxisId, yAxisId, isPanorama) => selectAxisWithScale(state, 'yAxis', yAxisId, isPanorama);
10var selectYAxisTicks = (state, _xAxisId, yAxisId, isPanorama) => selectTicksOfGraphicalItem(state, 'yAxis', yAxisId, isPanorama);
11var selectBandSize = createSelector([selectChartLayout, selectXAxisWithScale, selectYAxisWithScale, selectXAxisTicks, selectYAxisTicks], (layout, xAxis, yAxis, xAxisTicks, yAxisTicks) => {
12 if (isCategoricalAxis(layout, 'xAxis')) {
13 return getBandSizeOfAxis(xAxis, xAxisTicks, false);
14 }
15 return getBandSizeOfAxis(yAxis, yAxisTicks, false);
16});
17var pickLineId = (_state, _xAxisId, _yAxisId, _isPanorama, id) => id;
18function isLineSettings(item) {
19 return item.type === 'line';
20}
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 * So here instead of reading the dataKey from the props, we always read it from the state.
29 */
30var selectSynchronisedLineSettings = createSelector([selectUnfilteredCartesianItems, pickLineId], (graphicalItems, id) => graphicalItems.filter(isLineSettings).find(x => x.id === id));
31export var selectLinePoints = createSelector([selectChartLayout, selectXAxisWithScale, selectYAxisWithScale, selectXAxisTicks, selectYAxisTicks, selectSynchronisedLineSettings, selectBandSize, selectChartDataWithIndexesIfNotInPanoramaPosition4], (layout, xAxis, yAxis, xAxisTicks, yAxisTicks, lineSettings, bandSize, _ref) => {
32 var {
33 chartData,
34 dataStartIndex,
35 dataEndIndex
36 } = _ref;
37 if (lineSettings == null || xAxis == null || yAxis == null || xAxisTicks == null || yAxisTicks == null || xAxisTicks.length === 0 || yAxisTicks.length === 0 || bandSize == null || layout !== 'horizontal' && layout !== 'vertical') {
38 return undefined;
39 }
40 var {
41 dataKey,
42 data
43 } = lineSettings;
44 var displayedData;
45 if (data != null && data.length > 0) {
46 displayedData = data;
47 } else {
48 displayedData = chartData === null || chartData === void 0 ? void 0 : chartData.slice(dataStartIndex, dataEndIndex + 1);
49 }
50 if (displayedData == null) {
51 return undefined;
52 }
53 return computeLinePoints({
54 layout,
55 xAxis,
56 yAxis,
57 xAxisTicks,
58 yAxisTicks,
59 dataKey,
60 bandSize,
61 displayedData
62 });
63});
Note: See TracBrowser for help on using the repository browser.