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.
Files changed (31) hide show
  1. package/dist/victory-core.js +10581 -8123
  2. package/dist/victory-core.min.js +1 -1
  3. package/es/index.js +9 -2
  4. package/es/victory-label/victory-label.js +3 -3
  5. package/es/victory-primitives/point.js +1 -1
  6. package/es/victory-util/hooks/index.js +2 -0
  7. package/es/victory-util/hooks/use-animation-state.js +130 -0
  8. package/es/victory-util/hooks/use-previous-props.js +8 -0
  9. package/es/victory-util/line-helpers.js +45 -0
  10. package/es/{victory-primitives/path-helpers.js → victory-util/point-path-helpers.js} +0 -0
  11. package/es/victory-util/wrapper.js +372 -457
  12. package/lib/index.js +20 -8
  13. package/lib/victory-label/victory-label.js +3 -3
  14. package/lib/victory-primitives/point.js +10 -10
  15. package/lib/victory-util/hooks/index.js +21 -0
  16. package/lib/victory-util/hooks/use-animation-state.js +151 -0
  17. package/lib/victory-util/hooks/use-previous-props.js +22 -0
  18. package/lib/victory-util/line-helpers.js +56 -0
  19. package/lib/{victory-primitives/path-helpers.js → victory-util/point-path-helpers.js} +0 -0
  20. package/lib/victory-util/wrapper.js +389 -446
  21. package/package.json +6 -3
  22. package/src/index.js +5 -1
  23. package/src/victory-label/victory-label.js +3 -3
  24. package/src/victory-primitives/point.js +1 -1
  25. package/src/victory-util/hooks/index.js +2 -0
  26. package/src/victory-util/hooks/use-animation-state.js +123 -0
  27. package/src/victory-util/hooks/use-previous-props.js +9 -0
  28. package/src/victory-util/line-helpers.js +54 -0
  29. package/src/{victory-primitives/path-helpers.js → victory-util/point-path-helpers.js} +0 -0
  30. package/src/victory-util/transitions.js +0 -1
  31. package/src/victory-util/wrapper.js +422 -518
package/es/index.js CHANGED
@@ -57,8 +57,15 @@ import * as _Transitions from "./victory-util/transitions";
57
57
  export { _Transitions as Transitions };
58
58
  import * as _CommonProps from "./victory-util/common-props";
59
59
  export { _CommonProps as CommonProps };
60
- export { default as Wrapper } from "./victory-util/wrapper";
60
+ import * as _Wrapper from "./victory-util/wrapper";
61
+ export { _Wrapper as Wrapper };
61
62
  import * as _Axis from "./victory-util/axis";
62
63
  export { _Axis as Axis };
63
64
  export { default as TimerContext } from "./victory-util/timer-context";
64
- export { default as PortalContext } from "./victory-portal/portal-context";
65
+ export { default as PortalContext } from "./victory-portal/portal-context";
66
+ import * as _Hooks from "./victory-util/hooks";
67
+ export { _Hooks as Hooks };
68
+ import * as _LineHelpers from "./victory-util/line-helpers";
69
+ export { _LineHelpers as LineHelpers }; // TODO: Fix this default export
70
+
71
+ export { default as PointPathHelpers } from "./victory-util/point-path-helpers";
@@ -69,7 +69,7 @@ var getSingleValue = function (prop) {
69
69
  return Array.isArray(prop) ? prop[index] || prop[0] : prop;
70
70
  };
71
71
 
