victory-core 35.11.3 → 36.2.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/dist/victory-core.js +10581 -8123
- package/dist/victory-core.min.js +1 -1
- package/es/index.js +9 -2
- package/es/victory-label/victory-label.js +3 -3
- package/es/victory-primitives/point.js +1 -1
- package/es/victory-util/hooks/index.js +2 -0
- package/es/victory-util/hooks/use-animation-state.js +130 -0
- package/es/victory-util/hooks/use-previous-props.js +8 -0
- package/es/victory-util/line-helpers.js +45 -0
- package/es/{victory-primitives/path-helpers.js → victory-util/point-path-helpers.js} +0 -0
- package/es/victory-util/wrapper.js +372 -457
- package/lib/index.js +20 -8
- package/lib/victory-label/victory-label.js +3 -3
- package/lib/victory-primitives/point.js +10 -10
- package/lib/victory-util/hooks/index.js +21 -0
- package/lib/victory-util/hooks/use-animation-state.js +151 -0
- package/lib/victory-util/hooks/use-previous-props.js +22 -0
- package/lib/victory-util/line-helpers.js +56 -0
- package/lib/{victory-primitives/path-helpers.js → victory-util/point-path-helpers.js} +0 -0
- package/lib/victory-util/wrapper.js +389 -446
- package/package.json +6 -3
- package/src/index.js +5 -1
- package/src/victory-label/victory-label.js +3 -3
- package/src/victory-primitives/point.js +1 -1
- package/src/victory-util/hooks/index.js +2 -0
- package/src/victory-util/hooks/use-animation-state.js +123 -0
- package/src/victory-util/hooks/use-previous-props.js +9 -0
- package/src/victory-util/line-helpers.js +54 -0
- package/src/{victory-primitives/path-helpers.js → victory-util/point-path-helpers.js} +0 -0
- package/src/victory-util/transitions.js +0 -1
- package/src/victory-util/wrapper.js +422 -518
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "victory-core",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "36.2.0",
|
|
4
4
|
"description": "Victory Core",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"data visualization",
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
"license": "MIT",
|
|
21
21
|
"dependencies": {
|
|
22
22
|
"d3-ease": "^1.0.0",
|
|
23
|
-
"d3-interpolate": "^
|
|
23
|
+
"d3-interpolate": "^1.1.1",
|
|
24
24
|
"d3-scale": "^1.0.0",
|
|
25
25
|
"d3-shape": "^1.2.0",
|
|
26
26
|
"d3-timer": "^1.0.0",
|
|
@@ -28,6 +28,9 @@
|
|
|
28
28
|
"prop-types": "^15.5.8",
|
|
29
29
|
"react-fast-compare": "^2.0.0"
|
|
30
30
|
},
|
|
31
|
+
"resolutions": {
|
|
32
|
+
"d3-interpolate/d3-color": "^3.0.0"
|
|
33
|
+
},
|
|
31
34
|
"peerDependencies": {
|
|
32
35
|
"react": "^16.6.0 || ^17.0.0"
|
|
33
36
|
},
|
|
@@ -35,5 +38,5 @@
|
|
|
35
38
|
"version": "yarn run nps build-libs && nps build-dists"
|
|
36
39
|
},
|
|
37
40
|
"sideEffects": false,
|
|
38
|
-
"gitHead": "
|
|
41
|
+
"gitHead": "00c362fcd3e8f3880e14d3ba42873c34dd69c577"
|
|
39
42
|
}
|
package/src/index.js
CHANGED
|
@@ -40,7 +40,11 @@ export * as TextSize from "./victory-util/textsize";
|
|
|
40
40
|
export { default as Timer } from "./victory-util/timer";
|
|
41
41
|
export * as Transitions from "./victory-util/transitions";
|
|
42
42
|
export * as CommonProps from "./victory-util/common-props";
|
|
43
|
-
export
|
|
43
|
+
export * as Wrapper from "./victory-util/wrapper";
|
|
44
44
|
export * as Axis from "./victory-util/axis";
|
|
45
45
|
export { default as TimerContext } from "./victory-util/timer-context";
|
|
46
46
|
export { default as PortalContext } from "./victory-portal/portal-context";
|
|
47
|
+
export * as Hooks from "./victory-util/hooks";
|
|
48
|
+
export * as LineHelpers from "./victory-util/line-helpers";
|
|
49
|
+
// TODO: Fix this default export
|
|
50
|
+
export { default as PointPathHelpers } from "./victory-util/point-path-helpers";
|
|
@@ -51,7 +51,7 @@ const getSingleValue = (prop, index = 0) => {
|
|
|
51
51
|
return Array.isArray(prop) ? prop[index] || prop[0] : prop;
|
|
52
52
|
};
|
|
53
53
|
|
|
54
|
-
const
|
|
54
|
+
const shouldUseMultilineBackgrounds = (props) => {
|
|
55
55
|
const { backgroundStyle, backgroundPadding } = props;
|
|
56
56
|
return (
|
|
57
57
|
(Array.isArray(backgroundStyle) && !isEmpty(backgroundStyle)) ||
|
|
@@ -365,7 +365,7 @@ const getChildBackgrounds = (calculatedProps, tspanValues) => {
|
|
|
365
365
|
};
|
|
366
366
|
|
|
367
367
|
const getBackgroundElement = (calculatedProps, tspanValues) => {
|
|
368
|
-
return
|
|
368
|
+
return shouldUseMultilineBackgrounds(calculatedProps)
|
|
369
369
|
? getChildBackgrounds(calculatedProps, tspanValues)
|
|
370
370
|
: getFullBackground(calculatedProps, tspanValues);
|
|
371
371
|
};
|
|
@@ -387,7 +387,7 @@ const calculateSpanDy = (tspanValues, i, calculatedProps) => {
|
|
|
387
387
|
currentCaps / 2 +
|
|
388
388
|
previousCaps / 2;
|
|
389
389
|
|
|
390
|
-
return
|
|
390
|
+
return shouldUseMultilineBackgrounds(calculatedProps)
|
|
391
391
|
? textHeight +
|
|
392
392
|
current.backgroundPadding.top +
|
|
393
393
|
previous.backgroundPadding.bottom
|
|
@@ -2,7 +2,7 @@ import React from "react";
|
|
|
2
2
|
import PropTypes from "prop-types";
|
|
3
3
|
import { assign } from "lodash";
|
|
4
4
|
import * as Helpers from "../victory-util/helpers";
|
|
5
|
-
import pathHelpers from "
|
|
5
|
+
import pathHelpers from "../victory-util/point-path-helpers";
|
|
6
6
|
import * as CommonProps from "../victory-util/common-props";
|
|
7
7
|
import Path from "./path";
|
|
8
8
|
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { defaults, some } from "lodash";
|
|
3
|
+
|
|
4
|
+
import * as Collection from "../collection";
|
|
5
|
+
import * as Transitions from "../transitions";
|
|
6
|
+
|
|
7
|
+
const INITIAL_STATE = {
|
|
8
|
+
nodesShouldLoad: false,
|
|
9
|
+
nodesDoneLoad: false,
|
|
10
|
+
animating: true
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
export const useAnimationState = (initialState = INITIAL_STATE) => {
|
|
14
|
+
const [state, _setState] = React.useState(initialState);
|
|
15
|
+
|
|
16
|
+
// This allows us to use a state object and maintain the same API as this.setState
|
|
17
|
+
const setState = React.useCallback(
|
|
18
|
+
(newState) => {
|
|
19
|
+
_setState((oldState) => ({ ...oldState, ...newState }));
|
|
20
|
+
},
|
|
21
|
+
[_setState]
|
|
22
|
+
);
|
|
23
|
+
|
|
24
|
+
// This is a copy of Wrapper.getAnimationProps
|
|
25
|
+
const getAnimationProps = React.useCallback(
|
|
26
|
+
(props, child, index) => {
|
|
27
|
+
if (!props.animate) {
|
|
28
|
+
return child.props.animate;
|
|
29
|
+
}
|
|
30
|
+
const getFilteredState = () => {
|
|
31
|
+
let childrenTransitions = state && state.childrenTransitions;
|
|
32
|
+
childrenTransitions = Collection.isArrayOfArrays(childrenTransitions)
|
|
33
|
+
? childrenTransitions[index]
|
|
34
|
+
: childrenTransitions;
|
|
35
|
+
return defaults({ childrenTransitions }, state);
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
let getTransitions = props.animate && props.animate.getTransitions;
|
|
39
|
+
const filteredState = getFilteredState();
|
|
40
|
+
const parentState =
|
|
41
|
+
(props.animate && props.animate.parentState) || filteredState;
|
|
42
|
+
if (!getTransitions) {
|
|
43
|
+
const getTransitionProps = Transitions.getTransitionPropsFactory(
|
|
44
|
+
props,
|
|
45
|
+
filteredState,
|
|
46
|
+
(newState) => setState(newState)
|
|
47
|
+
);
|
|
48
|
+
getTransitions = (childComponent) =>
|
|
49
|
+
getTransitionProps(childComponent, index);
|
|
50
|
+
}
|
|
51
|
+
return defaults(
|
|
52
|
+
{ getTransitions, parentState },
|
|
53
|
+
props.animate,
|
|
54
|
+
child.props.animate
|
|
55
|
+
);
|
|
56
|
+
},
|
|
57
|
+
[state, setState]
|
|
58
|
+
);
|
|
59
|
+
|
|
60
|
+
// This is a copy of Wrapper.setAnimationState
|
|
61
|
+
const setAnimationState = React.useCallback(
|
|
62
|
+
(props, nextProps) => {
|
|
63
|
+
if (!props.animate) {
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
if (props.animate.parentState) {
|
|
67
|
+
const nodesWillExit = props.animate.parentState.nodesWillExit;
|
|
68
|
+
const oldProps = nodesWillExit ? props : null;
|
|
69
|
+
const newState = defaults(
|
|
70
|
+
{ oldProps, nextProps },
|
|
71
|
+
props.animate.parentState
|
|
72
|
+
);
|
|
73
|
+
setState(newState);
|
|
74
|
+
} else {
|
|
75
|
+
const oldChildren = React.Children.toArray(props.children);
|
|
76
|
+
const nextChildren = React.Children.toArray(nextProps.children);
|
|
77
|
+
const isContinuous = (child) => {
|
|
78
|
+
const check = (c) => c.type && c.type.continuous;
|
|
79
|
+
return Array.isArray(child) ? some(child, check) : check(child);
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
const continuous =
|
|
83
|
+
!props.polar &&
|
|
84
|
+
some(oldChildren, (child) => {
|
|
85
|
+
return (
|
|
86
|
+
isContinuous(child) ||
|
|
87
|
+
(child.props.children && isContinuous(child.props.children))
|
|
88
|
+
);
|
|
89
|
+
});
|
|
90
|
+
const {
|
|
91
|
+
nodesWillExit,
|
|
92
|
+
nodesWillEnter,
|
|
93
|
+
childrenTransitions,
|
|
94
|
+
nodesShouldEnter
|
|
95
|
+
} = Transitions.getInitialTransitionState(oldChildren, nextChildren);
|
|
96
|
+
|
|
97
|
+
setState({
|
|
98
|
+
nodesWillExit,
|
|
99
|
+
nodesWillEnter,
|
|
100
|
+
nodesShouldEnter,
|
|
101
|
+
childrenTransitions: Collection.isArrayOfArrays(childrenTransitions)
|
|
102
|
+
? childrenTransitions[0]
|
|
103
|
+
: childrenTransitions,
|
|
104
|
+
oldProps: nodesWillExit ? props : null,
|
|
105
|
+
nextProps,
|
|
106
|
+
continuous
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
},
|
|
110
|
+
[setState]
|
|
111
|
+
);
|
|
112
|
+
|
|
113
|
+
const getProps = React.useCallback(
|
|
114
|
+
(initialProps) => {
|
|
115
|
+
return state && state.nodesWillExit
|
|
116
|
+
? state.oldProps || initialProps
|
|
117
|
+
: initialProps;
|
|
118
|
+
},
|
|
119
|
+
[state]
|
|
120
|
+
);
|
|
121
|
+
|
|
122
|
+
return { state, setState, getAnimationProps, setAnimationState, getProps };
|
|
123
|
+
};
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import * as d3Shape from "d3-shape";
|
|
2
|
+
|
|
3
|
+
const defined = (d) => {
|
|
4
|
+
const y = d._y1 !== undefined ? d._y1 : d._y;
|
|
5
|
+
return y !== null && y !== undefined && d._y0 !== null;
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
const getXAccessor = (scale) => {
|
|
9
|
+
return (d) => scale.x(d._x1 !== undefined ? d._x1 : d._x);
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
const getYAccessor = (scale) => {
|
|
13
|
+
return (d) => scale.y(d._y1 !== undefined ? d._y1 : d._y);
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
const getAngleAccessor = (scale) => {
|
|
17
|
+
return (d) => {
|
|
18
|
+
const x = scale.x(d._x1 !== undefined ? d._x1 : d._x);
|
|
19
|
+
return -1 * x + Math.PI / 2;
|
|
20
|
+
};
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
const toNewName = (interpolation) => {
|
|
24
|
+
// d3 shape changed the naming scheme for interpolators from "basis" -> "curveBasis" etc.
|
|
25
|
+
const capitalize = (s) => s && s[0].toUpperCase() + s.slice(1);
|
|
26
|
+
return `curve${capitalize(interpolation)}`;
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
export const getLineFunction = (props) => {
|
|
30
|
+
const { polar, scale, horizontal } = props;
|
|
31
|
+
const defaultOpenCurve = polar ? false : true;
|
|
32
|
+
const openCurve =
|
|
33
|
+
props.openCurve === undefined ? defaultOpenCurve : props.openCurve;
|
|
34
|
+
const interpolationFunction =
|
|
35
|
+
typeof props.interpolation === "function" && props.interpolation;
|
|
36
|
+
const interpolationName =
|
|
37
|
+
typeof props.interpolation === "string" &&
|
|
38
|
+
(!openCurve
|
|
39
|
+
? `${toNewName(props.interpolation)}Closed`
|
|
40
|
+
: toNewName(props.interpolation));
|
|
41
|
+
return polar
|
|
42
|
+
? d3Shape
|
|
43
|
+
.lineRadial()
|
|
44
|
+
.defined(defined)
|
|
45
|
+
.curve(interpolationFunction || d3Shape[interpolationName])
|
|
46
|
+
.angle(getAngleAccessor(scale))
|
|
47
|
+
.radius(getYAccessor(scale))
|
|
48
|
+
: d3Shape
|
|
49
|
+
.line()
|
|
50
|
+
.defined(defined)
|
|
51
|
+
.curve(interpolationFunction || d3Shape[interpolationName])
|
|
52
|
+
.x(horizontal ? getYAccessor(scale) : getXAccessor(scale))
|
|
53
|
+
.y(horizontal ? getXAccessor(scale) : getYAccessor(scale));
|
|
54
|
+
};
|
|
File without changes
|