source: node_modules/recharts/lib/state/legendSlice.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: 2.6 KB
Line 
1"use strict";
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6exports.setLegendSize = exports.setLegendSettings = exports.replaceLegendPayload = exports.removeLegendPayload = exports.legendReducer = exports.addLegendPayload = void 0;
7var _toolkit = require("@reduxjs/toolkit");
8var _immer = require("immer");
9/**
10 * The properties inside this state update independently of each other and quite often.
11 * When selecting, never select the whole state because you are going to get
12 * unnecessary re-renders. Select only the properties you need.
13 *
14 * This is why this state type is not exported - don't use it directly.
15 */
16
17var initialState = {
18 settings: {
19 layout: 'horizontal',
20 align: 'center',
21 verticalAlign: 'middle',
22 itemSorter: 'value'
23 },
24 size: {
25 width: 0,
26 height: 0
27 },
28 payload: []
29};
30var legendSlice = (0, _toolkit.createSlice)({
31 name: 'legend',
32 initialState,
33 reducers: {
34 setLegendSize(state, action) {
35 state.size.width = action.payload.width;
36 state.size.height = action.payload.height;
37 },
38 setLegendSettings(state, action) {
39 state.settings.align = action.payload.align;
40 state.settings.layout = action.payload.layout;
41 state.settings.verticalAlign = action.payload.verticalAlign;
42 state.settings.itemSorter = action.payload.itemSorter;
43 },
44 addLegendPayload: {
45 reducer(state, action) {
46 state.payload.push((0, _immer.castDraft)(action.payload));
47 },
48 prepare: (0, _toolkit.prepareAutoBatched)()
49 },
50 replaceLegendPayload: {
51 reducer(state, action) {
52 var {
53 prev,
54 next
55 } = action.payload;
56 var index = (0, _toolkit.current)(state).payload.indexOf((0, _immer.castDraft)(prev));
57 if (index > -1) {
58 state.payload[index] = (0, _immer.castDraft)(next);
59 }
60 },
61 prepare: (0, _toolkit.prepareAutoBatched)()
62 },
63 removeLegendPayload: {
64 reducer(state, action) {
65 var index = (0, _toolkit.current)(state).payload.indexOf((0, _immer.castDraft)(action.payload));
66 if (index > -1) {
67 state.payload.splice(index, 1);
68 }
69 },
70 prepare: (0, _toolkit.prepareAutoBatched)()
71 }
72 }
73});
74var {
75 setLegendSize,
76 setLegendSettings,
77 addLegendPayload,
78 replaceLegendPayload,
79 removeLegendPayload
80} = legendSlice.actions;
81exports.removeLegendPayload = removeLegendPayload;
82exports.replaceLegendPayload = replaceLegendPayload;
83exports.addLegendPayload = addLegendPayload;
84exports.setLegendSettings = setLegendSettings;
85exports.setLegendSize = setLegendSize;
86var legendReducer = exports.legendReducer = legendSlice.reducer;
Note: See TracBrowser for help on using the repository browser.