victory-core 36.9.2 → 37.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +6 -0
- package/dist/victory-core.js +4371 -5749
- package/dist/victory-core.min.js +1 -1
- package/es/victory-accessible-group/victory-accessible-group.js +9 -15
- package/es/victory-animation/util.js +28 -47
- package/es/victory-animation/victory-animation.js +51 -67
- package/es/victory-clip-container/victory-clip-container.js +153 -229
- package/es/victory-container/victory-container.js +157 -216
- package/es/victory-label/victory-label.js +246 -323
- package/es/victory-portal/portal-context.js +1 -2
- package/es/victory-portal/portal.js +30 -76
- package/es/victory-portal/victory-portal.js +47 -104
- package/es/victory-primitives/arc.js +44 -47
- package/es/victory-primitives/background.js +14 -17
- package/es/victory-primitives/border.js +20 -24
- package/es/victory-primitives/circle.js +13 -27
- package/es/victory-primitives/clip-path.js +3 -7
- package/es/victory-primitives/line-segment.js +20 -24
- package/es/victory-primitives/line.js +13 -27
- package/es/victory-primitives/path.js +13 -27
- package/es/victory-primitives/point.js +36 -40
- package/es/victory-primitives/rect.js +13 -27
- package/es/victory-primitives/text.js +15 -28
- package/es/victory-primitives/tspan.js +13 -26
- package/es/victory-primitives/whisker.js +43 -47
- package/es/victory-theme/grayscale.js +22 -22
- package/es/victory-theme/material.js +46 -46
- package/es/victory-theme/victory-theme.js +3 -3
- package/es/victory-transition/victory-transition.js +126 -206
- package/es/victory-util/add-events.js +263 -374
- package/es/victory-util/axis.js +126 -222
- package/es/victory-util/collection.js +13 -41
- package/es/victory-util/data.js +159 -214
- package/es/victory-util/default-transitions.js +33 -51
- package/es/victory-util/domain.js +122 -171
- package/es/victory-util/events.js +168 -258
- package/es/victory-util/helpers.js +153 -178
- package/es/victory-util/hooks/use-animation-state.js +61 -99
- package/es/victory-util/hooks/use-previous-props.js +2 -2
- package/es/victory-util/immutable.js +6 -8
- package/es/victory-util/label-helpers.js +128 -130
- package/es/victory-util/line-helpers.js +29 -41
- package/es/victory-util/log.js +1 -1
- package/es/victory-util/point-path-helpers.js +89 -49
- package/es/victory-util/scale.js +24 -42
- package/es/victory-util/selection.js +39 -40
- package/es/victory-util/style.js +8 -13
- package/es/victory-util/textsize.js +80 -154
- package/es/victory-util/timer-context.js +2 -2
- package/es/victory-util/timer.js +40 -76
- package/es/victory-util/transitions.js +110 -150
- package/es/victory-util/type-helpers.js +2 -3
- package/es/victory-util/user-props.js +24 -49
- package/es/victory-util/wrapper.js +184 -247
- package/lib/index.js +0 -30
- package/lib/victory-accessible-group/victory-accessible-group.js +9 -19
- package/lib/victory-animation/util.js +28 -63
- package/lib/victory-animation/victory-animation.js +54 -83
- package/lib/victory-clip-container/victory-clip-container.js +156 -243
- package/lib/victory-container/victory-container.js +160 -232
- package/lib/victory-label/victory-label.js +248 -344
- package/lib/victory-portal/portal-context.js +1 -6
- package/lib/victory-portal/portal.js +31 -81
- package/lib/victory-portal/victory-portal.js +50 -116
- package/lib/victory-primitives/arc.js +48 -57
- package/lib/victory-primitives/background.js +16 -28
- package/lib/victory-primitives/border.js +22 -34
- package/lib/victory-primitives/circle.js +16 -36
- package/lib/victory-primitives/clip-path.js +3 -11
- package/lib/victory-primitives/index.js +0 -28
- package/lib/victory-primitives/line-segment.js +22 -34
- package/lib/victory-primitives/line.js +16 -36
- package/lib/victory-primitives/path.js +16 -36
- package/lib/victory-primitives/point.js +38 -52
- package/lib/victory-primitives/rect.js +16 -36
- package/lib/victory-primitives/text.js +15 -33
- package/lib/victory-primitives/tspan.js +13 -31
- package/lib/victory-primitives/whisker.js +45 -57
- package/lib/victory-theme/grayscale.js +23 -24
- package/lib/victory-theme/material.js +47 -48
- package/lib/victory-theme/victory-theme.js +2 -7
- package/lib/victory-transition/victory-transition.js +129 -224
- package/lib/victory-util/add-events.js +263 -380
- package/lib/victory-util/axis.js +128 -241
- package/lib/victory-util/collection.js +13 -50
- package/lib/victory-util/data.js +160 -239
- package/lib/victory-util/default-transitions.js +33 -54
- package/lib/victory-util/domain.js +123 -193
- package/lib/victory-util/events.js +167 -274
- package/lib/victory-util/helpers.js +156 -207
- package/lib/victory-util/hooks/index.js +0 -2
- package/lib/victory-util/hooks/use-animation-state.js +63 -113
- package/lib/victory-util/hooks/use-previous-props.js +2 -7
- package/lib/victory-util/immutable.js +6 -18
- package/lib/victory-util/index.js +2 -51
- package/lib/victory-util/label-helpers.js +130 -141
- package/lib/victory-util/line-helpers.js +31 -49
- package/lib/victory-util/log.js +1 -2
- package/lib/victory-util/point-path-helpers.js +91 -63
- package/lib/victory-util/scale.js +26 -57
- package/lib/victory-util/selection.js +41 -49
- package/lib/victory-util/style.js +8 -16
- package/lib/victory-util/textsize.js +80 -157
- package/lib/victory-util/timer-context.js +2 -8
- package/lib/victory-util/timer.js +40 -76
- package/lib/victory-util/transitions.js +110 -152
- package/lib/victory-util/type-helpers.js +2 -9
- package/lib/victory-util/user-props.js +25 -59
- package/lib/victory-util/wrapper.js +186 -281
- package/package.json +2 -2
|
@@ -1,45 +1,41 @@
|
|
|
1
1
|
import _pick from "lodash/pick";
|
|
2
2
|
import _property from "lodash/property";
|
|
3
3
|
import _defaults from "lodash/defaults";
|
|
4
|
-
|
|
5
4
|
/* eslint-disable no-use-before-define */
|
|
6
5
|
import React, { isValidElement } from "react";
|
|
7
|
-
|
|
8
6
|
// Private Functions
|
|
7
|
+
|
|
9
8
|
function getCartesianRange(props, axis) {
|
|
10
9
|
// determine how to lay the axis and what direction positive and negative are
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
10
|
+
const vertical = axis !== "x";
|
|
11
|
+
const padding = getPadding(props);
|
|
14
12
|
if (vertical) {
|
|
15
13
|
return [props.height - padding.bottom, padding.top];
|
|
16
14
|
}
|
|
17
|
-
|
|
18
15
|
return [padding.left, props.width - padding.right];
|
|
19
16
|
}
|
|
20
|
-
|
|
21
17
|
function getPolarRange(props, axis) {
|
|
22
18
|
if (axis === "x") {
|
|
23
|
-
|
|
24
|
-
|
|
19
|
+
const startAngle = degreesToRadians(props.startAngle || 0);
|
|
20
|
+
const endAngle = degreesToRadians(props.endAngle || 360);
|
|
25
21
|
return [startAngle, endAngle];
|
|
26
22
|
}
|
|
27
|
-
|
|
28
23
|
return [props.innerRadius || 0, getRadius(props)];
|
|
29
|
-
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// Exported Functions
|
|
30
27
|
|
|
31
28
|
/**
|
|
32
29
|
* Creates an object composed of the inverted keys and values of object.
|
|
33
30
|
* If object contains duplicate values, subsequent values overwrite property assignments of previous values.
|
|
34
31
|
*/
|
|
35
|
-
|
|
36
|
-
|
|
37
32
|
export function invert(original) {
|
|
38
|
-
return Object.entries(original).reduce(
|
|
33
|
+
return Object.entries(original).reduce((acc, current) => {
|
|
39
34
|
acc[current[1]] = current[0];
|
|
40
35
|
return acc;
|
|
41
36
|
}, {});
|
|
42
37
|
}
|
|
38
|
+
|
|
43
39
|
/**
|
|
44
40
|
* creates an object with some keys excluded
|
|
45
41
|
* replacement for lodash.omit for performance. does not mimic the entire lodash.omit api
|
|
@@ -47,43 +43,39 @@ export function invert(original) {
|
|
|
47
43
|
* @param {Array<String>} ks: an array of keys to omit from the new object
|
|
48
44
|
* @returns {Object} new object with same properties as originalObject
|
|
49
45
|
*/
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
46
|
+
export function omit(originalObject, ks) {
|
|
47
|
+
if (ks === void 0) {
|
|
48
|
+
ks = [];
|
|
49
|
+
}
|
|
53
50
|
// code based on babel's _objectWithoutProperties
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
for (var key in originalObject) {
|
|
51
|
+
const newObject = {};
|
|
52
|
+
for (const key in originalObject) {
|
|
57
53
|
// @ts-expect-error String is not assignable to Key
|
|
58
54
|
if (ks.indexOf(key) >= 0) {
|
|
59
55
|
continue;
|
|
60
56
|
}
|
|
61
|
-
|
|
62
57
|
if (!Object.prototype.hasOwnProperty.call(originalObject, key)) {
|
|
63
58
|
continue;
|
|
64
59
|
}
|
|
65
|
-
|
|
66
60
|
newObject[key] = originalObject[key];
|
|
67
61
|
}
|
|
68
|
-
|
|
69
62
|
return newObject;
|
|
70
63
|
}
|
|
71
64
|
export function getPoint(datum) {
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
var point = {
|
|
65
|
+
const exists = val => val !== undefined;
|
|
66
|
+
const {
|
|
67
|
+
_x,
|
|
68
|
+
_x1,
|
|
69
|
+
_x0,
|
|
70
|
+
_voronoiX,
|
|
71
|
+
_y,
|
|
72
|
+
_y1,
|
|
73
|
+
_y0,
|
|
74
|
+
_voronoiY
|
|
75
|
+
} = datum;
|
|
76
|
+
const defaultX = exists(_x1) ? _x1 : _x;
|
|
77
|
+
const defaultY = exists(_y1) ? _y1 : _y;
|
|
78
|
+
const point = {
|
|
87
79
|
x: exists(_voronoiX) ? _voronoiX : defaultX,
|
|
88
80
|
x0: exists(_x0) ? _x0 : _x,
|
|
89
81
|
y: exists(_voronoiY) ? _voronoiY : defaultY,
|
|
@@ -92,18 +84,20 @@ export function getPoint(datum) {
|
|
|
92
84
|
return _defaults({}, point, datum);
|
|
93
85
|
}
|
|
94
86
|
export function scalePoint(props, datum) {
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
87
|
+
const {
|
|
88
|
+
scale,
|
|
89
|
+
polar,
|
|
90
|
+
horizontal
|
|
91
|
+
} = props;
|
|
92
|
+
const d = getPoint(datum);
|
|
93
|
+
const origin = props.origin || {
|
|
100
94
|
x: 0,
|
|
101
95
|
y: 0
|
|
102
96
|
};
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
97
|
+
const x = horizontal ? scale.y(d.y) : scale.x(d.x);
|
|
98
|
+
const x0 = horizontal ? scale.y(d.y0) : scale.x(d.x0);
|
|
99
|
+
const y = horizontal ? scale.x(d.x) : scale.y(d.y);
|
|
100
|
+
const y0 = horizontal ? scale.x(d.x0) : scale.y(d.y0);
|
|
107
101
|
return {
|
|
108
102
|
x: polar ? y * Math.cos(x) + origin.x : x,
|
|
109
103
|
x0: polar ? y0 * Math.cos(x0) + origin.x : x0,
|
|
@@ -111,11 +105,13 @@ export function scalePoint(props, datum) {
|
|
|
111
105
|
y0: polar ? -y0 * Math.sin(x0) + origin.x : y0
|
|
112
106
|
};
|
|
113
107
|
}
|
|
114
|
-
export function getPadding(props) {
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
108
|
+
export function getPadding(props, name) {
|
|
109
|
+
if (name === void 0) {
|
|
110
|
+
name = "padding";
|
|
111
|
+
}
|
|
112
|
+
const padding = props[name];
|
|
113
|
+
const paddingVal = typeof padding === "number" ? padding : 0;
|
|
114
|
+
const paddingObj = typeof padding === "object" ? padding : {};
|
|
119
115
|
return {
|
|
120
116
|
top: paddingObj.top || paddingVal,
|
|
121
117
|
bottom: paddingObj.bottom || paddingVal,
|
|
@@ -124,50 +120,47 @@ export function getPadding(props) {
|
|
|
124
120
|
};
|
|
125
121
|
}
|
|
126
122
|
export function isTooltip(component) {
|
|
127
|
-
|
|
123
|
+
const labelRole = component && component.type && component.type.role;
|
|
128
124
|
return labelRole === "tooltip";
|
|
129
125
|
}
|
|
130
126
|
export function getDefaultStyles(props, role) {
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
127
|
+
const {
|
|
128
|
+
theme = {},
|
|
129
|
+
labelComponent
|
|
130
|
+
} = props;
|
|
131
|
+
const defaultStyles = theme[role] && theme[role].style || {};
|
|
136
132
|
if (!isTooltip(labelComponent)) {
|
|
137
133
|
return defaultStyles;
|
|
138
134
|
}
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
var labelStyle = _defaults({}, tooltipStyle, defaultStyles.labels);
|
|
143
|
-
|
|
135
|
+
const tooltipStyle = theme.tooltip && theme.tooltip.style || {};
|
|
136
|
+
const labelStyle = _defaults({}, tooltipStyle, defaultStyles.labels);
|
|
144
137
|
return _defaults({}, {
|
|
145
138
|
labels: labelStyle
|
|
146
139
|
}, defaultStyles);
|
|
147
140
|
}
|
|
148
141
|
export function getStyles(style, defaultStyles) {
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
142
|
+
const width = "100%";
|
|
143
|
+
const height = "100%";
|
|
152
144
|
if (!style) {
|
|
153
145
|
return _defaults({
|
|
154
146
|
parent: {
|
|
155
|
-
height
|
|
156
|
-
width
|
|
147
|
+
height,
|
|
148
|
+
width
|
|
157
149
|
}
|
|
158
150
|
}, defaultStyles);
|
|
159
151
|
}
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
152
|
+
const {
|
|
153
|
+
data,
|
|
154
|
+
labels,
|
|
155
|
+
parent
|
|
156
|
+
} = style;
|
|
157
|
+
const defaultParent = defaultStyles && defaultStyles.parent || {};
|
|
158
|
+
const defaultLabels = defaultStyles && defaultStyles.labels || {};
|
|
159
|
+
const defaultData = defaultStyles && defaultStyles.data || {};
|
|
167
160
|
return {
|
|
168
161
|
parent: _defaults({}, parent, defaultParent, {
|
|
169
|
-
width
|
|
170
|
-
height
|
|
162
|
+
width,
|
|
163
|
+
height
|
|
171
164
|
}),
|
|
172
165
|
labels: _defaults({}, labels, defaultLabels),
|
|
173
166
|
data: _defaults({}, data, defaultData)
|
|
@@ -180,14 +173,10 @@ export function evaluateStyle(style, props) {
|
|
|
180
173
|
if (props.disableInlineStyles) {
|
|
181
174
|
return {};
|
|
182
175
|
}
|
|
183
|
-
|
|
184
|
-
if (!style || !Object.keys(style).some(function (value) {
|
|
185
|
-
return isFunction(style[value]);
|
|
186
|
-
})) {
|
|
176
|
+
if (!style || !Object.keys(style).some(value => isFunction(style[value]))) {
|
|
187
177
|
return style;
|
|
188
178
|
}
|
|
189
|
-
|
|
190
|
-
return Object.keys(style).reduce(function (prev, curr) {
|
|
179
|
+
return Object.keys(style).reduce((prev, curr) => {
|
|
191
180
|
prev[curr] = evaluateProp(style[curr], props);
|
|
192
181
|
return prev;
|
|
193
182
|
}, {});
|
|
@@ -199,29 +188,32 @@ export function radiansToDegrees(radians) {
|
|
|
199
188
|
return typeof radians === "number" ? radians / (Math.PI / 180) : radians;
|
|
200
189
|
}
|
|
201
190
|
export function getRadius(props) {
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
191
|
+
const {
|
|
192
|
+
left,
|
|
193
|
+
right,
|
|
194
|
+
top,
|
|
195
|
+
bottom
|
|
196
|
+
} = getPadding(props);
|
|
197
|
+
const {
|
|
198
|
+
width,
|
|
199
|
+
height
|
|
200
|
+
} = props;
|
|
210
201
|
return Math.min(width - left - right, height - top - bottom) / 2;
|
|
211
202
|
}
|
|
212
203
|
export function getPolarOrigin(props) {
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
204
|
+
const {
|
|
205
|
+
width,
|
|
206
|
+
height
|
|
207
|
+
} = props;
|
|
208
|
+
const {
|
|
209
|
+
top,
|
|
210
|
+
bottom,
|
|
211
|
+
left,
|
|
212
|
+
right
|
|
213
|
+
} = getPadding(props);
|
|
214
|
+
const radius = Math.min(width - left - right, height - top - bottom) / 2;
|
|
215
|
+
const offsetWidth = width / 2 + left - right;
|
|
216
|
+
const offsetHeight = height / 2 + top - bottom;
|
|
225
217
|
return {
|
|
226
218
|
x: offsetWidth + radius > width ? radius + left - right : offsetWidth,
|
|
227
219
|
y: offsetHeight + radius > height ? radius + top - bottom : offsetHeight
|
|
@@ -233,18 +225,18 @@ export function getRange(props, axis) {
|
|
|
233
225
|
} else if (props.range && Array.isArray(props.range)) {
|
|
234
226
|
return props.range;
|
|
235
227
|
}
|
|
236
|
-
|
|
237
228
|
return props.polar ? getPolarRange(props, axis) : getCartesianRange(props, axis);
|
|
238
229
|
}
|
|
230
|
+
|
|
239
231
|
/**
|
|
240
232
|
* Checks if `value` is `null` or `undefined`.
|
|
241
233
|
* @returns {boolean} Returns `true` if `value` is nullish, else `false`.
|
|
242
234
|
*/
|
|
243
|
-
|
|
244
235
|
export function isNil(value) {
|
|
245
236
|
// eslint-disable-next-line eqeqeq
|
|
246
237
|
return value == null;
|
|
247
238
|
}
|
|
239
|
+
|
|
248
240
|
/**
|
|
249
241
|
* Checks if `value` is classified as a `Function` object.
|
|
250
242
|
*
|
|
@@ -252,7 +244,6 @@ export function isNil(value) {
|
|
|
252
244
|
* @param {*} value The value to check.
|
|
253
245
|
* @returns {boolean} Returns `true` if `value` is a function, else `false`.
|
|
254
246
|
*/
|
|
255
|
-
|
|
256
247
|
export function isFunction(value) {
|
|
257
248
|
return typeof value === "function";
|
|
258
249
|
}
|
|
@@ -263,47 +254,45 @@ export function createAccessor(key) {
|
|
|
263
254
|
return key;
|
|
264
255
|
} else if (key === null || key === undefined) {
|
|
265
256
|
// null/undefined means "return the data item itself"
|
|
266
|
-
return
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
} // otherwise, assume it is an array index, property key or path (_.property handles all three)
|
|
270
|
-
|
|
271
|
-
|
|
257
|
+
return x => x;
|
|
258
|
+
}
|
|
259
|
+
// otherwise, assume it is an array index, property key or path (_.property handles all three)
|
|
272
260
|
return _property(key);
|
|
273
261
|
}
|
|
274
262
|
export function modifyProps(props, fallbackProps, role) {
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
horizontal
|
|
263
|
+
const theme = props.theme && props.theme[role] ? props.theme[role] : {};
|
|
264
|
+
const themeProps = omit(theme, ["style"]);
|
|
265
|
+
const horizontal = isHorizontal(props);
|
|
266
|
+
const defaultObject = horizontal === undefined ? {} : {
|
|
267
|
+
horizontal
|
|
280
268
|
};
|
|
281
269
|
return _defaults(defaultObject, props, themeProps, fallbackProps);
|
|
282
270
|
}
|
|
271
|
+
|
|
283
272
|
/**
|
|
284
273
|
* Returns the given axis or the opposite axis when horizontal
|
|
285
274
|
* @param {string} axis: the given axis, either "x" pr "y"
|
|
286
275
|
* @param {Boolean} horizontal: true when the chart is flipped to the horizontal orientation
|
|
287
276
|
* @returns {String} the dimension appropriate for the axis given its props "x" or "y"
|
|
288
277
|
*/
|
|
289
|
-
|
|
290
278
|
export function getCurrentAxis(axis, horizontal) {
|
|
291
|
-
|
|
279
|
+
const otherAxis = axis === "x" ? "y" : "x";
|
|
292
280
|
return horizontal ? otherAxis : axis;
|
|
293
281
|
}
|
|
282
|
+
|
|
294
283
|
/**
|
|
295
284
|
* Creates an object with the same keys as object and values generated by running
|
|
296
285
|
* each own enumerable string keyed property of object through the function fn
|
|
297
286
|
*/
|
|
298
|
-
|
|
299
287
|
export function mapValues(values, fn) {
|
|
300
288
|
if (values) {
|
|
301
|
-
return Object.keys(values).reduce(
|
|
289
|
+
return Object.keys(values).reduce((acc, key) => {
|
|
302
290
|
acc[key] = fn(values[key]);
|
|
303
291
|
return acc;
|
|
304
292
|
}, {});
|
|
305
293
|
}
|
|
306
294
|
}
|
|
295
|
+
|
|
307
296
|
/**
|
|
308
297
|
* Creates an array of numbers (positive and/or negative) progressing
|
|
309
298
|
* from start up to, but not including, end.
|
|
@@ -314,28 +303,25 @@ export function mapValues(values, fn) {
|
|
|
314
303
|
* @param end [The end value] If this is defined, start is the start value
|
|
315
304
|
* @returns An array of the given length
|
|
316
305
|
*/
|
|
317
|
-
|
|
318
306
|
export function range(start, end, increment) {
|
|
319
307
|
// when the end index is not given, start from 0
|
|
320
|
-
|
|
308
|
+
const startIndex = end ? start : 0;
|
|
321
309
|
|
|
322
|
-
|
|
310
|
+
// when the end index is not given, the end of the range is the start index
|
|
311
|
+
let endIndex = end ? end : start;
|
|
323
312
|
|
|
313
|
+
// ensure endIndex is not a falsy value
|
|
324
314
|
if (!endIndex) endIndex = 0;
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
315
|
+
const k = endIndex - startIndex; // the value range
|
|
316
|
+
const length = Math.abs(k); // the length of the range
|
|
317
|
+
const sign = k / length || 1; // the sign of the range (negative or positive)
|
|
318
|
+
const inc = increment || 1; // the step size of each increment
|
|
328
319
|
|
|
329
|
-
var sign = k / length || 1; // the sign of the range (negative or positive)
|
|
330
|
-
|
|
331
|
-
var inc = increment || 1; // the step size of each increment
|
|
332
320
|
// normalize the array length when dealing with floating point values
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
return Array.from(Array(arrayLength), function (_, i) {
|
|
336
|
-
return startIndex + i * sign * inc;
|
|
337
|
-
});
|
|
321
|
+
const arrayLength = Math.max(Math.ceil(length / inc), 0);
|
|
322
|
+
return Array.from(Array(arrayLength), (_, i) => startIndex + i * sign * inc);
|
|
338
323
|
}
|
|
324
|
+
|
|
339
325
|
/**
|
|
340
326
|
* @param {Array} children: an array of child components
|
|
341
327
|
* @param {Function} iteratee: a function with arguments "child", "childName", and "parent"
|
|
@@ -345,78 +331,67 @@ export function range(start, end, increment) {
|
|
|
345
331
|
* to the memo for the next iteration step
|
|
346
332
|
* @returns {Array} returns an array of results from calling the iteratee on all nested children
|
|
347
333
|
*/
|
|
348
|
-
|
|
349
334
|
/* eslint-disable max-params */
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
}
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
335
|
+
export function reduceChildren(children, iteratee, parentProps,
|
|
336
|
+
// @ts-expect-error These defaults are hard to type
|
|
337
|
+
initialMemo, combine) {
|
|
338
|
+
if (parentProps === void 0) {
|
|
339
|
+
parentProps = {};
|
|
340
|
+
}
|
|
341
|
+
if (initialMemo === void 0) {
|
|
342
|
+
initialMemo = [];
|
|
343
|
+
}
|
|
344
|
+
if (combine === void 0) {
|
|
345
|
+
combine = (memo, item) =>
|
|
346
|
+
// @ts-expect-error These defaults are hard to type
|
|
347
|
+
memo.concat(item);
|
|
348
|
+
}
|
|
349
|
+
const sharedProps = ["data", "domain", "categories", "polar", "startAngle", "endAngle", "minDomain", "maxDomain", "horizontal"];
|
|
350
|
+
const traverseChildren = (childArray, names, parent) => {
|
|
351
|
+
return childArray.reduce((memo, child, index) => {
|
|
352
|
+
let newMemo = memo;
|
|
353
|
+
const childRole = child.type && child.type.role;
|
|
354
|
+
const childName = child.props.name || `${childRole}-${names[index]}`;
|
|
367
355
|
if (child.props && child.props.children) {
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
356
|
+
const childProps = Object.assign({}, child.props, _pick(parentProps, sharedProps));
|
|
357
|
+
const nestedChildren = child.type && child.type.role === "stack" && isFunction(child.type.getChildren) ? child.type.getChildren(childProps) : React.Children.toArray(child.props.children).map(c => {
|
|
358
|
+
const nestedChildProps = Object.assign({}, c.props, _pick(childProps, sharedProps));
|
|
371
359
|
return /*#__PURE__*/React.cloneElement(c, nestedChildProps);
|
|
372
360
|
});
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
return "".concat(childName, "-").concat(i);
|
|
376
|
-
});
|
|
377
|
-
|
|
378
|
-
var nestedResults = traverseChildren(nestedChildren, _childNames, child);
|
|
361
|
+
const childNames = nestedChildren.map((c, i) => `${childName}-${i}`);
|
|
362
|
+
const nestedResults = traverseChildren(nestedChildren, childNames, child);
|
|
379
363
|
newMemo = combine(newMemo, nestedResults);
|
|
380
364
|
} else {
|
|
381
|
-
|
|
382
|
-
|
|
365
|
+
const result = iteratee(child, childName, parent);
|
|
383
366
|
if (result) {
|
|
384
367
|
newMemo = combine(newMemo, result);
|
|
385
368
|
}
|
|
386
369
|
}
|
|
387
|
-
|
|
388
370
|
return newMemo;
|
|
389
371
|
}, initialMemo);
|
|
390
372
|
};
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
var childNames = validChildren.map(function (c, i) {
|
|
394
|
-
return i;
|
|
395
|
-
});
|
|
373
|
+
const validChildren = children.filter(isValidElement);
|
|
374
|
+
const childNames = validChildren.map((c, i) => i);
|
|
396
375
|
return traverseChildren(validChildren, childNames);
|
|
397
376
|
}
|
|
377
|
+
|
|
398
378
|
/**
|
|
399
379
|
* @param {Object} props: the props object
|
|
400
380
|
* @returns {Boolean} returns true if the props object contains `horizontal: true` of if any
|
|
401
381
|
* children or nested children are horizontal
|
|
402
382
|
*/
|
|
403
|
-
|
|
404
383
|
export function isHorizontal(props) {
|
|
405
384
|
if (props.horizontal !== undefined || !props.children) {
|
|
406
385
|
return props.horizontal;
|
|
407
386
|
}
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
var childProps = child.props || {};
|
|
412
|
-
|
|
387
|
+
const traverseChildren = childArray => {
|
|
388
|
+
return childArray.reduce((memo, child) => {
|
|
389
|
+
const childProps = child.props || {};
|
|
413
390
|
if (memo || childProps.horizontal || !childProps.children) {
|
|
414
391
|
return memo || childProps.horizontal;
|
|
415
392
|
}
|
|
416
|
-
|
|
417
393
|
return traverseChildren(React.Children.toArray(childProps.children));
|
|
418
394
|
}, false);
|
|
419
395
|
};
|
|
420
|
-
|
|
421
396
|
return traverseChildren(React.Children.toArray(props.children));
|
|
422
397
|
}
|