72
- var useMultiLineBackgrounds = function (props) {
72
+ var shouldUseMultilineBackgrounds = function (props) {
73
73
  var backgroundStyle = props.backgroundStyle,
74
74
  backgroundPadding = props.backgroundPadding;
75
75
  return Array.isArray(backgroundStyle) && !_isEmpty(backgroundStyle) || Array.isArray(backgroundPadding) && !_isEmpty(backgroundPadding);
@@ -361,7 +361,7 @@ var getChildBackgrounds = function (calculatedProps, tspanValues) {
361
361
  };
362
362
 
363
363
  var getBackgroundElement = function (calculatedProps, tspanValues) {
364
- return useMultiLineBackgrounds(calculatedProps) ? getChildBackgrounds(calculatedProps, tspanValues) : getFullBackground(calculatedProps, tspanValues);
364
+ return shouldUseMultilineBackgrounds(calculatedProps) ? getChildBackgrounds(calculatedProps, tspanValues) : getFullBackground(calculatedProps, tspanValues);
365
365
  };
366
366
 
367
367
  var calculateSpanDy = function (tspanValues, i, calculatedProps) {
@@ -372,7 +372,7 @@ var calculateSpanDy = function (tspanValues, i, calculatedProps) {
372
372
  var previousCaps = previous.fontSize - previous.capHeight;
373
373
  var currentCaps = current.fontSize - current.capHeight;
374
374
  var textHeight = previousHeight - previous.fontSize / 2 + current.fontSize / 2 - previousHeight / 2 + currentHeight / 2 - currentCaps / 2 + previousCaps / 2;
375
- return useMultiLineBackgrounds(calculatedProps) ? textHeight + current.backgroundPadding.top + previous.backgroundPadding.bottom : textHeight;
375
+ return shouldUseMultilineBackgrounds(calculatedProps) ? textHeight + current.backgroundPadding.top + previous.backgroundPadding.bottom : textHeight;
376
376
  };
377
377
 
378
378
  var getTSpanDy = function (tspanValues, calculatedProps, i) {
@@ -7,7 +7,7 @@ function _defineProperty(obj, key, value) { if (key in obj) { Object.definePrope
7
7
  import React from "react";
8
8
  import PropTypes from "prop-types";
9
9
  import * as Helpers from "../victory-util/helpers";
10
- import pathHelpers from "./path-helpers";
10
+ import pathHelpers from "../victory-util/point-path-helpers";
11
11
  import * as CommonProps from "../victory-util/common-props";
12
12
  import Path from "./path";
13
13
 
@@ -0,0 +1,2 @@
1
+ export { usePreviousProps } from "./use-previous-props";
2
+ export { useAnimationState } from "./use-animation-state";
@@ -0,0 +1,130 @@
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
+ var INITIAL_STATE = {
20
+ nodesShouldLoad: false,
21
+ nodesDoneLoad: false,
22
+ animating: true
23
+ };
24
+ export var useAnimationState = function () {
25
+ var initialState = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : INITIAL_STATE;
26
+
27
+ var _React$useState = React.useState(initialState),
28
+ _React$useState2 = _slicedToArray(_React$useState, 2),
29
+ state = _React$useState2[0],
30
+ _setState = _React$useState2[1]; // This allows us to use a state object and maintain the same API as this.setState
31
+
32
+
33
+ var setState = React.useCallback(function (newState) {
34
+ _setState(function (oldState) {
35
+ return _objectSpread({}, oldState, newState);
36
+ });
37
+ }, [_setState]); // This is a copy of Wrapper.getAnimationProps
38
+
39
+ var getAnimationProps = React.useCallback(function (props, child, index) {
40
+ if (!props.animate) {
41
+ return child.props.animate;
42
+ }
43
+
44
+ var getFilteredState = function () {
45
+ var childrenTransitions = state && state.childrenTransitions;
46
+ childrenTransitions = Collection.isArrayOfArrays(childrenTransitions) ? childrenTransitions[index] : childrenTransitions;
47
+ return _defaults({
48
+ childrenTransitions: childrenTransitions
49
+ }, state);
50
+ };
51
+
52
+ var getTransitions = props.animate && props.animate.getTransitions;
53
+ var filteredState = getFilteredState();
54
+ var parentState = props.animate && props.animate.parentState || filteredState;
55
+
56
+ if (!getTransitions) {
57
+ var getTransitionProps = Transitions.getTransitionPropsFactory(props, filteredState, function (newState) {
58
+ return setState(newState);
59
+ });
60
+
61
+ getTransitions = function (childComponent) {
62
+ return getTransitionProps(childComponent, index);
63
+ };
64
+ }
65
+
66
+ return _defaults({
67
+ getTransitions: getTransitions,
68
+ parentState: parentState
69
+ }, props.animate, child.props.animate);
70
+ }, [state, setState]); // This is a copy of Wrapper.setAnimationState
71
+
72
+ var setAnimationState = React.useCallback(function (props, nextProps) {
73
+ if (!props.animate) {
74
+ return;
75
+ }
76
+
77
+ if (props.animate.parentState) {
78
+ var nodesWillExit = props.animate.parentState.nodesWillExit;
79
+ var oldProps = nodesWillExit ? props : null;
80
+
81
+ var newState = _defaults({
82
+ oldProps: oldProps,
83
+ nextProps: nextProps
84
+ }, props.animate.parentState);
85
+
86
+ setState(newState);
87
+ } else {
88
+ var oldChildren = React.Children.toArray(props.children);
89
+ var nextChildren = React.Children.toArray(nextProps.children);
90
+
91
+ var isContinuous = function (child) {
92
+ var check = function (c) {
93
+ return c.type && c.type.continuous;
94
+ };
95
+
96
+ return Array.isArray(child) ? _some(child, check) : check(child);
97
+ };
98
+
99
+ var continuous = !props.polar && _some(oldChildren, function (child) {
100
+ return isContinuous(child) || child.props.children && isContinuous(child.props.children);
101
+ });
102
+
103
+ var _Transitions$getIniti = Transitions.getInitialTransitionState(oldChildren, nextChildren),
104
+ _nodesWillExit = _Transitions$getIniti.nodesWillExit,
105
+ nodesWillEnter = _Transitions$getIniti.nodesWillEnter,
106
+ childrenTransitions = _Transitions$getIniti.childrenTransitions,
107
+ nodesShouldEnter = _Transitions$getIniti.nodesShouldEnter;
108
+
109
+ setState({
110
+ nodesWillExit: _nodesWillExit,
111
+ nodesWillEnter: nodesWillEnter,
112
+ nodesShouldEnter: nodesShouldEnter,
113
+ childrenTransitions: Collection.isArrayOfArrays(childrenTransitions) ? childrenTransitions[0] : childrenTransitions,
114
+ oldProps: _nodesWillExit ? props : null,
115
+ nextProps: nextProps,
116
+ continuous: continuous
117
+ });
118
+ }
119
+ }, [setState]);
120
+ var getProps = React.useCallback(function (initialProps) {
121
+ return state && state.nodesWillExit ? state.oldProps || initialProps : initialProps;
122
+ }, [state]);
123
+ return {
124
+ state: state,
125
+ setState: setState,
126
+ getAnimationProps: getAnimationProps,
127
+ setAnimationState: setAnimationState,
128
+ getProps: getProps
129
+ };
130
+ };
@@ -0,0 +1,8 @@
1
+ import React from "react";
2
+ export var usePreviousProps = function (props) {
3
+ var ref = React.useRef();
4
+ React.useEffect(function () {
5
+ ref.current = props;
6
+ });
7
+ return ref.current || {};
8
+ };
@@ -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
+ };