victory-core 37.3.2 → 37.3.4
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 +16 -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,31 +1,77 @@
|
|
|
1
1
|
import React, { isValidElement } from "react";
|
|
2
|
-
import
|
|
3
|
-
import
|
|
2
|
+
import defaults from "lodash/defaults";
|
|
3
|
+
import property from "lodash/property";
|
|
4
|
+
import pick from "lodash/pick";
|
|
5
|
+
|
|
4
6
|
import { ValueOrAccessor } from "../types/prop-types";
|
|
5
7
|
|
|
6
|
-
|
|
8
|
+
export type ElementPadding = {
|
|
9
|
+
top: number;
|
|
10
|
+
bottom: number;
|
|
11
|
+
left: number;
|
|
12
|
+
right: number;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export type MaybePointData = {
|
|
16
|
+
x?: number;
|
|
17
|
+
x0?: number;
|
|
18
|
+
x1?: number;
|
|
19
|
+
y?: number;
|
|
20
|
+
y0?: number;
|
|
21
|
+
y1?: number;
|
|
22
|
+
_x?: number;
|
|
23
|
+
_x0?: number;
|
|
24
|
+
_x1?: number;
|
|
25
|
+
_y?: number;
|
|
26
|
+
_y0?: number;
|
|
27
|
+
_y1?: number;
|
|
28
|
+
_voronoiX?: number;
|
|
29
|
+
_voronoiY?: number;
|
|
30
|
+
};
|
|
7
31
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
32
|
+
/**
|
|
33
|
+
* Determine the range of a cartesian axis
|
|
34
|
+
*/
|
|
35
|
+
function getCartesianRange(options: {
|
|
36
|
+
axis: "x" | "y";
|
|
37
|
+
height: number;
|
|
38
|
+
width: number;
|
|
39
|
+
padding: ElementPadding;
|
|
40
|
+
}): [number, number] {
|
|
41
|
+
const vertical = options.axis !== "x";
|
|
12
42
|
if (vertical) {
|
|
13
|
-
return [
|
|
43
|
+
return [options.height - options.padding.bottom, options.padding.top];
|
|
14
44
|
}
|
|
15
|
-
return [padding.left,
|
|
45
|
+
return [options.padding.left, options.width - options.padding.right];
|
|
16
46
|
}
|
|
17
47
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
48
|
+
/**
|
|
49
|
+
* Determine the range of a polar axis in radians
|
|
50
|
+
*/
|
|
51
|
+
function getPolarRange(options: {
|
|
52
|
+
axis: "x" | "y";
|
|
53
|
+
innerRadius?: number;
|
|
54
|
+
startAngle?: number;
|
|
55
|
+
endAngle?: number;
|
|
56
|
+
padding: ElementPadding;
|
|
57
|
+
height: number;
|
|
58
|
+
width: number;
|
|
59
|
+
}): [number, number] {
|
|
60
|
+
if (options.axis === "x") {
|
|
61
|
+
const startAngle = degreesToRadians(options.startAngle || 0);
|
|
62
|
+
const endAngle = degreesToRadians(options.endAngle || 360);
|
|
22
63
|
return [startAngle, endAngle];
|
|
23
64
|
}
|
|
24
|
-
return [
|
|
65
|
+
return [
|
|
66
|
+
options.innerRadius || 0,
|
|
67
|
+
getRadius({
|
|
68
|
+
height: options.height,
|
|
69
|
+
width: options.width,
|
|
70
|
+
padding: options.padding,
|
|
71
|
+
}),
|
|
72
|
+
];
|
|
25
73
|
}
|
|
26
74
|
|
|
27
|
-
// Exported Functions
|
|
28
|
-
|
|
29
75
|
/**
|
|
30
76
|
* Creates an object composed of the inverted keys and values of object.
|
|
31
77
|
* If object contains duplicate values, subsequent values overwrite property assignments of previous values.
|
|
@@ -63,21 +109,36 @@ export function omit<T, Keys extends keyof T>(
|
|
|
63
109
|
return newObject;
|
|
64
110
|
}
|
|
65
111
|
|
|
66
|
-
|
|
67
|
-
|
|
112
|
+
/**
|
|
113
|
+
* Coalesce the x and y values from a data point
|
|
114
|
+
*/
|
|
115
|
+
export function getPoint(datum: MaybePointData): MaybePointData {
|
|
68
116
|
const { _x, _x1, _x0, _voronoiX, _y, _y1, _y0, _voronoiY } = datum;
|
|
69
|
-
const defaultX =
|
|
70
|
-
const defaultY =
|
|
117
|
+
const defaultX = _x1 ?? _x;
|
|
118
|
+
const defaultY = _y1 ?? _y;
|
|
119
|
+
|
|
71
120
|
const point = {
|
|
72
|
-
x:
|
|
73
|
-
x0:
|
|
74
|
-
y:
|
|
75
|
-
y0:
|
|
121
|
+
x: _voronoiX ?? defaultX,
|
|
122
|
+
x0: _x0 ?? _x,
|
|
123
|
+
y: _voronoiY ?? defaultY,
|
|
124
|
+
y0: _y0 ?? _y,
|
|
76
125
|
};
|
|
126
|
+
|
|
77
127
|
return defaults({}, point, datum);
|
|
78
128
|
}
|
|
79
129
|
|
|
80
|
-
|
|
130
|
+
/**
|
|
131
|
+
* Scale a point based on the origin, direction, and given scale function
|
|
132
|
+
*/
|
|
133
|
+
export function scalePoint(
|
|
134
|
+
props: {
|
|
135
|
+
scale: { x: (x?: number) => number; y: (y?: number) => number };
|
|
136
|
+
polar?: boolean;
|
|
137
|
+
horizontal?: boolean;
|
|
138
|
+
origin?: { x: number; y: number };
|
|
139
|
+
},
|
|
140
|
+
datum: MaybePointData,
|
|
141
|
+
) {
|
|
81
142
|
const { scale, polar, horizontal } = props;
|
|
82
143
|
const d = getPoint(datum);
|
|
83
144
|
const origin = props.origin || { x: 0, y: 0 };
|
|
@@ -93,8 +154,12 @@ export function scalePoint(props, datum) {
|
|
|
93
154
|
};
|
|
94
155
|
}
|
|
95
156
|
|
|
96
|
-
|
|
97
|
-
|
|
157
|
+
/**
|
|
158
|
+
* Returns a padding value from a number or partial padding values
|
|
159
|
+
*/
|
|
160
|
+
export function getPadding(
|
|
161
|
+
padding?: number | Partial<ElementPadding>,
|
|
162
|
+
): ElementPadding {
|
|
98
163
|
const paddingVal = typeof padding === "number" ? padding : 0;
|
|
99
164
|
const paddingObj = typeof padding === "object" ? padding : {};
|
|
100
165
|
return {
|
|
@@ -105,7 +170,10 @@ export function getPadding(props, name = "padding") {
|
|
|
105
170
|
};
|
|
106
171
|
}
|
|
107
172
|
|
|
108
|
-
|
|
173
|
+
/**
|
|
174
|
+
* Returns true if the component is defined as a tooltip
|
|
175
|
+
*/
|
|
176
|
+
export function isTooltip(component?: { type?: { role?: string } }) {
|
|
109
177
|
const labelRole = component && component.type && component.type.role;
|
|
110
178
|
return labelRole === "tooltip";
|
|
111
179
|
}
|
|
@@ -138,9 +206,12 @@ export function getStyles(style, defaultStyles) {
|
|
|
138
206
|
};
|
|
139
207
|
}
|
|
140
208
|
|
|
209
|
+
/**
|
|
210
|
+
* Returns the value of a prop or accessor function with the given props
|
|
211
|
+
*/
|
|
141
212
|
export function evaluateProp<TValue>(
|
|
142
|
-
prop: ValueOrAccessor<TValue,
|
|
143
|
-
props:
|
|
213
|
+
prop: ValueOrAccessor<TValue, Record<string, any>>,
|
|
214
|
+
props: Record<string, any>,
|
|
144
215
|
): TValue {
|
|
145
216
|
return isFunction(prop) ? prop(props) : prop;
|
|
146
217
|
}
|
|
@@ -166,15 +237,29 @@ export function radiansToDegrees(radians) {
|
|
|
166
237
|
return typeof radians === "number" ? radians / (Math.PI / 180) : radians;
|
|
167
238
|
}
|
|
168
239
|
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
240
|
+
/**
|
|
241
|
+
* Get the maximum radius that will fit in the container
|
|
242
|
+
*/
|
|
243
|
+
export function getRadius(options: {
|
|
244
|
+
height: number;
|
|
245
|
+
width: number;
|
|
246
|
+
padding: ElementPadding;
|
|
247
|
+
}) {
|
|
248
|
+
const { width, height, padding } = options;
|
|
249
|
+
const { left, right, top, bottom } = padding;
|
|
172
250
|
return Math.min(width - left - right, height - top - bottom) / 2;
|
|
173
251
|
}
|
|
174
252
|
|
|
175
|
-
|
|
253
|
+
/**
|
|
254
|
+
* Returns the origin for a polar chart within the padded area
|
|
255
|
+
*/
|
|
256
|
+
export function getPolarOrigin(props: {
|
|
257
|
+
height: number;
|
|
258
|
+
width: number;
|
|
259
|
+
padding: ElementPadding;
|
|
260
|
+
}): { x: number; y: number } {
|
|
176
261
|
const { width, height } = props;
|
|
177
|
-
const { top, bottom, left, right } = getPadding(props);
|
|
262
|
+
const { top, bottom, left, right } = getPadding(props.padding);
|
|
178
263
|
const radius = Math.min(width - left - right, height - top - bottom) / 2;
|
|
179
264
|
const offsetWidth = width / 2 + left - right;
|
|
180
265
|
const offsetHeight = height / 2 + top - bottom;
|
|
@@ -184,15 +269,43 @@ export function getPolarOrigin(props) {
|
|
|
184
269
|
};
|
|
185
270
|
}
|
|
186
271
|
|
|
187
|
-
|
|
272
|
+
/**
|
|
273
|
+
* Determine the range of an axis based on the given props
|
|
274
|
+
*/
|
|
275
|
+
export function getRange(
|
|
276
|
+
props: {
|
|
277
|
+
range?: [number, number];
|
|
278
|
+
polar?: boolean;
|
|
279
|
+
innerRadius?: number;
|
|
280
|
+
startAngle?: number;
|
|
281
|
+
endAngle?: number;
|
|
282
|
+
height: number;
|
|
283
|
+
width: number;
|
|
284
|
+
padding: number | Partial<ElementPadding>;
|
|
285
|
+
},
|
|
286
|
+
axis: "x" | "y",
|
|
287
|
+
) {
|
|
188
288
|
if (props.range && props.range[axis]) {
|
|
189
289
|
return props.range[axis];
|
|
190
290
|
} else if (props.range && Array.isArray(props.range)) {
|
|
191
291
|
return props.range;
|
|
192
292
|
}
|
|
193
293
|
return props.polar
|
|
194
|
-
? getPolarRange(
|
|
195
|
-
|
|
294
|
+
? getPolarRange({
|
|
295
|
+
axis,
|
|
296
|
+
innerRadius: props.innerRadius,
|
|
297
|
+
startAngle: props.startAngle,
|
|
298
|
+
endAngle: props.endAngle,
|
|
299
|
+
height: props.height,
|
|
300
|
+
width: props.width,
|
|
301
|
+
padding: getPadding(props.padding),
|
|
302
|
+
})
|
|
303
|
+
: getCartesianRange({
|
|
304
|
+
axis,
|
|
305
|
+
height: props.height,
|
|
306
|
+
width: props.width,
|
|
307
|
+
padding: getPadding(props.padding),
|
|
308
|
+
});
|
|
196
309
|
}
|
|
197
310
|
|
|
198
311
|
/**
|
|
@@ -390,7 +503,10 @@ export function reduceChildren<
|
|
|
390
503
|
* @returns {Boolean} returns true if the props object contains `horizontal: true` of if any
|
|
391
504
|
* children or nested children are horizontal
|
|
392
505
|
*/
|
|
393
|
-
export function isHorizontal(props
|
|
506
|
+
export function isHorizontal(props: {
|
|
507
|
+
horizontal?: boolean;
|
|
508
|
+
children?: React.ReactNode;
|
|
509
|
+
}) {
|
|
394
510
|
if (props.horizontal !== undefined || !props.children) {
|
|
395
511
|
return props.horizontal;
|
|
396
512
|
}
|
package/src/victory-util/log.ts
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: string) {
|
|
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,6 +1,7 @@
|
|
|
1
1
|
// http://www.pearsonified.com/2012/01/characters-per-line.php
|
|
2
2
|
/* eslint-disable no-magic-numbers */
|
|
3
|
-
import
|
|
3
|
+
import defaults from "lodash/defaults";
|
|
4
|
+
import memoize from "lodash/memoize";
|
|
4
5
|
|
|
5
6
|
// Based on measuring specific character widths
|
|
6
7
|
// as in the following example https://bl.ocks.org/tophtucker/62f93a4658387bb61e4510c37e2e97cf
|
|
@@ -30,11 +30,6 @@ export function getValueForAxis<T = unknown>(
|
|
|
30
30
|
return value;
|
|
31
31
|
}
|
|
32
32
|
|
|
33
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-function-type
|
|
34
|
-
export function isFunction<T = Function>(func?: unknown): func is T {
|
|
35
|
-
return typeof func === "function";
|
|
36
|
-
}
|
|
37
|
-
|
|
38
33
|
export function isDate(value: unknown): value is Date {
|
|
39
34
|
return value instanceof Date;
|
|
40
35
|
}
|
|
@@ -78,7 +78,7 @@ export function assert<T>(
|
|
|
78
78
|
* @returns {Object}: object containing remaining acceptable props
|
|
79
79
|
*/
|
|
80
80
|
export const getSafeUserProps = <T>(
|
|
81
|
-
props: T,
|
|
81
|
+
props: T extends Record<string, any> ? T : never,
|
|
82
82
|
): Record<SafeAttribute, string> => {
|
|
83
83
|
const propsToFilter = { ...props };
|
|
84
84
|
return Object.fromEntries(
|
|
@@ -1,5 +1,9 @@
|
|
|
1
|
-
import { defaults, uniq, groupBy, uniqBy } from "lodash";
|
|
2
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
|
+
|
|
3
7
|
import * as Axis from "./axis";
|
|
4
8
|
import * as Style from "./style";
|
|
5
9
|
import * as Data from "./data";
|