victory-core 35.11.2 → 36.1.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/LICENSE.txt +30 -0
- package/dist/victory-core.js +4376 -1142
- package/dist/victory-core.min.js +1 -1
- package/es/index.d.ts +6 -0
- package/es/index.js +8 -2
- package/es/victory-accessible-group/victory-accessible-group.js +1 -3
- package/es/victory-animation/victory-animation.js +1 -3
- package/es/victory-clip-container/victory-clip-container.js +1 -3
- package/es/victory-container/victory-container.js +1 -3
- package/es/victory-label/victory-label.js +3 -3
- package/es/victory-portal/portal.js +1 -3
- package/es/victory-portal/victory-portal.js +1 -3
- package/es/victory-primitives/point.js +1 -1
- package/es/victory-transition/victory-transition.js +1 -3
- package/es/victory-util/add-events.js +305 -308
- package/es/victory-util/hooks.js +137 -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/timer.js +1 -3
- package/es/victory-util/wrapper.js +372 -457
- package/lib/index.d.ts +6 -0
- package/lib/index.js +78 -8
- package/lib/victory-accessible-group/victory-accessible-group.js +1 -3
- package/lib/victory-animation/victory-animation.js +1 -3
- package/lib/victory-clip-container/victory-clip-container.js +1 -3
- package/lib/victory-container/victory-container.js +1 -3
- package/lib/victory-label/victory-label.js +3 -3
- package/lib/victory-portal/portal.js +1 -3
- package/lib/victory-portal/victory-portal.js +1 -3
- package/lib/victory-primitives/point.js +10 -10
- package/lib/victory-transition/victory-transition.js +1 -3
- package/lib/victory-util/add-events.js +301 -304
- package/lib/victory-util/hooks.js +162 -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/timer.js +1 -3
- package/lib/victory-util/wrapper.js +389 -446
- package/package.json +7 -3
- package/src/index.d.ts +6 -0
- 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.js +131 -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
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
import _some from "lodash/some";
|
|
2
|
+
import _defaults from "lodash/defaults";
|
|
3
|
+
|
|
4
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; var ownKeys = Object.keys(source); if (typeof Object.getOwnPropertySymbols === 'function') { ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function (sym) { return Object.getOwnPropertyDescriptor(source, sym).enumerable; })); } ownKeys.forEach(function (key) { _defineProperty(target, key, source[key]); }); } return target; }
|
|
5
|
+
|
|
6
|
+
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
7
|
+
|
|
8
|
+
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _nonIterableRest(); }
|
|
9
|
+
|
|
10
|
+
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance"); }
|
|
11
|
+
|
|
12
|
+
function _iterableToArrayLimit(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
|
|
13
|
+
|
|
14
|
+
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
15
|
+
|
|
16
|
+
import React from "react";
|
|
17
|
+
import * as Collection from "./collection";
|
|
18
|
+
import * as Transitions from "./transitions";
|
|
19
|
+
export var usePreviousProps = function (props) {
|
|
20
|
+
var ref = React.useRef();
|
|
21
|
+
React.useEffect(function () {
|
|
22
|
+
ref.current = props;
|
|
23
|
+
});
|
|
24
|
+
return ref.current || {};
|
|
25
|
+
};
|
|
26
|
+
var INITIAL_STATE = {
|
|
27
|
+
nodesShouldLoad: false,
|
|
28
|
+
nodesDoneLoad: false,
|
|
29
|
+
animating: true
|
|
30
|
+
};
|
|
31
|
+
export var useAnimationState = function () {
|
|
32
|
+
var initialState = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : INITIAL_STATE;
|
|
33
|
+
|
|
34
|
+
var _React$useState = React.useState(initialState),
|
|
35
|
+
_React$useState2 = _slicedToArray(_React$useState, 2),
|
|
36
|
+
state = _React$useState2[0],
|
|
37
|
+
_setState = _React$useState2[1]; // This allows us to use a state object and maintain the same API as this.setState
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
var setState = React.useCallback(function (newState) {
|
|
41
|
+
_setState(function (oldState) {
|
|
42
|
+
return _objectSpread({}, oldState, newState);
|
|
43
|
+
});
|
|
44
|
+
}, [_setState]); // This is a copy of Wrapper.getAnimationProps
|
|
45
|
+
|
|
46
|
+
var getAnimationProps = React.useCallback(function (props, child, index) {
|
|
47
|
+
if (!props.animate) {
|
|
48
|
+
return child.props.animate;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
var getFilteredState = function () {
|
|
52
|
+
var childrenTransitions = state && state.childrenTransitions;
|
|
53
|
+
childrenTransitions = Collection.isArrayOfArrays(childrenTransitions) ? childrenTransitions[index] : childrenTransitions;
|
|
54
|
+
return _defaults({
|
|
55
|
+
childrenTransitions: childrenTransitions
|
|
56
|
+
}, state);
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
var getTransitions = props.animate && props.animate.getTransitions;
|
|
60
|
+
var filteredState = getFilteredState();
|
|
61
|
+
var parentState = props.animate && props.animate.parentState || filteredState;
|
|
62
|
+
|
|
63
|
+
if (!getTransitions) {
|
|
64
|
+
var getTransitionProps = Transitions.getTransitionPropsFactory(props, filteredState, function (newState) {
|
|
65
|
+
return setState(newState);
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
getTransitions = function (childComponent) {
|
|
69
|
+
return getTransitionProps(childComponent, index);
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
return _defaults({
|
|
74
|
+
getTransitions: getTransitions,
|
|
75
|
+
parentState: parentState
|
|
76
|
+
}, props.animate, child.props.animate);
|
|
77
|
+
}, [state, setState]); // This is a copy of Wrapper.setAnimationState
|
|
78
|
+
|
|
79
|
+
var setAnimationState = React.useCallback(function (props, nextProps) {
|
|
80
|
+
if (!props.animate) {
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
if (props.animate.parentState) {
|
|
85
|
+
var nodesWillExit = props.animate.parentState.nodesWillExit;
|
|
86
|
+
var oldProps = nodesWillExit ? props : null;
|
|
87
|
+
|
|
88
|
+
var newState = _defaults({
|
|
89
|
+
oldProps: oldProps,
|
|
90
|
+
nextProps: nextProps
|
|
91
|
+
}, props.animate.parentState);
|
|
92
|
+
|
|
93
|
+
setState(newState);
|
|
94
|
+
} else {
|
|
95
|
+
var oldChildren = React.Children.toArray(props.children);
|
|
96
|
+
var nextChildren = React.Children.toArray(nextProps.children);
|
|
97
|
+
|
|
98
|
+
var isContinuous = function (child) {
|
|
99
|
+
var check = function (c) {
|
|
100
|
+
return c.type && c.type.continuous;
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
return Array.isArray(child) ? _some(child, check) : check(child);
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
var continuous = !props.polar && _some(oldChildren, function (child) {
|
|
107
|
+
return isContinuous(child) || child.props.children && isContinuous(child.props.children);
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
var _Transitions$getIniti = Transitions.getInitialTransitionState(oldChildren, nextChildren),
|
|
111
|
+
_nodesWillExit = _Transitions$getIniti.nodesWillExit,
|
|
112
|
+
nodesWillEnter = _Transitions$getIniti.nodesWillEnter,
|
|
113
|
+
childrenTransitions = _Transitions$getIniti.childrenTransitions,
|
|
114
|
+
nodesShouldEnter = _Transitions$getIniti.nodesShouldEnter;
|
|
115
|
+
|
|
116
|
+
setState({
|
|
117
|
+
nodesWillExit: _nodesWillExit,
|
|
118
|
+
nodesWillEnter: nodesWillEnter,
|
|
119
|
+
nodesShouldEnter: nodesShouldEnter,
|
|
120
|
+
childrenTransitions: Collection.isArrayOfArrays(childrenTransitions) ? childrenTransitions[0] : childrenTransitions,
|
|
121
|
+
oldProps: _nodesWillExit ? props : null,
|
|
122
|
+
nextProps: nextProps,
|
|
123
|
+
continuous: continuous
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
}, [setState]);
|
|
127
|
+
var getProps = React.useCallback(function (initialProps) {
|
|
128
|
+
return state && state.nodesWillExit ? state.oldProps || initialProps : initialProps;
|
|
129
|
+
}, [state]);
|
|
130
|
+
return {
|
|
131
|
+
state: state,
|
|
132
|
+
setState: setState,
|
|
133
|
+
getAnimationProps: getAnimationProps,
|
|
134
|
+
setAnimationState: setAnimationState,
|
|
135
|
+
getProps: getProps
|
|
136
|
+
};
|
|
137
|
+
};
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import * as d3Shape from "d3-shape";
|
|
2
|
+
|
|
3
|
+
var defined = function (d) {
|
|
4
|
+
var y = d._y1 !== undefined ? d._y1 : d._y;
|
|
5
|
+
return y !== null && y !== undefined && d._y0 !== null;
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
var getXAccessor = function (scale) {
|
|
9
|
+
return function (d) {
|
|
10
|
+
return scale.x(d._x1 !== undefined ? d._x1 : d._x);
|
|
11
|
+
};
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
var getYAccessor = function (scale) {
|
|
15
|
+
return function (d) {
|
|
16
|
+
return scale.y(d._y1 !== undefined ? d._y1 : d._y);
|
|
17
|
+
};
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
var getAngleAccessor = function (scale) {
|
|
21
|
+
return function (d) {
|
|
22
|
+
var x = scale.x(d._x1 !== undefined ? d._x1 : d._x);
|
|
23
|
+
return -1 * x + Math.PI / 2;
|
|
24
|
+
};
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
var toNewName = function (interpolation) {
|
|
28
|
+
// d3 shape changed the naming scheme for interpolators from "basis" -> "curveBasis" etc.
|
|
29
|
+
var capitalize = function (s) {
|
|
30
|
+
return s && s[0].toUpperCase() + s.slice(1);
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
return "curve".concat(capitalize(interpolation));
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
export var getLineFunction = function (props) {
|
|
37
|
+
var polar = props.polar,
|
|
38
|
+
scale = props.scale,
|
|
39
|
+
horizontal = props.horizontal;
|
|
40
|
+
var defaultOpenCurve = polar ? false : true;
|
|
41
|
+
var openCurve = props.openCurve === undefined ? defaultOpenCurve : props.openCurve;
|
|
42
|
+
var interpolationFunction = typeof props.interpolation === "function" && props.interpolation;
|
|
43
|
+
var interpolationName = typeof props.interpolation === "string" && (!openCurve ? "".concat(toNewName(props.interpolation), "Closed") : toNewName(props.interpolation));
|
|
44
|
+
return polar ? d3Shape.lineRadial().defined(defined).curve(interpolationFunction || d3Shape[interpolationName]).angle(getAngleAccessor(scale)).radius(getYAccessor(scale)) : d3Shape.line().defined(defined).curve(interpolationFunction || d3Shape[interpolationName]).x(horizontal ? getYAccessor(scale) : getXAccessor(scale)).y(horizontal ? getXAccessor(scale) : getYAccessor(scale));
|
|
45
|
+
};
|
|
File without changes
|
package/es/victory-util/timer.js
CHANGED
|
@@ -6,9 +6,7 @@ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _d
|
|
|
6
6
|
|
|
7
7
|
import { timer, now } from "d3-timer";
|
|
8
8
|
|
|
9
|
-
var Timer =
|
|
10
|
-
/*#__PURE__*/
|
|
11
|
-
function () {
|
|
9
|
+
var Timer = /*#__PURE__*/function () {
|
|
12
10
|
function Timer() {
|
|
13
11
|
_classCallCheck(this, Timer);
|
|
14
12
|
|