| 1 | import { createSelector } from 'reselect';
|
|---|
| 2 | import { computeLinePoints } from '../../cartesian/Line';
|
|---|
| 3 | import { selectChartDataWithIndexesIfNotInPanoramaPosition4 } from './dataSelectors';
|
|---|
| 4 | import { selectChartLayout } from '../../context/chartLayoutContext';
|
|---|
| 5 | import { selectAxisWithScale, selectTicksOfGraphicalItem, selectUnfilteredCartesianItems } from './axisSelectors';
|
|---|
| 6 | import { getBandSizeOfAxis, isCategoricalAxis } from '../../util/ChartUtils';
|
|---|
| 7 | var selectXAxisWithScale = (state, xAxisId, _yAxisId, isPanorama) => selectAxisWithScale(state, 'xAxis', xAxisId, isPanorama);
|
|---|
| 8 | var selectXAxisTicks = (state, xAxisId, _yAxisId, isPanorama) => selectTicksOfGraphicalItem(state, 'xAxis', xAxisId, isPanorama);
|
|---|
| 9 | var selectYAxisWithScale = (state, _xAxisId, yAxisId, isPanorama) => selectAxisWithScale(state, 'yAxis', yAxisId, isPanorama);
|
|---|
| 10 | var selectYAxisTicks = (state, _xAxisId, yAxisId, isPanorama) => selectTicksOfGraphicalItem(state, 'yAxis', yAxisId, isPanorama);
|
|---|
| 11 | var 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 | });
|
|---|
| 17 | var pickLineId = (_state, _xAxisId, _yAxisId, _isPanorama, id) => id;
|
|---|
| 18 | function 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 | */
|
|---|
| 30 | var selectSynchronisedLineSettings = createSelector([selectUnfilteredCartesianItems, pickLineId], (graphicalItems, id) => graphicalItems.filter(isLineSettings).find(x => x.id === id));
|
|---|
| 31 | export 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 | }); |
|---|