source: node_modules/recharts/es6/state/cartesianAxisSlice.js@ a762898

Last change on this file since a762898 was a762898, checked in by istevanoska <ilinastevanoska@…>, 5 months ago

Added visualizations

  • Property mode set to 100644
File size: 5.4 KB
RevLine 
[a762898]1function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
2function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
3function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
4function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
5function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
6import { createSlice, prepareAutoBatched } from '@reduxjs/toolkit';
7import { castDraft } from 'immer';
8
9/**
10 * @inline
11 */
12
13export var defaultAxisId = 0;
14
15/**
16 * Properties shared in X, Y, and Z axes.
17 * User defined axis settings, coming from props.
18 */
19
20/**
21 * These are the external props, visible for users as they set them using our public API.
22 * There is all sorts of internal computed things based on these, but they will come through selectors.
23 *
24 * Properties shared between X and Y axes
25 */
26
27/**
28 * Z axis is special because it's never displayed. It controls the size of Scatter dots,
29 * but it never displays ticks anywhere.
30 */
31
32var initialState = {
33 xAxis: {},
34 yAxis: {},
35 zAxis: {}
36};
37
38/**
39 * This is the slice where each individual Axis element pushes its own configuration.
40 * Prefer to use this one instead of axisSlice.
41 */
42var cartesianAxisSlice = createSlice({
43 name: 'cartesianAxis',
44 initialState,
45 reducers: {
46 addXAxis: {
47 reducer(state, action) {
48 state.xAxis[action.payload.id] = castDraft(action.payload);
49 },
50 prepare: prepareAutoBatched()
51 },
52 replaceXAxis: {
53 reducer(state, action) {
54 var {
55 prev,
56 next
57 } = action.payload;
58 if (state.xAxis[prev.id] !== undefined) {
59 if (prev.id !== next.id) {
60 delete state.xAxis[prev.id];
61 }
62 state.xAxis[next.id] = castDraft(next);
63 }
64 },
65 prepare: prepareAutoBatched()
66 },
67 removeXAxis: {
68 reducer(state, action) {
69 delete state.xAxis[action.payload.id];
70 },
71 prepare: prepareAutoBatched()
72 },
73 addYAxis: {
74 reducer(state, action) {
75 state.yAxis[action.payload.id] = castDraft(action.payload);
76 },
77 prepare: prepareAutoBatched()
78 },
79 replaceYAxis: {
80 reducer(state, action) {
81 var {
82 prev,
83 next
84 } = action.payload;
85 if (state.yAxis[prev.id] !== undefined) {
86 if (prev.id !== next.id) {
87 delete state.yAxis[prev.id];
88 }
89 state.yAxis[next.id] = castDraft(next);
90 }
91 },
92 prepare: prepareAutoBatched()
93 },
94 removeYAxis: {
95 reducer(state, action) {
96 delete state.yAxis[action.payload.id];
97 },
98 prepare: prepareAutoBatched()
99 },
100 addZAxis: {
101 reducer(state, action) {
102 state.zAxis[action.payload.id] = castDraft(action.payload);
103 },
104 prepare: prepareAutoBatched()
105 },
106 replaceZAxis: {
107 reducer(state, action) {
108 var {
109 prev,
110 next
111 } = action.payload;
112 if (state.zAxis[prev.id] !== undefined) {
113 if (prev.id !== next.id) {
114 delete state.zAxis[prev.id];
115 }
116 state.zAxis[next.id] = castDraft(next);
117 }
118 },
119 prepare: prepareAutoBatched()
120 },
121 removeZAxis: {
122 reducer(state, action) {
123 delete state.zAxis[action.payload.id];
124 },
125 prepare: prepareAutoBatched()
126 },
127 updateYAxisWidth(state, action) {
128 var {
129 id,
130 width
131 } = action.payload;
132 var axis = state.yAxis[id];
133 if (axis) {
134 var _history$;
135 var history = axis.widthHistory || [];
136 // An oscillation is detected when the new width is the same as the width before the last one.
137 // This is a simple A -> B -> A pattern. If the next width is B, and the difference is less than 1 pixel, we ignore it.
138 if (history.length === 3 && history[0] === history[2] && width === history[1] && width !== axis.width && Math.abs(width - ((_history$ = history[0]) !== null && _history$ !== void 0 ? _history$ : 0)) <= 1) {
139 return;
140 }
141 var newHistory = [...history, width].slice(-3);
142 state.yAxis[id] = _objectSpread(_objectSpread({}, axis), {}, {
143 width,
144 widthHistory: newHistory
145 });
146 }
147 }
148 }
149});
150export var {
151 addXAxis,
152 replaceXAxis,
153 removeXAxis,
154 addYAxis,
155 replaceYAxis,
156 removeYAxis,
157 addZAxis,
158 replaceZAxis,
159 removeZAxis,
160 updateYAxisWidth
161} = cartesianAxisSlice.actions;
162export var cartesianAxisReducer = cartesianAxisSlice.reducer;
Note: See TracBrowser for help on using the repository browser.