| 1 | "use strict";
|
|---|
| 2 |
|
|---|
| 3 | Object.defineProperty(exports, "__esModule", {
|
|---|
| 4 | value: true
|
|---|
| 5 | });
|
|---|
| 6 | exports.selectLinePoints = void 0;
|
|---|
| 7 | var _reselect = require("reselect");
|
|---|
| 8 | var _Line = require("../../cartesian/Line");
|
|---|
| 9 | var _dataSelectors = require("./dataSelectors");
|
|---|
| 10 | var _chartLayoutContext = require("../../context/chartLayoutContext");
|
|---|
| 11 | var _axisSelectors = require("./axisSelectors");
|
|---|
| 12 | var _ChartUtils = require("../../util/ChartUtils");
|
|---|
| 13 | var selectXAxisWithScale = (state, xAxisId, _yAxisId, isPanorama) => (0, _axisSelectors.selectAxisWithScale)(state, 'xAxis', xAxisId, isPanorama);
|
|---|
| 14 | var selectXAxisTicks = (state, xAxisId, _yAxisId, isPanorama) => (0, _axisSelectors.selectTicksOfGraphicalItem)(state, 'xAxis', xAxisId, isPanorama);
|
|---|
| 15 | var selectYAxisWithScale = (state, _xAxisId, yAxisId, isPanorama) => (0, _axisSelectors.selectAxisWithScale)(state, 'yAxis', yAxisId, isPanorama);
|
|---|
| 16 | var selectYAxisTicks = (state, _xAxisId, yAxisId, isPanorama) => (0, _axisSelectors.selectTicksOfGraphicalItem)(state, 'yAxis', yAxisId, isPanorama);
|
|---|
| 17 | var selectBandSize = (0, _reselect.createSelector)([_chartLayoutContext.selectChartLayout, selectXAxisWithScale, selectYAxisWithScale, selectXAxisTicks, selectYAxisTicks], (layout, xAxis, yAxis, xAxisTicks, yAxisTicks) => {
|
|---|
| 18 | if ((0, _ChartUtils.isCategoricalAxis)(layout, 'xAxis')) {
|
|---|
| 19 | return (0, _ChartUtils.getBandSizeOfAxis)(xAxis, xAxisTicks, false);
|
|---|
| 20 | }
|
|---|
| 21 | return (0, _ChartUtils.getBandSizeOfAxis)(yAxis, yAxisTicks, false);
|
|---|
| 22 | });
|
|---|
| 23 | var pickLineId = (_state, _xAxisId, _yAxisId, _isPanorama, id) => id;
|
|---|
| 24 | function isLineSettings(item) {
|
|---|
| 25 | return item.type === 'line';
|
|---|
| 26 | }
|
|---|
| 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 | * So here instead of reading the dataKey from the props, we always read it from the state.
|
|---|
| 35 | */
|
|---|
| 36 | var selectSynchronisedLineSettings = (0, _reselect.createSelector)([_axisSelectors.selectUnfilteredCartesianItems, pickLineId], (graphicalItems, id) => graphicalItems.filter(isLineSettings).find(x => x.id === id));
|
|---|
| 37 | var selectLinePoints = exports.selectLinePoints = (0, _reselect.createSelector)([_chartLayoutContext.selectChartLayout, selectXAxisWithScale, selectYAxisWithScale, selectXAxisTicks, selectYAxisTicks, selectSynchronisedLineSettings, selectBandSize, _dataSelectors.selectChartDataWithIndexesIfNotInPanoramaPosition4], (layout, xAxis, yAxis, xAxisTicks, yAxisTicks, lineSettings, bandSize, _ref) => {
|
|---|
| 38 | var {
|
|---|
| 39 | chartData,
|
|---|
| 40 | dataStartIndex,
|
|---|
| 41 | dataEndIndex
|
|---|
| 42 | } = _ref;
|
|---|
| 43 | if (lineSettings == null || xAxis == null || yAxis == null || xAxisTicks == null || yAxisTicks == null || xAxisTicks.length === 0 || yAxisTicks.length === 0 || bandSize == null || layout !== 'horizontal' && layout !== 'vertical') {
|
|---|
| 44 | return undefined;
|
|---|
| 45 | }
|
|---|
| 46 | var {
|
|---|
| 47 | dataKey,
|
|---|
| 48 | data
|
|---|
| 49 | } = lineSettings;
|
|---|
| 50 | var displayedData;
|
|---|
| 51 | if (data != null && data.length > 0) {
|
|---|
| 52 | displayedData = data;
|
|---|
| 53 | } else {
|
|---|
| 54 | displayedData = chartData === null || chartData === void 0 ? void 0 : chartData.slice(dataStartIndex, dataEndIndex + 1);
|
|---|
| 55 | }
|
|---|
| 56 | if (displayedData == null) {
|
|---|
| 57 | return undefined;
|
|---|
| 58 | }
|
|---|
| 59 | return (0, _Line.computeLinePoints)({
|
|---|
| 60 | layout,
|
|---|
| 61 | xAxis,
|
|---|
| 62 | yAxis,
|
|---|
| 63 | xAxisTicks,
|
|---|
| 64 | yAxisTicks,
|
|---|
| 65 | dataKey,
|
|---|
| 66 | bandSize,
|
|---|
| 67 | displayedData
|
|---|
| 68 | });
|
|---|
| 69 | }); |
|---|