victory-core 37.3.2 → 37.3.3
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 +14 -0
- package/dist/victory-core.js +423 -371
- package/dist/victory-core.min.js +1 -1
- package/es/types/callbacks.d.ts +11 -11
- package/es/types/prop-types.d.ts +28 -28
- package/es/victory-animation/util.js +6 -6
- package/es/victory-animation/victory-animation.d.ts +3 -3
- package/es/victory-clip-container/victory-clip-container.d.ts +6 -1
- package/es/victory-clip-container/victory-clip-container.js +20 -12
- package/es/victory-container/victory-container.js +2 -2
- package/es/victory-label/victory-label.d.ts +3 -3
- package/es/victory-label/victory-label.js +12 -16
- package/es/victory-portal/victory-portal.js +4 -4
- package/es/victory-primitives/arc.js +2 -2
- package/es/victory-primitives/background.js +2 -2
- package/es/victory-primitives/border.js +2 -2
- package/es/victory-primitives/line-segment.js +2 -2
- package/es/victory-primitives/point.js +2 -2
- package/es/victory-primitives/tspan.d.ts +0 -1
- package/es/victory-primitives/types.d.ts +1 -1
- package/es/victory-primitives/whisker.d.ts +1 -1
- package/es/victory-primitives/whisker.js +2 -2
- package/es/victory-theme/types.d.ts +11 -11
- package/es/victory-transition/victory-transition.d.ts +1 -1
- package/es/victory-transition/victory-transition.js +7 -7
- package/es/victory-util/add-events.d.ts +8 -8
- package/es/victory-util/add-events.js +13 -13
- package/es/victory-util/axis.js +11 -11
- package/es/victory-util/data.js +16 -16
- package/es/victory-util/domain.js +13 -13
- package/es/victory-util/events.d.ts +4 -4
- package/es/victory-util/events.js +14 -14
- package/es/victory-util/helpers.d.ts +94 -19
- package/es/victory-util/helpers.js +95 -49
- package/es/victory-util/hooks/use-animation-state.d.ts +2 -2
- package/es/victory-util/hooks/use-animation-state.js +4 -4
- package/es/victory-util/label-helpers.d.ts +4 -3
- package/es/victory-util/label-helpers.js +3 -2
- package/es/victory-util/line-helpers.d.ts +1 -1
- package/es/victory-util/log.js +3 -2
- package/es/victory-util/merge-refs.d.ts +1 -1
- package/es/victory-util/scale.js +2 -2
- package/es/victory-util/selection.d.ts +3 -3
- package/es/victory-util/textsize.js +7 -5
- package/es/victory-util/timer.d.ts +1 -1
- package/es/victory-util/transitions.d.ts +1 -1
- package/es/victory-util/transitions.js +12 -12
- package/es/victory-util/type-helpers.d.ts +0 -1
- package/es/victory-util/type-helpers.js +0 -5
- package/es/victory-util/user-props.d.ts +2 -2
- package/es/victory-util/wrapper.js +12 -12
- package/lib/types/callbacks.d.ts +11 -11
- package/lib/types/prop-types.d.ts +28 -28
- package/lib/victory-animation/util.js +6 -6
- package/lib/victory-animation/victory-animation.d.ts +3 -3
- package/lib/victory-clip-container/victory-clip-container.d.ts +6 -1
- package/lib/victory-clip-container/victory-clip-container.js +20 -12
- package/lib/victory-container/victory-container.js +3 -3
- package/lib/victory-label/victory-label.d.ts +3 -3
- package/lib/victory-label/victory-label.js +12 -16
- package/lib/victory-portal/victory-portal.js +5 -5
- package/lib/victory-primitives/arc.js +2 -2
- package/lib/victory-primitives/background.js +2 -2
- package/lib/victory-primitives/border.js +2 -2
- package/lib/victory-primitives/line-segment.js +2 -2
- package/lib/victory-primitives/point.js +2 -2
- package/lib/victory-primitives/tspan.d.ts +0 -1
- package/lib/victory-primitives/types.d.ts +1 -1
- package/lib/victory-primitives/whisker.d.ts +1 -1
- package/lib/victory-primitives/whisker.js +2 -2
- package/lib/victory-theme/types.d.ts +11 -11
- package/lib/victory-transition/victory-transition.d.ts +1 -1
- package/lib/victory-transition/victory-transition.js +7 -7
- package/lib/victory-util/add-events.d.ts +8 -8
- package/lib/victory-util/add-events.js +13 -13
- package/lib/victory-util/axis.js +11 -11
- package/lib/victory-util/data.js +16 -16
- package/lib/victory-util/domain.js +13 -13
- package/lib/victory-util/events.d.ts +4 -4
- package/lib/victory-util/events.js +14 -14
- package/lib/victory-util/helpers.d.ts +94 -19
- package/lib/victory-util/helpers.js +96 -50
- package/lib/victory-util/hooks/use-animation-state.d.ts +2 -2
- package/lib/victory-util/hooks/use-animation-state.js +4 -4
- package/lib/victory-util/label-helpers.d.ts +4 -3
- package/lib/victory-util/label-helpers.js +3 -3
- package/lib/victory-util/line-helpers.d.ts +1 -1
- package/lib/victory-util/log.js +3 -2
- package/lib/victory-util/merge-refs.d.ts +1 -1
- package/lib/victory-util/scale.js +2 -2
- package/lib/victory-util/selection.d.ts +3 -3
- package/lib/victory-util/textsize.js +5 -5
- package/lib/victory-util/timer.d.ts +1 -1
- package/lib/victory-util/transitions.d.ts +1 -1
- package/lib/victory-util/transitions.js +12 -12
- package/lib/victory-util/type-helpers.d.ts +0 -1
- package/lib/victory-util/type-helpers.js +0 -6
- package/lib/victory-util/user-props.d.ts +2 -2
- package/lib/victory-util/wrapper.js +12 -12
- package/package.json +2 -30
- package/src/victory-animation/util.ts +3 -1
- package/src/victory-clip-container/victory-clip-container.tsx +26 -11
- package/src/victory-container/victory-container.tsx +1 -1
- package/src/victory-label/victory-label.tsx +5 -3
- package/src/victory-portal/victory-portal.tsx +3 -1
- package/src/victory-primitives/arc.tsx +1 -1
- package/src/victory-primitives/background.tsx +1 -1
- package/src/victory-primitives/border.tsx +1 -1
- package/src/victory-primitives/line-segment.tsx +1 -1
- package/src/victory-primitives/point.tsx +1 -1
- package/src/victory-primitives/whisker.tsx +1 -1
- package/src/victory-transition/victory-transition.tsx +4 -2
- package/src/victory-util/add-events.tsx +5 -2
- package/src/victory-util/axis.tsx +7 -3
- package/src/victory-util/data.ts +9 -10
- package/src/victory-util/domain.ts +8 -4
- package/src/victory-util/events.ts +4 -1
- package/src/victory-util/helpers.ts +155 -39
- package/src/victory-util/hooks/use-animation-state.ts +1 -1
- package/src/victory-util/label-helpers.ts +1 -1
- package/src/victory-util/log.ts +3 -2
- package/src/victory-util/scale.ts +1 -1
- package/src/victory-util/textsize.ts +2 -1
- package/src/victory-util/transitions.ts +3 -1
- package/src/victory-util/type-helpers.ts +0 -5
- package/src/victory-util/user-props.ts +1 -1
- package/src/victory-util/wrapper.tsx +5 -1
|
@@ -1,29 +1,34 @@
|
|
|
1
|
-
import _pick from "lodash/pick";
|
|
2
|
-
import _property from "lodash/property";
|
|
3
|
-
import _defaults from "lodash/defaults";
|
|
4
1
|
import React, { isValidElement } from "react";
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
2
|
+
import defaults from "lodash/defaults";
|
|
3
|
+
import property from "lodash/property";
|
|
4
|
+
import pick from "lodash/pick";
|
|
5
|
+
/**
|
|
6
|
+
* Determine the range of a cartesian axis
|
|
7
|
+
*/
|
|
8
|
+
function getCartesianRange(options) {
|
|
9
|
+
const vertical = options.axis !== "x";
|
|
11
10
|
if (vertical) {
|
|
12
|
-
return [
|
|
11
|
+
return [options.height - options.padding.bottom, options.padding.top];
|
|
13
12
|
}
|
|
14
|
-
return [padding.left,
|
|
13
|
+
return [options.padding.left, options.width - options.padding.right];
|
|
15
14
|
}
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Determine the range of a polar axis in radians
|
|
18
|
+
*/
|
|
19
|
+
function getPolarRange(options) {
|
|
20
|
+
if (options.axis === "x") {
|
|
21
|
+
const startAngle = degreesToRadians(options.startAngle || 0);
|
|
22
|
+
const endAngle = degreesToRadians(options.endAngle || 360);
|
|
20
23
|
return [startAngle, endAngle];
|
|
21
24
|
}
|
|
22
|
-
return [
|
|
25
|
+
return [options.innerRadius || 0, getRadius({
|
|
26
|
+
height: options.height,
|
|
27
|
+
width: options.width,
|
|
28
|
+
padding: options.padding
|
|
29
|
+
})];
|
|
23
30
|
}
|
|
24
31
|
|
|
25
|
-
// Exported Functions
|
|
26
|
-
|
|
27
32
|
/**
|
|
28
33
|
* Creates an object composed of the inverted keys and values of object.
|
|
29
34
|
* If object contains duplicate values, subsequent values overwrite property assignments of previous values.
|
|
@@ -60,8 +65,11 @@ export function omit(originalObject, ks) {
|
|
|
60
65
|
}
|
|
61
66
|
return newObject;
|
|
62
67
|
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Coalesce the x and y values from a data point
|
|
71
|
+
*/
|
|
63
72
|
export function getPoint(datum) {
|
|
64
|
-
const exists = val => val !== undefined;
|
|
65
73
|
const {
|
|
66
74
|
_x,
|
|
67
75
|
_x1,
|
|
@@ -72,16 +80,20 @@ export function getPoint(datum) {
|
|
|
72
80
|
_y0,
|
|
73
81
|
_voronoiY
|
|
74
82
|
} = datum;
|
|
75
|
-
const defaultX =
|
|
76
|
-
const defaultY =
|
|
83
|
+
const defaultX = _x1 ?? _x;
|
|
84
|
+
const defaultY = _y1 ?? _y;
|
|
77
85
|
const point = {
|
|
78
|
-
x:
|
|
79
|
-
x0:
|
|
80
|
-
y:
|
|
81
|
-
y0:
|
|
86
|
+
x: _voronoiX ?? defaultX,
|
|
87
|
+
x0: _x0 ?? _x,
|
|
88
|
+
y: _voronoiY ?? defaultY,
|
|
89
|
+
y0: _y0 ?? _y
|
|
82
90
|
};
|
|
83
|
-
return
|
|
91
|
+
return defaults({}, point, datum);
|
|
84
92
|
}
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Scale a point based on the origin, direction, and given scale function
|
|
96
|
+
*/
|
|
85
97
|
export function scalePoint(props, datum) {
|
|
86
98
|
const {
|
|
87
99
|
scale,
|
|
@@ -104,11 +116,11 @@ export function scalePoint(props, datum) {
|
|
|
104
116
|
y0: polar ? -y0 * Math.sin(x0) + origin.x : y0
|
|
105
117
|
};
|
|
106
118
|
}
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* Returns a padding value from a number or partial padding values
|
|
122
|
+
*/
|
|
123
|
+
export function getPadding(padding) {
|
|
112
124
|
const paddingVal = typeof padding === "number" ? padding : 0;
|
|
113
125
|
const paddingObj = typeof padding === "object" ? padding : {};
|
|
114
126
|
return {
|
|
@@ -118,6 +130,10 @@ export function getPadding(props, name) {
|
|
|
118
130
|
right: paddingObj.right || paddingVal
|
|
119
131
|
};
|
|
120
132
|
}
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* Returns true if the component is defined as a tooltip
|
|
136
|
+
*/
|
|
121
137
|
export function isTooltip(component) {
|
|
122
138
|
const labelRole = component && component.type && component.type.role;
|
|
123
139
|
return labelRole === "tooltip";
|
|
@@ -132,8 +148,8 @@ export function getDefaultStyles(props, role) {
|
|
|
132
148
|
return defaultStyles;
|
|
133
149
|
}
|
|
134
150
|
const tooltipStyle = theme.tooltip && theme.tooltip.style || {};
|
|
135
|
-
const labelStyle =
|
|
136
|
-
return
|
|
151
|
+
const labelStyle = defaults({}, tooltipStyle, defaultStyles.labels);
|
|
152
|
+
return defaults({}, {
|
|
137
153
|
labels: labelStyle
|
|
138
154
|
}, defaultStyles);
|
|
139
155
|
}
|
|
@@ -141,7 +157,7 @@ export function getStyles(style, defaultStyles) {
|
|
|
141
157
|
const width = "100%";
|
|
142
158
|
const height = "100%";
|
|
143
159
|
if (!style) {
|
|
144
|
-
return
|
|
160
|
+
return defaults({
|
|
145
161
|
parent: {
|
|
146
162
|
height,
|
|
147
163
|
width
|
|
@@ -157,14 +173,18 @@ export function getStyles(style, defaultStyles) {
|
|
|
157
173
|
const defaultLabels = defaultStyles && defaultStyles.labels || {};
|
|
158
174
|
const defaultData = defaultStyles && defaultStyles.data || {};
|
|
159
175
|
return {
|
|
160
|
-
parent:
|
|
176
|
+
parent: defaults({}, parent, defaultParent, {
|
|
161
177
|
width,
|
|
162
178
|
height
|
|
163
179
|
}),
|
|
164
|
-
labels:
|
|
165
|
-
data:
|
|
180
|
+
labels: defaults({}, labels, defaultLabels),
|
|
181
|
+
data: defaults({}, data, defaultData)
|
|
166
182
|
};
|
|
167
183
|
}
|
|
184
|
+
|
|
185
|
+
/**
|
|
186
|
+
* Returns the value of a prop or accessor function with the given props
|
|
187
|
+
*/
|
|
168
188
|
export function evaluateProp(prop, props) {
|
|
169
189
|
return isFunction(prop) ? prop(props) : prop;
|
|
170
190
|
}
|
|
@@ -186,19 +206,28 @@ export function degreesToRadians(degrees) {
|
|
|
186
206
|
export function radiansToDegrees(radians) {
|
|
187
207
|
return typeof radians === "number" ? radians / (Math.PI / 180) : radians;
|
|
188
208
|
}
|
|
189
|
-
|
|
209
|
+
|
|
210
|
+
/**
|
|
211
|
+
* Get the maximum radius that will fit in the container
|
|
212
|
+
*/
|
|
213
|
+
export function getRadius(options) {
|
|
214
|
+
const {
|
|
215
|
+
width,
|
|
216
|
+
height,
|
|
217
|
+
padding
|
|
218
|
+
} = options;
|
|
190
219
|
const {
|
|
191
220
|
left,
|
|
192
221
|
right,
|
|
193
222
|
top,
|
|
194
223
|
bottom
|
|
195
|
-
} =
|
|
196
|
-
const {
|
|
197
|
-
width,
|
|
198
|
-
height
|
|
199
|
-
} = props;
|
|
224
|
+
} = padding;
|
|
200
225
|
return Math.min(width - left - right, height - top - bottom) / 2;
|
|
201
226
|
}
|
|
227
|
+
|
|
228
|
+
/**
|
|
229
|
+
* Returns the origin for a polar chart within the padded area
|
|
230
|
+
*/
|
|
202
231
|
export function getPolarOrigin(props) {
|
|
203
232
|
const {
|
|
204
233
|
width,
|
|
@@ -209,7 +238,7 @@ export function getPolarOrigin(props) {
|
|
|
209
238
|
bottom,
|
|
210
239
|
left,
|
|
211
240
|
right
|
|
212
|
-
} = getPadding(props);
|
|
241
|
+
} = getPadding(props.padding);
|
|
213
242
|
const radius = Math.min(width - left - right, height - top - bottom) / 2;
|
|
214
243
|
const offsetWidth = width / 2 + left - right;
|
|
215
244
|
const offsetHeight = height / 2 + top - bottom;
|
|
@@ -218,13 +247,30 @@ export function getPolarOrigin(props) {
|
|
|
218
247
|
y: offsetHeight + radius > height ? radius + top - bottom : offsetHeight
|
|
219
248
|
};
|
|
220
249
|
}
|
|
250
|
+
|
|
251
|
+
/**
|
|
252
|
+
* Determine the range of an axis based on the given props
|
|
253
|
+
*/
|
|
221
254
|
export function getRange(props, axis) {
|
|
222
255
|
if (props.range && props.range[axis]) {
|
|
223
256
|
return props.range[axis];
|
|
224
257
|
} else if (props.range && Array.isArray(props.range)) {
|
|
225
258
|
return props.range;
|
|
226
259
|
}
|
|
227
|
-
return props.polar ? getPolarRange(
|
|
260
|
+
return props.polar ? getPolarRange({
|
|
261
|
+
axis,
|
|
262
|
+
innerRadius: props.innerRadius,
|
|
263
|
+
startAngle: props.startAngle,
|
|
264
|
+
endAngle: props.endAngle,
|
|
265
|
+
height: props.height,
|
|
266
|
+
width: props.width,
|
|
267
|
+
padding: getPadding(props.padding)
|
|
268
|
+
}) : getCartesianRange({
|
|
269
|
+
axis,
|
|
270
|
+
height: props.height,
|
|
271
|
+
width: props.width,
|
|
272
|
+
padding: getPadding(props.padding)
|
|
273
|
+
});
|
|
228
274
|
}
|
|
229
275
|
|
|
230
276
|
/**
|
|
@@ -256,7 +302,7 @@ export function createAccessor(key) {
|
|
|
256
302
|
return x => x;
|
|
257
303
|
}
|
|
258
304
|
// otherwise, assume it is an array index, property key or path (_.property handles all three)
|
|
259
|
-
return
|
|
305
|
+
return property(key);
|
|
260
306
|
}
|
|
261
307
|
export function modifyProps(props, fallbackProps, role) {
|
|
262
308
|
const theme = props.theme && props.theme[role] ? props.theme[role] : {};
|
|
@@ -265,7 +311,7 @@ export function modifyProps(props, fallbackProps, role) {
|
|
|
265
311
|
const defaultObject = horizontal === undefined ? {} : {
|
|
266
312
|
horizontal
|
|
267
313
|
};
|
|
268
|
-
return
|
|
314
|
+
return defaults(defaultObject, props, themeProps, fallbackProps);
|
|
269
315
|
}
|
|
270
316
|
|
|
271
317
|
/**
|
|
@@ -352,9 +398,9 @@ initialMemo, combine) {
|
|
|
352
398
|
const childRole = child.type && child.type.role;
|
|
353
399
|
const childName = child.props.name || `${childRole}-${names[index]}`;
|
|
354
400
|
if (child.props && child.props.children) {
|
|
355
|
-
const childProps = Object.assign({}, child.props,
|
|
401
|
+
const childProps = Object.assign({}, child.props, pick(parentProps, sharedProps));
|
|
356
402
|
const nestedChildren = child.type && child.type.role === "stack" && isFunction(child.type.getChildren) ? child.type.getChildren(childProps) : React.Children.toArray(child.props.children).map(c => {
|
|
357
|
-
const nestedChildProps = Object.assign({}, c.props,
|
|
403
|
+
const nestedChildProps = Object.assign({}, c.props, pick(childProps, sharedProps));
|
|
358
404
|
return /*#__PURE__*/React.cloneElement(c, nestedChildProps);
|
|
359
405
|
});
|
|
360
406
|
const childNames = nestedChildren.map((c, i) => `${childName}-${i}`);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import _defaults from "lodash/defaults";
|
|
2
1
|
import React from "react";
|
|
2
|
+
import defaults from "lodash/defaults";
|
|
3
3
|
import * as Collection from "../collection";
|
|
4
4
|
import * as Transitions from "../transitions";
|
|
5
5
|
const INITIAL_STATE = {
|
|
@@ -29,7 +29,7 @@ export const useAnimationState = function (initialState) {
|
|
|
29
29
|
const getFilteredState = () => {
|
|
30
30
|
let childrenTransitions = state && state.childrenTransitions;
|
|
31
31
|
childrenTransitions = Collection.isArrayOfArrays(childrenTransitions) ? childrenTransitions[index] : childrenTransitions;
|
|
32
|
-
return
|
|
32
|
+
return defaults({
|
|
33
33
|
childrenTransitions
|
|
34
34
|
}, state);
|
|
35
35
|
};
|
|
@@ -40,7 +40,7 @@ export const useAnimationState = function (initialState) {
|
|
|
40
40
|
const getTransitionProps = Transitions.getTransitionPropsFactory(props, filteredState, newState => setState(newState));
|
|
41
41
|
getTransitions = childComponent => getTransitionProps(childComponent, index);
|
|
42
42
|
}
|
|
43
|
-
return
|
|
43
|
+
return defaults({
|
|
44
44
|
getTransitions,
|
|
45
45
|
parentState
|
|
46
46
|
}, props.animate, child.props.animate);
|
|
@@ -54,7 +54,7 @@ export const useAnimationState = function (initialState) {
|
|
|
54
54
|
if (props.animate.parentState) {
|
|
55
55
|
const nodesWillExit = props.animate.parentState.nodesWillExit;
|
|
56
56
|
const oldProps = nodesWillExit ? props : null;
|
|
57
|
-
const newState =
|
|
57
|
+
const newState = defaults({
|
|
58
58
|
oldProps,
|
|
59
59
|
nextProps
|
|
60
60
|
}, props.animate.parentState);
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
|
|
1
|
+
import { VictoryLabelProps } from "../victory-label/victory-label";
|
|
2
|
+
export declare function getText(props: any, datum: VictoryLabelProps["datum"], index: any): any;
|
|
2
3
|
export declare function getPolarTextAnchor(props: any, degrees: any): "end" | "start" | "middle";
|
|
3
4
|
export declare function getPolarVerticalAnchor(props: any, degrees: any): "end" | "start" | "middle";
|
|
4
5
|
export declare function getPolarAngle(props: any, baseAngle?: any): number;
|
|
@@ -16,8 +17,8 @@ export declare function getProps(props: any, index: any): {
|
|
|
16
17
|
text: any;
|
|
17
18
|
textAnchor: any;
|
|
18
19
|
verticalAnchor: any;
|
|
19
|
-
x:
|
|
20
|
-
y:
|
|
20
|
+
x: number;
|
|
21
|
+
y: number;
|
|
21
22
|
dx: number | undefined;
|
|
22
23
|
dy: number | undefined;
|
|
23
24
|
width: any;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import _defaults from "lodash/defaults";
|
|
2
1
|
import * as Helpers from "./helpers";
|
|
2
|
+
import defaults from "lodash/defaults";
|
|
3
|
+
|
|
3
4
|
// Private Functions
|
|
4
5
|
|
|
5
6
|
function getVerticalAnchor(props, datum) {
|
|
@@ -227,5 +228,5 @@ export function getProps(props, index) {
|
|
|
227
228
|
return labelProps;
|
|
228
229
|
}
|
|
229
230
|
const tooltipTheme = theme && theme.tooltip || {};
|
|
230
|
-
return
|
|
231
|
+
return defaults({}, labelProps, Helpers.omit(tooltipTheme, ["style"]));
|
|
231
232
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as d3Shape from "victory-vendor/d3-shape";
|
|
2
|
-
export
|
|
2
|
+
export type CurveName = "basis" | "cardinal" | "bumpX" | "bumpY" | "bundle" | "catmullRom" | "linear" | "monotoneX" | "monotoneY" | "step" | "stepAfter" | "stepBefore" | "natural";
|
|
3
3
|
export declare const getInterpolationFunction: (props: any) => any;
|
|
4
4
|
export declare const getLineFunction: (props: any) => d3Shape.LineRadial<[number, number]> | d3Shape.Line<[number, number]>;
|
|
5
5
|
//# sourceMappingURL=line-helpers.d.ts.map
|
package/es/victory-util/log.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
/* global console */
|
|
1
|
+
/* global console process */
|
|
2
2
|
/* eslint-disable no-console */
|
|
3
3
|
|
|
4
|
-
// TODO: Use "warning" npm module like React is switching to.
|
|
5
4
|
export function warn(message) {
|
|
5
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
6
|
+
// @ts-ignore - Webpack DefinePlugin will replace process.env.NODE_ENV
|
|
6
7
|
if (process.env.NODE_ENV !== "production") {
|
|
7
8
|
if (console && console.warn) {
|
|
8
9
|
console.warn(message);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React from "react";
|
|
2
|
-
|
|
2
|
+
type Ref<T> = React.MutableRefObject<T> | React.LegacyRef<T> | undefined | null;
|
|
3
3
|
/**
|
|
4
4
|
* Used to merge multiple React refs into a single callback ref.
|
|
5
5
|
*
|
package/es/victory-util/scale.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import isPlainObject from "lodash/isPlainObject";
|
|
2
2
|
import * as Helpers from "./helpers";
|
|
3
3
|
import * as Collection from "./collection";
|
|
4
4
|
import * as d3Scale from "victory-vendor/d3-scale";
|
|
@@ -51,7 +51,7 @@ function getScaleTypeFromData(props, axis) {
|
|
|
51
51
|
}
|
|
52
52
|
const accessor = Helpers.createAccessor(props[axis]);
|
|
53
53
|
const axisData = props.data.map(datum => {
|
|
54
|
-
const processedData =
|
|
54
|
+
const processedData = isPlainObject(accessor(datum)) ? accessor(datum)[axis] : accessor(datum);
|
|
55
55
|
return processedData !== undefined ? processedData : datum[axis];
|
|
56
56
|
});
|
|
57
57
|
return Collection.containsDates(axisData) ? "time" : "linear";
|
|
@@ -9,15 +9,15 @@ export declare function getDomainCoordinates(props: Pick<VictoryCommonProps, "sc
|
|
|
9
9
|
};
|
|
10
10
|
export declare function getDataCoordinates(props: any, scale: ScaleXYPropType, x: number, y: number): SVGCoordinateType;
|
|
11
11
|
export declare function getBounds(props: ComputedCommonProps): SVGCoordinateBounds;
|
|
12
|
-
export
|
|
12
|
+
export type SVGCoordinateType = {
|
|
13
13
|
x: number;
|
|
14
14
|
y: number;
|
|
15
15
|
};
|
|
16
|
-
export
|
|
16
|
+
export type SVGCoordinateBounds = {
|
|
17
17
|
x: readonly [number, number];
|
|
18
18
|
y: readonly [number, number];
|
|
19
19
|
};
|
|
20
|
-
|
|
20
|
+
type ComputedCommonProps = {
|
|
21
21
|
scale: ScaleXYPropType;
|
|
22
22
|
x1: number;
|
|
23
23
|
x2: number;
|
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
import _defaults from "lodash/defaults"; // http://www.pearsonified.com/2012/01/characters-per-line.php
|
|
1
|
+
// http://www.pearsonified.com/2012/01/characters-per-line.php
|
|
3
2
|
/* eslint-disable no-magic-numbers */
|
|
3
|
+
import defaults from "lodash/defaults";
|
|
4
|
+
import memoize from "lodash/memoize";
|
|
5
|
+
|
|
4
6
|
// Based on measuring specific character widths
|
|
5
7
|
// as in the following example https://bl.ocks.org/tophtucker/62f93a4658387bb61e4510c37e2e97cf
|
|
6
8
|
// For new fonts: pull gist, open index.html locally, add font files (if not generic), enter font name in `font-family` input
|
|
@@ -179,7 +181,7 @@ export const convertLengthToPixels = (length, fontSize) => {
|
|
|
179
181
|
};
|
|
180
182
|
const _prepareParams = (inputStyle, index) => {
|
|
181
183
|
const lineStyle = Array.isArray(inputStyle) ? inputStyle[index] : inputStyle;
|
|
182
|
-
const style =
|
|
184
|
+
const style = defaults({}, lineStyle, defaultStyle);
|
|
183
185
|
return Object.assign({}, style, {
|
|
184
186
|
fontFamily: style.fontFamily,
|
|
185
187
|
letterSpacing: typeof style.letterSpacing === "number" ? style.letterSpacing : convertLengthToPixels(String(style.letterSpacing), style.fontSize),
|
|
@@ -227,7 +229,7 @@ const _approximateDimensionsInternal = (text, style) => {
|
|
|
227
229
|
height: heightWithRotate * coefficients.heightOverlapCoef
|
|
228
230
|
};
|
|
229
231
|
};
|
|
230
|
-
const _getMeasurementContainer =
|
|
232
|
+
const _getMeasurementContainer = memoize(() => {
|
|
231
233
|
const element = document.createElementNS("http://www.w3.org/2000/svg", "svg");
|
|
232
234
|
element.setAttribute("xlink", "http://www.w3.org/1999/xlink");
|
|
233
235
|
element.setAttribute("width", "300");
|
|
@@ -248,7 +250,7 @@ const styleToKeyComponent = style => {
|
|
|
248
250
|
}
|
|
249
251
|
return `${style.angle}:${style.fontFamily}:${style.fontSize}:${style.letterSpacing}:${style.lineHeight}`;
|
|
250
252
|
};
|
|
251
|
-
const _measureDimensionsInternal =
|
|
253
|
+
const _measureDimensionsInternal = memoize((text, style) => {
|
|
252
254
|
let containerElement = _getMeasurementContainer();
|
|
253
255
|
if (!containerElement.isConnected) {
|
|
254
256
|
_getMeasurementContainer.cache.clear?.();
|
|
@@ -21,7 +21,7 @@ export declare function getInitialTransitionState(oldChildren: any, nextChildren
|
|
|
21
21
|
childrenTransitions: any;
|
|
22
22
|
nodesShouldEnter: boolean;
|
|
23
23
|
};
|
|
24
|
-
|
|
24
|
+
type TransitionProps = {
|
|
25
25
|
data: any;
|
|
26
26
|
animate?: AnimatePropTypeInterface;
|
|
27
27
|
clipWidth?: number;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import _identity from "lodash/identity";
|
|
2
|
-
import _defaults from "lodash/defaults";
|
|
3
1
|
import React from "react";
|
|
2
|
+
import defaults from "lodash/defaults";
|
|
3
|
+
import identity from "lodash/identity";
|
|
4
4
|
function getDatumKey(datum, idx) {
|
|
5
5
|
return (datum.key || idx).toString();
|
|
6
6
|
}
|
|
@@ -108,7 +108,7 @@ export function getInitialTransitionState(oldChildren, nextChildren) {
|
|
|
108
108
|
};
|
|
109
109
|
}
|
|
110
110
|
function getInitialChildProps(animate, data) {
|
|
111
|
-
const after = animate.onEnter && animate.onEnter.after ? animate.onEnter.after :
|
|
111
|
+
const after = animate.onEnter && animate.onEnter.after ? animate.onEnter.after : identity;
|
|
112
112
|
return {
|
|
113
113
|
data: data.map((datum, idx) => Object.assign({}, datum, after(datum, idx, data)))
|
|
114
114
|
};
|
|
@@ -125,7 +125,7 @@ function getChildBeforeLoad(animate, child, data, cb) {
|
|
|
125
125
|
data
|
|
126
126
|
};
|
|
127
127
|
}
|
|
128
|
-
const before = newAnimate.onLoad && newAnimate.onLoad.before ? newAnimate.onLoad.before :
|
|
128
|
+
const before = newAnimate.onLoad && newAnimate.onLoad.before ? newAnimate.onLoad.before : identity;
|
|
129
129
|
// If nodes need to exit, transform them with the provided onLoad.before function.
|
|
130
130
|
const newData = data.map((datum, idx) => {
|
|
131
131
|
return Object.assign({}, datum, before(datum, idx, data));
|
|
@@ -147,7 +147,7 @@ function getChildOnLoad(animate, data, cb) {
|
|
|
147
147
|
data
|
|
148
148
|
};
|
|
149
149
|
}
|
|
150
|
-
const after = animate.onLoad && animate.onLoad.after ? animate.onLoad.after :
|
|
150
|
+
const after = animate.onLoad && animate.onLoad.after ? animate.onLoad.after : identity;
|
|
151
151
|
// If nodes need to exit, transform them with the provided onLoad.after function.
|
|
152
152
|
newData = data.map((datum, idx) => {
|
|
153
153
|
return Object.assign({}, datum, after(datum, idx, data));
|
|
@@ -169,7 +169,7 @@ function getChildPropsOnExit(animate, child, data, exitingNodes, cb) {
|
|
|
169
169
|
// After the exit transition occurs, trigger the animations for
|
|
170
170
|
// nodes that are neither exiting nor entering.
|
|
171
171
|
animate.onEnd = cb;
|
|
172
|
-
const before = animate.onExit && animate.onExit.before ? animate.onExit.before :
|
|
172
|
+
const before = animate.onExit && animate.onExit.before ? animate.onExit.before : identity;
|
|
173
173
|
// If nodes need to exit, transform them with the provided onExit.before function.
|
|
174
174
|
newData = data.map((datum, idx) => {
|
|
175
175
|
const key = (datum.key || idx).toString();
|
|
@@ -192,7 +192,7 @@ function getChildPropsBeforeEnter(animate, child, data, enteringNodes, cb) {
|
|
|
192
192
|
newAnimate = Object.assign({}, animate, {
|
|
193
193
|
onEnd: cb
|
|
194
194
|
});
|
|
195
|
-
const before = animate.onEnter && animate.onEnter.before ? animate.onEnter.before :
|
|
195
|
+
const before = animate.onEnter && animate.onEnter.before ? animate.onEnter.before : identity;
|
|
196
196
|
// We want the entering nodes to be included in the transition target
|
|
197
197
|
// domain. However, we may not want these nodes to be displayed initially,
|
|
198
198
|
// so perform the `onEnter.before` transformation on each node.
|
|
@@ -219,7 +219,7 @@ function getChildPropsOnEnter(animate, data, enteringNodes, cb) {
|
|
|
219
219
|
// domain should encompass the nodes that will now enter. So perform
|
|
220
220
|
// the `onEnter.after` transformation on each node.
|
|
221
221
|
newAnimate.onEnd = cb;
|
|
222
|
-
const after = newAnimate.onEnter && newAnimate.onEnter.after ? newAnimate.onEnter.after :
|
|
222
|
+
const after = newAnimate.onEnter && newAnimate.onEnter.after ? newAnimate.onEnter.after : identity;
|
|
223
223
|
newData = data.map((datum, idx) => {
|
|
224
224
|
const key = getDatumKey(datum, idx);
|
|
225
225
|
return enteringNodes[key] ? Object.assign({}, datum, after(datum, idx, data)) : datum;
|
|
@@ -316,11 +316,11 @@ export function getTransitionPropsFactory(props, state, setState) {
|
|
|
316
316
|
};
|
|
317
317
|
return function getTransitionProps(child, index) {
|
|
318
318
|
const data = getChildData(child) || [];
|
|
319
|
-
const animate =
|
|
319
|
+
const animate = defaults({}, props.animate, child.props.animate);
|
|
320
320
|
const defaultTransitions = child.props.polar ? child.type.defaultPolarTransitions || child.type.defaultTransitions : child.type.defaultTransitions;
|
|
321
|
-
animate.onExit =
|
|
322
|
-
animate.onEnter =
|
|
323
|
-
animate.onLoad =
|
|
321
|
+
animate.onExit = defaults({}, animate.onExit, defaultTransitions && defaultTransitions.onExit);
|
|
322
|
+
animate.onEnter = defaults({}, animate.onEnter, defaultTransitions && defaultTransitions.onEnter);
|
|
323
|
+
animate.onLoad = defaults({}, animate.onLoad, defaultTransitions && defaultTransitions.onLoad);
|
|
324
324
|
const childTransitions = childrenTransitions[index] || childrenTransitions[0];
|
|
325
325
|
if (!nodesDoneLoad) {
|
|
326
326
|
// should do onLoad animation
|
|
@@ -2,7 +2,6 @@ import { ForAxes, AxisType, Tuple, Datum, DatumValue } from "../types/prop-types
|
|
|
2
2
|
export declare function hasValueForAxis<T = unknown>(value: unknown | ForAxes<T>, axis: AxisType): value is ForAxes<T>;
|
|
3
3
|
export declare function isTuple<T = unknown>(value: unknown): value is Tuple<T>;
|
|
4
4
|
export declare function getValueForAxis<T = unknown>(value: T | ForAxes<T> | undefined, axis: AxisType): T | undefined;
|
|
5
|
-
export declare function isFunction<T = Function>(func?: unknown): func is T;
|
|
6
5
|
export declare function isDate(value: unknown): value is Date;
|
|
7
6
|
export declare function isKeyValueObject(datum: Datum): datum is {
|
|
8
7
|
[key: string]: DatumValue;
|
|
@@ -13,11 +13,6 @@ export function getValueForAxis(value, axis) {
|
|
|
13
13
|
}
|
|
14
14
|
return value;
|
|
15
15
|
}
|
|
16
|
-
|
|
17
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-function-type
|
|
18
|
-
export function isFunction(func) {
|
|
19
|
-
return typeof func === "function";
|
|
20
|
-
}
|
|
21
16
|
export function isDate(value) {
|
|
22
17
|
return value instanceof Date;
|
|
23
18
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
|
-
|
|
2
|
+
type SafeAttribute = string;
|
|
3
3
|
/**
|
|
4
4
|
* Asserts that value is not null or undefined, throwing an error if it is.
|
|
5
5
|
* @param value The value to assert
|
|
@@ -14,7 +14,7 @@ export declare function assert<T>(value: T, message?: string): asserts value is
|
|
|
14
14
|
* @param {Object} props: props to be filtered against USER_PROPS_SAFELIST
|
|
15
15
|
* @returns {Object}: object containing remaining acceptable props
|
|
16
16
|
*/
|
|
17
|
-
export declare const getSafeUserProps: <T>(props: T) => Record<SafeAttribute, string>;
|
|
17
|
+
export declare const getSafeUserProps: <T>(props: T extends Record<string, any> ? T : never) => Record<SafeAttribute, string>;
|
|
18
18
|
/**
|
|
19
19
|
* Wraps a component and adds safe user props
|
|
20
20
|
*
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import _uniqBy from "lodash/uniqBy";
|
|
2
|
-
import _groupBy from "lodash/groupBy";
|
|
3
|
-
import _uniq from "lodash/uniq";
|
|
4
|
-
import _defaults from "lodash/defaults";
|
|
5
1
|
import React from "react";
|
|
2
|
+
import defaults from "lodash/defaults";
|
|
3
|
+
import uniq from "lodash/uniq";
|
|
4
|
+
import groupBy from "lodash/groupBy";
|
|
5
|
+
import uniqBy from "lodash/uniqBy";
|
|
6
6
|
import * as Axis from "./axis";
|
|
7
7
|
import * as Style from "./style";
|
|
8
8
|
import * as Data from "./data";
|
|
@@ -108,10 +108,10 @@ export function getDataFromChildren(props, childComponents) {
|
|
|
108
108
|
}, datum));
|
|
109
109
|
};
|
|
110
110
|
const stacked = children.filter(c => c.type && c.type.role === "stack").length;
|
|
111
|
-
const combine = (memo, val) => memo.concat(
|
|
111
|
+
const combine = (memo, val) => memo.concat(uniqBy(val, "_group"));
|
|
112
112
|
const datasets = Helpers.reduceChildren(children, iteratee, props, [], combine);
|
|
113
113
|
const group = stacked ? "_group" : "_stack";
|
|
114
|
-
return Object.values(
|
|
114
|
+
return Object.values(groupBy(datasets, group));
|
|
115
115
|
}
|
|
116
116
|
export function getData(props, childComponents) {
|
|
117
117
|
if (props.data) {
|
|
@@ -238,7 +238,7 @@ export function getScale(props, axis, childComponents) {
|
|
|
238
238
|
});
|
|
239
239
|
return Scale.getScaleType(sharedProps, axis);
|
|
240
240
|
};
|
|
241
|
-
const childScale =
|
|
241
|
+
const childScale = uniq(Helpers.reduceChildren(children, iteratee, props));
|
|
242
242
|
|
|
243
243
|
// default to linear scale if more than one uniq scale type is given by children
|
|
244
244
|
return childScale.length > 1 ? Scale.getScaleFromName("linear") : Scale.getScaleFromName(childScale[0]);
|
|
@@ -300,8 +300,8 @@ export function getChildStyle(child, index, calculatedProps, theme) {
|
|
|
300
300
|
const dataWidth = role === "stack" ? {} : {
|
|
301
301
|
width: getWidth(calculatedProps)
|
|
302
302
|
};
|
|
303
|
-
const dataStyle =
|
|
304
|
-
const labelsStyle =
|
|
303
|
+
const dataStyle = defaults({}, childStyle.data, Object.assign({}, dataWidth, style.data, defaultColor));
|
|
304
|
+
const labelsStyle = defaults({}, childStyle.labels, style.labels);
|
|
305
305
|
return {
|
|
306
306
|
...childStyle,
|
|
307
307
|
parent: style.parent,
|
|
@@ -354,7 +354,7 @@ export function getCategoryAndAxisStringsFromChildren(props, axis, childComponen
|
|
|
354
354
|
const axisComponent = Axis.getAxisComponent(childComponents, axis);
|
|
355
355
|
const axisStrings = axisComponent ? Data.getStringsFromAxes(axisComponent.props, axis) : [];
|
|
356
356
|
const categoryStrings = categories.length ? categories : getStringsFromChildrenCategories(childComponents, axis);
|
|
357
|
-
return
|
|
357
|
+
return uniq([...categoryStrings, ...axisStrings].flat());
|
|
358
358
|
}
|
|
359
359
|
export function getStringsFromChildren(props, childComponents) {
|
|
360
360
|
const children = childComponents || React.Children.toArray(props.children);
|
|
@@ -362,8 +362,8 @@ export function getStringsFromChildren(props, childComponents) {
|
|
|
362
362
|
const yStrings = getCategoryAndAxisStringsFromChildren(props, "y", children);
|
|
363
363
|
const dataStrings = getStringsFromData(children);
|
|
364
364
|
return {
|
|
365
|
-
x:
|
|
366
|
-
y:
|
|
365
|
+
x: uniq([...xStrings, ...dataStrings.x].flat()),
|
|
366
|
+
y: uniq([...yStrings, ...dataStrings.y].flat())
|
|
367
367
|
};
|
|
368
368
|
}
|
|
369
369
|
export function getCategories(props, childComponents, allStrings) {
|