source: node_modules/recharts/lib/state/cartesianAxisSlice.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: 6.3 KB
Line 
1"use strict";
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6exports.updateYAxisWidth = exports.replaceZAxis = exports.replaceYAxis = exports.replaceXAxis = exports.removeZAxis = exports.removeYAxis = exports.removeXAxis = exports.defaultAxisId = exports.cartesianAxisReducer = exports.addZAxis = exports.addYAxis = exports.addXAxis = void 0;
7var _toolkit = require("@reduxjs/toolkit");
8var _immer = require("immer");
9function 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; }
10function _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; }
11function _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; }
12function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
13function _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); }
14/**
15 * @inline
16 */
17
18var defaultAxisId = exports.defaultAxisId = 0;
19
20/**
21 * Properties shared in X, Y, and Z axes.
22 * User defined axis settings, coming from props.
23 */
24
25/**
26 * These are the external props, visible for users as they set them using our public API.
27 * There is all sorts of internal computed things based on these, but they will come through selectors.
28 *
29 * Properties shared between X and Y axes
30 */
31
32/**
33 * Z axis is special because it's never displayed. It controls the size of Scatter dots,
34 * but it never displays ticks anywhere.
35 */
36
37var initialState = {
38 xAxis: {},
39 yAxis: {},
40 zAxis: {}
41};
42
43/**
44 * This is the slice where each individual Axis element pushes its own configuration.
45 * Prefer to use this one instead of axisSlice.
46 */
47var cartesianAxisSlice = (0, _toolkit.createSlice)({
48 name: 'cartesianAxis',
49 initialState,
50 reducers: {
51 addXAxis: {
52 reducer(state, action) {
53 state.xAxis[action.payload.id] = (0, _immer.castDraft)(action.payload);
54 },
55 prepare: (0, _toolkit.prepareAutoBatched)()
56 },
57 replaceXAxis: {
58 reducer(state, action) {
59 var {
60 prev,
61 next
62 } = action.payload;
63 if (state.xAxis[prev.id] !== undefined) {
64 if (prev.id !== next.id) {
65 delete state.xAxis[prev.id];
66 }
67 state.xAxis[next.id] = (0, _immer.castDraft)(next);
68 }
69 },
70 prepare: (0, _toolkit.prepareAutoBatched)()
71 },
72 removeXAxis: {
73 reducer(state, action) {
74 delete state.xAxis[action.payload.id];
75 },
76 prepare: (0, _toolkit.prepareAutoBatched)()
77 },
78 addYAxis: {
79 reducer(state, action) {
80 state.yAxis[action.payload.id] = (0, _immer.castDraft)(action.payload);
81 },
82 prepare: (0, _toolkit.prepareAutoBatched)()
83 },
84 replaceYAxis: {
85 reducer(state, action) {
86 var {
87 prev,
88 next
89 } = action.payload;
90 if (state.yAxis[prev.id] !== undefined) {
91 if (prev.id !== next.id) {
92 delete state.yAxis[prev.id];
93 }
94 state.yAxis[next.id] = (0, _immer.castDraft)(next);
95 }
96 },
97 prepare: (0, _toolkit.prepareAutoBatched)()
98 },
99 removeYAxis: {
100 reducer(state, action) {
101 delete state.yAxis[action.payload.id];
102 },
103 prepare: (0, _toolkit.prepareAutoBatched)()
104 },
105 addZAxis: {
106 reducer(state, action) {
107 state.zAxis[action.payload.id] = (0, _immer.castDraft)(action.payload);
108 },
109 prepare: (0, _toolkit.prepareAutoBatched)()
110 },
111 replaceZAxis: {
112 reducer(state, action) {
113 var {
114 prev,
115 next
116 } = action.payload;
117 if (state.zAxis[prev.id] !== undefined) {
118 if (prev.id !== next.id) {
119 delete state.zAxis[prev.id];
120 }
121 state.zAxis[next.id] = (0, _immer.castDraft)(next);
122 }
123 },
124 prepare: (0, _toolkit.prepareAutoBatched)()
125 },
126 removeZAxis: {
127 reducer(state, action) {
128 delete state.zAxis[action.payload.id];
129 },
130 prepare: (0, _toolkit.prepareAutoBatched)()
131 },
132 updateYAxisWidth(state, action) {
133 var {
134 id,
135 width
136 } = action.payload;
137 var axis = state.yAxis[id];
138 if (axis) {
139 var _history$;
140 var history = axis.widthHistory || [];
141 // An oscillation is detected when the new width is the same as the width before the last one.
142 // 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.
143 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) {
144 return;
145 }
146 var newHistory = [...history, width].slice(-3);
147 state.yAxis[id] = _objectSpread(_objectSpread({}, axis), {}, {
148 width,
149 widthHistory: newHistory
150 });
151 }
152 }
153 }
154});
155var {
156 addXAxis,
157 replaceXAxis,
158 removeXAxis,
159 addYAxis,
160 replaceYAxis,
161 removeYAxis,
162 addZAxis,
163 replaceZAxis,
164 removeZAxis,
165 updateYAxisWidth
166} = cartesianAxisSlice.actions;
167exports.updateYAxisWidth = updateYAxisWidth;
168exports.removeZAxis = removeZAxis;
169exports.replaceZAxis = replaceZAxis;
170exports.addZAxis = addZAxis;
171exports.removeYAxis = removeYAxis;
172exports.replaceYAxis = replaceYAxis;
173exports.addYAxis = addYAxis;
174exports.removeXAxis = removeXAxis;
175exports.replaceXAxis = replaceXAxis;
176exports.addXAxis = addXAxis;
177var cartesianAxisReducer = exports.cartesianAxisReducer = cartesianAxisSlice.reducer;
Note: See TracBrowser for help on using the repository browser.