| 1 | "use strict";
|
|---|
| 2 |
|
|---|
| 3 | Object.defineProperty(exports, "__esModule", {
|
|---|
| 4 | value: true
|
|---|
| 5 | });
|
|---|
| 6 | exports.setDataStartEndIndexes = exports.setComputedData = exports.setChartData = exports.initialChartDataState = exports.chartDataReducer = void 0;
|
|---|
| 7 | var _toolkit = require("@reduxjs/toolkit");
|
|---|
| 8 | var _immer = require("immer");
|
|---|
| 9 | /**
|
|---|
| 10 | * This is the data that's coming through main chart `data` prop
|
|---|
| 11 | * Recharts is very flexible in what it accepts so the type is very flexible too.
|
|---|
| 12 | * This will typically be an object, and various components will provide various `dataKey`
|
|---|
| 13 | * that dictates how to pull data from that object.
|
|---|
| 14 | *
|
|---|
| 15 | * TL;DR: before dataKey
|
|---|
| 16 | *
|
|---|
| 17 | * @inline
|
|---|
| 18 | */
|
|---|
| 19 |
|
|---|
| 20 | /**
|
|---|
| 21 | * So this is the same unknown type as ChartData but this is after the dataKey has been applied.
|
|---|
| 22 | * We still don't know what the type is - that depends on what exactly it was before the dataKey application,
|
|---|
| 23 | * and the dataKey can return whatever anyway - but let's keep it separate as a form of documentation.
|
|---|
| 24 | *
|
|---|
| 25 | * TL;DR: ChartData after dataKey.
|
|---|
| 26 | */
|
|---|
| 27 |
|
|---|
| 28 | var initialChartDataState = exports.initialChartDataState = {
|
|---|
| 29 | chartData: undefined,
|
|---|
| 30 | computedData: undefined,
|
|---|
| 31 | dataStartIndex: 0,
|
|---|
| 32 | dataEndIndex: 0
|
|---|
| 33 | };
|
|---|
| 34 | var chartDataSlice = (0, _toolkit.createSlice)({
|
|---|
| 35 | name: 'chartData',
|
|---|
| 36 | initialState: initialChartDataState,
|
|---|
| 37 | reducers: {
|
|---|
| 38 | setChartData(state, action) {
|
|---|
| 39 | state.chartData = (0, _immer.castDraft)(action.payload);
|
|---|
| 40 | if (action.payload == null) {
|
|---|
| 41 | state.dataStartIndex = 0;
|
|---|
| 42 | state.dataEndIndex = 0;
|
|---|
| 43 | return;
|
|---|
| 44 | }
|
|---|
| 45 | if (action.payload.length > 0 && state.dataEndIndex !== action.payload.length - 1) {
|
|---|
| 46 | state.dataEndIndex = action.payload.length - 1;
|
|---|
| 47 | }
|
|---|
| 48 | },
|
|---|
| 49 | setComputedData(state, action) {
|
|---|
| 50 | state.computedData = action.payload;
|
|---|
| 51 | },
|
|---|
| 52 | setDataStartEndIndexes(state, action) {
|
|---|
| 53 | var {
|
|---|
| 54 | startIndex,
|
|---|
| 55 | endIndex
|
|---|
| 56 | } = action.payload;
|
|---|
| 57 | if (startIndex != null) {
|
|---|
| 58 | state.dataStartIndex = startIndex;
|
|---|
| 59 | }
|
|---|
| 60 | if (endIndex != null) {
|
|---|
| 61 | state.dataEndIndex = endIndex;
|
|---|
| 62 | }
|
|---|
| 63 | }
|
|---|
| 64 | }
|
|---|
| 65 | });
|
|---|
| 66 | var {
|
|---|
| 67 | setChartData,
|
|---|
| 68 | setDataStartEndIndexes,
|
|---|
| 69 | setComputedData
|
|---|
| 70 | } = chartDataSlice.actions;
|
|---|
| 71 | exports.setComputedData = setComputedData;
|
|---|
| 72 | exports.setDataStartEndIndexes = setDataStartEndIndexes;
|
|---|
| 73 | exports.setChartData = setChartData;
|
|---|
| 74 | var chartDataReducer = exports.chartDataReducer = chartDataSlice.reducer; |
|---|