victory-core 36.9.2 → 37.0.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/CHANGELOG.md +6 -0
- package/dist/victory-core.js +4371 -5749
- package/dist/victory-core.min.js +1 -1
- package/es/victory-accessible-group/victory-accessible-group.js +9 -15
- package/es/victory-animation/util.js +28 -47
- package/es/victory-animation/victory-animation.js +51 -67
- package/es/victory-clip-container/victory-clip-container.js +153 -229
- package/es/victory-container/victory-container.js +157 -216
- package/es/victory-label/victory-label.js +246 -323
- package/es/victory-portal/portal-context.js +1 -2
- package/es/victory-portal/portal.js +30 -76
- package/es/victory-portal/victory-portal.js +47 -104
- package/es/victory-primitives/arc.js +44 -47
- package/es/victory-primitives/background.js +14 -17
- package/es/victory-primitives/border.js +20 -24
- package/es/victory-primitives/circle.js +13 -27
- package/es/victory-primitives/clip-path.js +3 -7
- package/es/victory-primitives/line-segment.js +20 -24
- package/es/victory-primitives/line.js +13 -27
- package/es/victory-primitives/path.js +13 -27
- package/es/victory-primitives/point.js +36 -40
- package/es/victory-primitives/rect.js +13 -27
- package/es/victory-primitives/text.js +15 -28
- package/es/victory-primitives/tspan.js +13 -26
- package/es/victory-primitives/whisker.js +43 -47
- package/es/victory-theme/grayscale.js +22 -22
- package/es/victory-theme/material.js +46 -46
- package/es/victory-theme/victory-theme.js +3 -3
- package/es/victory-transition/victory-transition.js +126 -206
- package/es/victory-util/add-events.js +263 -374
- package/es/victory-util/axis.js +126 -222
- package/es/victory-util/collection.js +13 -41
- package/es/victory-util/data.js +159 -214
- package/es/victory-util/default-transitions.js +33 -51
- package/es/victory-util/domain.js +122 -171
- package/es/victory-util/events.js +168 -258
- package/es/victory-util/helpers.js +153 -178
- package/es/victory-util/hooks/use-animation-state.js +61 -99
- package/es/victory-util/hooks/use-previous-props.js +2 -2
- package/es/victory-util/immutable.js +6 -8
- package/es/victory-util/label-helpers.js +128 -130
- package/es/victory-util/line-helpers.js +29 -41
- package/es/victory-util/log.js +1 -1
- package/es/victory-util/point-path-helpers.js +89 -49
- package/es/victory-util/scale.js +24 -42
- package/es/victory-util/selection.js +39 -40
- package/es/victory-util/style.js +8 -13
- package/es/victory-util/textsize.js +80 -154
- package/es/victory-util/timer-context.js +2 -2
- package/es/victory-util/timer.js +40 -76
- package/es/victory-util/transitions.js +110 -150
- package/es/victory-util/type-helpers.js +2 -3
- package/es/victory-util/user-props.js +24 -49
- package/es/victory-util/wrapper.js +184 -247
- package/lib/index.js +0 -30
- package/lib/victory-accessible-group/victory-accessible-group.js +9 -19
- package/lib/victory-animation/util.js +28 -63
- package/lib/victory-animation/victory-animation.js +54 -83
- package/lib/victory-clip-container/victory-clip-container.js +156 -243
- package/lib/victory-container/victory-container.js +160 -232
- package/lib/victory-label/victory-label.js +248 -344
- package/lib/victory-portal/portal-context.js +1 -6
- package/lib/victory-portal/portal.js +31 -81
- package/lib/victory-portal/victory-portal.js +50 -116
- package/lib/victory-primitives/arc.js +48 -57
- package/lib/victory-primitives/background.js +16 -28
- package/lib/victory-primitives/border.js +22 -34
- package/lib/victory-primitives/circle.js +16 -36
- package/lib/victory-primitives/clip-path.js +3 -11
- package/lib/victory-primitives/index.js +0 -28
- package/lib/victory-primitives/line-segment.js +22 -34
- package/lib/victory-primitives/line.js +16 -36
- package/lib/victory-primitives/path.js +16 -36
- package/lib/victory-primitives/point.js +38 -52
- package/lib/victory-primitives/rect.js +16 -36
- package/lib/victory-primitives/text.js +15 -33
- package/lib/victory-primitives/tspan.js +13 -31
- package/lib/victory-primitives/whisker.js +45 -57
- package/lib/victory-theme/grayscale.js +23 -24
- package/lib/victory-theme/material.js +47 -48
- package/lib/victory-theme/victory-theme.js +2 -7
- package/lib/victory-transition/victory-transition.js +129 -224
- package/lib/victory-util/add-events.js +263 -380
- package/lib/victory-util/axis.js +128 -241
- package/lib/victory-util/collection.js +13 -50
- package/lib/victory-util/data.js +160 -239
- package/lib/victory-util/default-transitions.js +33 -54
- package/lib/victory-util/domain.js +123 -193
- package/lib/victory-util/events.js +167 -274
- package/lib/victory-util/helpers.js +156 -207
- package/lib/victory-util/hooks/index.js +0 -2
- package/lib/victory-util/hooks/use-animation-state.js +63 -113
- package/lib/victory-util/hooks/use-previous-props.js +2 -7
- package/lib/victory-util/immutable.js +6 -18
- package/lib/victory-util/index.js +2 -51
- package/lib/victory-util/label-helpers.js +130 -141
- package/lib/victory-util/line-helpers.js +31 -49
- package/lib/victory-util/log.js +1 -2
- package/lib/victory-util/point-path-helpers.js +91 -63
- package/lib/victory-util/scale.js +26 -57
- package/lib/victory-util/selection.js +41 -49
- package/lib/victory-util/style.js +8 -16
- package/lib/victory-util/textsize.js +80 -157
- package/lib/victory-util/timer-context.js +2 -8
- package/lib/victory-util/timer.js +40 -76
- package/lib/victory-util/transitions.js +110 -152
- package/lib/victory-util/type-helpers.js +2 -9
- package/lib/victory-util/user-props.js +25 -59
- package/lib/victory-util/wrapper.js +186 -281
- package/package.json +2 -2
package/lib/index.js
CHANGED
|
@@ -12,9 +12,7 @@ Object.defineProperty(exports, "Box", {
|
|
|
12
12
|
return _victoryPrimitives.Border;
|
|
13
13
|
}
|
|
14
14
|
});
|
|
15
|
-
|
|
16
15
|
var _callbacks = require("./types/callbacks");
|
|
17
|
-
|
|
18
16
|
Object.keys(_callbacks).forEach(function (key) {
|
|
19
17
|
if (key === "default" || key === "__esModule") return;
|
|
20
18
|
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
@@ -26,9 +24,7 @@ Object.keys(_callbacks).forEach(function (key) {
|
|
|
26
24
|
}
|
|
27
25
|
});
|
|
28
26
|
});
|
|
29
|
-
|
|
30
27
|
var _propTypes = require("./types/prop-types");
|
|
31
|
-
|
|
32
28
|
Object.keys(_propTypes).forEach(function (key) {
|
|
33
29
|
if (key === "default" || key === "__esModule") return;
|
|
34
30
|
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
@@ -40,9 +36,7 @@ Object.keys(_propTypes).forEach(function (key) {
|
|
|
40
36
|
}
|
|
41
37
|
});
|
|
42
38
|
});
|
|
43
|
-
|
|
44
39
|
var _victoryAccessibleGroup = require("./victory-accessible-group/victory-accessible-group");
|
|
45
|
-
|
|
46
40
|
Object.keys(_victoryAccessibleGroup).forEach(function (key) {
|
|
47
41
|
if (key === "default" || key === "__esModule") return;
|
|
48
42
|
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
@@ -54,9 +48,7 @@ Object.keys(_victoryAccessibleGroup).forEach(function (key) {
|
|
|
54
48
|
}
|
|
55
49
|
});
|
|
56
50
|
});
|
|
57
|
-
|
|
58
51
|
var _victoryAnimation = require("./victory-animation/victory-animation");
|
|
59
|
-
|
|
60
52
|
Object.keys(_victoryAnimation).forEach(function (key) {
|
|
61
53
|
if (key === "default" || key === "__esModule") return;
|
|
62
54
|
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
@@ -68,9 +60,7 @@ Object.keys(_victoryAnimation).forEach(function (key) {
|
|
|
68
60
|
}
|
|
69
61
|
});
|
|
70
62
|
});
|
|
71
|
-
|
|
72
63
|
var _victoryContainer = require("./victory-container/victory-container");
|
|
73
|
-
|
|
74
64
|
Object.keys(_victoryContainer).forEach(function (key) {
|
|
75
65
|
if (key === "default" || key === "__esModule") return;
|
|
76
66
|
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
@@ -82,9 +72,7 @@ Object.keys(_victoryContainer).forEach(function (key) {
|
|
|
82
72
|
}
|
|
83
73
|
});
|
|
84
74
|
});
|
|
85
|
-
|
|
86
75
|
var _victoryLabel = require("./victory-label/victory-label");
|
|
87
|
-
|
|
88
76
|
Object.keys(_victoryLabel).forEach(function (key) {
|
|
89
77
|
if (key === "default" || key === "__esModule") return;
|
|
90
78
|
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
@@ -96,9 +84,7 @@ Object.keys(_victoryLabel).forEach(function (key) {
|
|
|
96
84
|
}
|
|
97
85
|
});
|
|
98
86
|
});
|
|
99
|
-
|
|
100
87
|
var _victoryTransition = require("./victory-transition/victory-transition");
|
|
101
|
-
|
|
102
88
|
Object.keys(_victoryTransition).forEach(function (key) {
|
|
103
89
|
if (key === "default" || key === "__esModule") return;
|
|
104
90
|
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
@@ -110,9 +96,7 @@ Object.keys(_victoryTransition).forEach(function (key) {
|
|
|
110
96
|
}
|
|
111
97
|
});
|
|
112
98
|
});
|
|
113
|
-
|
|
114
99
|
var _victoryClipContainer = require("./victory-clip-container/victory-clip-container");
|
|
115
|
-
|
|
116
100
|
Object.keys(_victoryClipContainer).forEach(function (key) {
|
|
117
101
|
if (key === "default" || key === "__esModule") return;
|
|
118
102
|
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
@@ -124,9 +108,7 @@ Object.keys(_victoryClipContainer).forEach(function (key) {
|
|
|
124
108
|
}
|
|
125
109
|
});
|
|
126
110
|
});
|
|
127
|
-
|
|
128
111
|
var _types = require("./victory-theme/types");
|
|
129
|
-
|
|
130
112
|
Object.keys(_types).forEach(function (key) {
|
|
131
113
|
if (key === "default" || key === "__esModule") return;
|
|
132
114
|
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
@@ -138,9 +120,7 @@ Object.keys(_types).forEach(function (key) {
|
|
|
138
120
|
}
|
|
139
121
|
});
|
|
140
122
|
});
|
|
141
|
-
|
|
142
123
|
var _victoryTheme = require("./victory-theme/victory-theme");
|
|
143
|
-
|
|
144
124
|
Object.keys(_victoryTheme).forEach(function (key) {
|
|
145
125
|
if (key === "default" || key === "__esModule") return;
|
|
146
126
|
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
@@ -152,9 +132,7 @@ Object.keys(_victoryTheme).forEach(function (key) {
|
|
|
152
132
|
}
|
|
153
133
|
});
|
|
154
134
|
});
|
|
155
|
-
|
|
156
135
|
var _portal = require("./victory-portal/portal");
|
|
157
|
-
|
|
158
136
|
Object.keys(_portal).forEach(function (key) {
|
|
159
137
|
if (key === "default" || key === "__esModule") return;
|
|
160
138
|
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
@@ -166,9 +144,7 @@ Object.keys(_portal).forEach(function (key) {
|
|
|
166
144
|
}
|
|
167
145
|
});
|
|
168
146
|
});
|
|
169
|
-
|
|
170
147
|
var _portalContext = require("./victory-portal/portal-context");
|
|
171
|
-
|
|
172
148
|
Object.keys(_portalContext).forEach(function (key) {
|
|
173
149
|
if (key === "default" || key === "__esModule") return;
|
|
174
150
|
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
@@ -180,9 +156,7 @@ Object.keys(_portalContext).forEach(function (key) {
|
|
|
180
156
|
}
|
|
181
157
|
});
|
|
182
158
|
});
|
|
183
|
-
|
|
184
159
|
var _victoryPortal = require("./victory-portal/victory-portal");
|
|
185
|
-
|
|
186
160
|
Object.keys(_victoryPortal).forEach(function (key) {
|
|
187
161
|
if (key === "default" || key === "__esModule") return;
|
|
188
162
|
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
@@ -194,9 +168,7 @@ Object.keys(_victoryPortal).forEach(function (key) {
|
|
|
194
168
|
}
|
|
195
169
|
});
|
|
196
170
|
});
|
|
197
|
-
|
|
198
171
|
var _victoryPrimitives = require("./victory-primitives");
|
|
199
|
-
|
|
200
172
|
Object.keys(_victoryPrimitives).forEach(function (key) {
|
|
201
173
|
if (key === "default" || key === "__esModule") return;
|
|
202
174
|
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
@@ -208,9 +180,7 @@ Object.keys(_victoryPrimitives).forEach(function (key) {
|
|
|
208
180
|
}
|
|
209
181
|
});
|
|
210
182
|
});
|
|
211
|
-
|
|
212
183
|
var _victoryUtil = require("./victory-util");
|
|
213
|
-
|
|
214
184
|
Object.keys(_victoryUtil).forEach(function (key) {
|
|
215
185
|
if (key === "default" || key === "__esModule") return;
|
|
216
186
|
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
@@ -4,26 +4,17 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.VictoryAccessibleGroup = void 0;
|
|
7
|
-
|
|
8
7
|
var _react = _interopRequireDefault(require("react"));
|
|
9
|
-
|
|
10
|
-
var _excluded = ["desc", "children", "tabIndex", "className"];
|
|
11
|
-
|
|
12
8
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
_ref$className = _ref.className,
|
|
23
|
-
className = _ref$className === void 0 ? "VictoryAccessibleGroup" : _ref$className,
|
|
24
|
-
props = _objectWithoutProperties(_ref, _excluded);
|
|
25
|
-
|
|
26
|
-
var descId = desc && (props["aria-describedby"] || desc.split(" ").join("-"));
|
|
9
|
+
const VictoryAccessibleGroup = _ref => {
|
|
10
|
+
let {
|
|
11
|
+
desc,
|
|
12
|
+
children,
|
|
13
|
+
tabIndex,
|
|
14
|
+
className = "VictoryAccessibleGroup",
|
|
15
|
+
...props
|
|
16
|
+
} = _ref;
|
|
17
|
+
const descId = desc && (props["aria-describedby"] || desc.split(" ").join("-"));
|
|
27
18
|
return desc ? /*#__PURE__*/_react.default.createElement("g", {
|
|
28
19
|
"aria-label": props["aria-label"],
|
|
29
20
|
"aria-describedby": descId,
|
|
@@ -38,5 +29,4 @@ var VictoryAccessibleGroup = function (_ref) {
|
|
|
38
29
|
tabIndex: tabIndex
|
|
39
30
|
}, children);
|
|
40
31
|
};
|
|
41
|
-
|
|
42
32
|
exports.VictoryAccessibleGroup = VictoryAccessibleGroup;
|
|
@@ -4,42 +4,32 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.victoryInterpolator = exports.isInterpolatable = exports.interpolateString = exports.interpolateObject = exports.interpolateImmediate = exports.interpolateFunction = void 0;
|
|
7
|
-
|
|
8
7
|
var _orderBy2 = _interopRequireDefault(require("lodash/orderBy"));
|
|
9
|
-
|
|
10
8
|
var _isPlainObject2 = _interopRequireDefault(require("lodash/isPlainObject"));
|
|
11
|
-
|
|
12
9
|
var _d3Interpolate = require("victory-vendor/d3-interpolate");
|
|
13
|
-
|
|
14
10
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
15
|
-
|
|
16
|
-
var isInterpolatable = function (obj) {
|
|
11
|
+
const isInterpolatable = function (obj) {
|
|
17
12
|
// d3 turns null into 0 and undefined into NaN, which we don't want.
|
|
18
13
|
if (obj !== null) {
|
|
19
14
|
switch (typeof obj) {
|
|
20
15
|
case "undefined":
|
|
21
16
|
return false;
|
|
22
|
-
|
|
23
17
|
case "number":
|
|
24
18
|
// The standard `isNaN` is fine in this case since we already know the
|
|
25
19
|
// type is number.
|
|
26
20
|
return !isNaN(obj) && obj !== Number.POSITIVE_INFINITY && obj !== Number.NEGATIVE_INFINITY;
|
|
27
|
-
|
|
28
21
|
case "string":
|
|
29
22
|
// d3 might not *actually* be able to interpolate the string, but it
|
|
30
23
|
// won't cause any issues to let it try.
|
|
31
24
|
return true;
|
|
32
|
-
|
|
33
25
|
case "boolean":
|
|
34
26
|
// d3 turns Booleans into integers, which we don't want. Sure, we could
|
|
35
27
|
// interpolate from 0 -> 1, but we'd be sending a non-Boolean to
|
|
36
28
|
// something expecting a Boolean.
|
|
37
29
|
return false;
|
|
38
|
-
|
|
39
30
|
case "object":
|
|
40
31
|
// Don't try to interpolate class instances (except Date or Array).
|
|
41
32
|
return obj instanceof Date || Array.isArray(obj) || (0, _isPlainObject2.default)(obj);
|
|
42
|
-
|
|
43
33
|
case "function":
|
|
44
34
|
// Careful! There may be extra properties on function objects that the
|
|
45
35
|
// component expects to access - for instance, it may be a `d3.scale()`
|
|
@@ -54,9 +44,9 @@ var isInterpolatable = function (obj) {
|
|
|
54
44
|
return true;
|
|
55
45
|
}
|
|
56
46
|
}
|
|
57
|
-
|
|
58
47
|
return false;
|
|
59
48
|
};
|
|
49
|
+
|
|
60
50
|
/**
|
|
61
51
|
* Interpolate immediately to the end value at the given step `when`.
|
|
62
52
|
* Some nicer default behavior might be to jump at the halfway point or return
|
|
@@ -72,16 +62,16 @@ var isInterpolatable = function (obj) {
|
|
|
72
62
|
* @param {Number} when - Step value (0 to 1) at which to jump to `b`.
|
|
73
63
|
* @returns {Function} An interpolation function.
|
|
74
64
|
*/
|
|
75
|
-
|
|
76
|
-
|
|
77
65
|
exports.isInterpolatable = isInterpolatable;
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
66
|
+
const interpolateImmediate = function (a, b, when) {
|
|
67
|
+
if (when === void 0) {
|
|
68
|
+
when = 0;
|
|
69
|
+
}
|
|
81
70
|
return function (t) {
|
|
82
71
|
return t < when ? a : b;
|
|
83
72
|
};
|
|
84
73
|
};
|
|
74
|
+
|
|
85
75
|
/**
|
|
86
76
|
* Interpolate to or from a function. The interpolated value will be a function
|
|
87
77
|
* that calls `a` (if it's a function) and `b` (if it's a function) and calls
|
|
@@ -94,24 +84,21 @@ var interpolateImmediate = function (a, b) {
|
|
|
94
84
|
* @param {any} b - End value.
|
|
95
85
|
* @returns {Function} An interpolation function.
|
|
96
86
|
*/
|
|
97
|
-
|
|
98
|
-
|
|
99
87
|
exports.interpolateImmediate = interpolateImmediate;
|
|
100
|
-
|
|
101
|
-
var interpolateFunction = function (a, b) {
|
|
88
|
+
const interpolateFunction = function (a, b) {
|
|
102
89
|
return function (t) {
|
|
103
90
|
if (t >= 1) {
|
|
104
91
|
return b;
|
|
105
92
|
}
|
|
106
|
-
|
|
107
93
|
return function () {
|
|
108
94
|
/* eslint-disable no-invalid-this, prefer-rest-params */
|
|
109
|
-
|
|
110
|
-
|
|
95
|
+
const aval = typeof a === "function" ? a.apply(this, arguments) : a;
|
|
96
|
+
const bval = typeof b === "function" ? b.apply(this, arguments) : b;
|
|
111
97
|
return (0, _d3Interpolate.interpolate)(aval, bval)(t);
|
|
112
98
|
};
|
|
113
99
|
};
|
|
114
100
|
};
|
|
101
|
+
|
|
115
102
|
/**
|
|
116
103
|
* Interpolate to or from an object. This method is a modification of the object interpolator in
|
|
117
104
|
* d3-interpolate https://github.com/d3/d3-interpolate/blob/master/src/object.js. This interpolator
|
|
@@ -122,47 +109,37 @@ var interpolateFunction = function (a, b) {
|
|
|
122
109
|
* @param {any} endValue - End value.
|
|
123
110
|
* @returns {Function} An interpolation function.
|
|
124
111
|
*/
|
|
125
|
-
|
|
126
|
-
|
|
127
112
|
exports.interpolateFunction = interpolateFunction;
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
var interpolateTypes = function (x, y) {
|
|
113
|
+
const interpolateObject = function (startValue, endValue) {
|
|
114
|
+
const interpolateTypes = (x, y) => {
|
|
131
115
|
if (x === y || !isInterpolatable(x) || !isInterpolatable(y)) {
|
|
132
116
|
return interpolateImmediate(x, y);
|
|
133
117
|
}
|
|
134
|
-
|
|
135
118
|
if (typeof x === "function" || typeof y === "function") {
|
|
136
119
|
return interpolateFunction(x, y);
|
|
137
120
|
}
|
|
138
|
-
|
|
139
121
|
if (typeof x === "object" && (0, _isPlainObject2.default)(x) || typeof y === "object" && (0, _isPlainObject2.default)(y)) {
|
|
140
122
|
return interpolateObject(x, y);
|
|
141
123
|
}
|
|
142
|
-
|
|
143
124
|
return (0, _d3Interpolate.interpolate)(x, y);
|
|
144
|
-
};
|
|
145
|
-
// based on "key" instead of index
|
|
146
|
-
|
|
125
|
+
};
|
|
147
126
|
|
|
148
|
-
|
|
127
|
+
// When the value is an array, attempt to sort by "key" so that animating nodes may be identified
|
|
128
|
+
// based on "key" instead of index
|
|
129
|
+
const keyData = val => {
|
|
149
130
|
return Array.isArray(val) ? (0, _orderBy2.default)(val, "key") : val;
|
|
150
131
|
};
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
var k;
|
|
157
|
-
|
|
132
|
+
const i = {};
|
|
133
|
+
const c = {};
|
|
134
|
+
let a = startValue;
|
|
135
|
+
let b = endValue;
|
|
136
|
+
let k;
|
|
158
137
|
if (a === null || typeof a !== "object") {
|
|
159
138
|
a = {};
|
|
160
139
|
}
|
|
161
|
-
|
|
162
140
|
if (b === null || typeof b !== "object") {
|
|
163
141
|
b = {};
|
|
164
142
|
}
|
|
165
|
-
|
|
166
143
|
for (k in b) {
|
|
167
144
|
if (k in a) {
|
|
168
145
|
i[k] = interpolateTypes(keyData(a[k]), keyData(b[k]));
|
|
@@ -170,25 +147,21 @@ var interpolateObject = function (startValue, endValue) {
|
|
|
170
147
|
c[k] = b[k];
|
|
171
148
|
}
|
|
172
149
|
}
|
|
173
|
-
|
|
174
150
|
return function (t) {
|
|
175
151
|
for (k in i) {
|
|
176
152
|
c[k] = i[k](t);
|
|
177
153
|
}
|
|
178
|
-
|
|
179
154
|
return c;
|
|
180
155
|
};
|
|
181
156
|
};
|
|
182
|
-
|
|
183
157
|
exports.interpolateObject = interpolateObject;
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
var format = function (val) {
|
|
158
|
+
const interpolateString = function (a, b) {
|
|
159
|
+
const format = val => {
|
|
187
160
|
return typeof val === "string" ? val.replace(/,/g, "") : val;
|
|
188
161
|
};
|
|
189
|
-
|
|
190
162
|
return (0, _d3Interpolate.interpolate)(format(a), format(b));
|
|
191
163
|
};
|
|
164
|
+
|
|
192
165
|
/**
|
|
193
166
|
* By default, the list of interpolators used by `d3.interpolate` has a few
|
|
194
167
|
* downsides:
|
|
@@ -212,33 +185,25 @@ var interpolateString = function (a, b) {
|
|
|
212
185
|
* @param {any} b - End value.
|
|
213
186
|
* @returns {Function|undefined} An interpolation function, if necessary.
|
|
214
187
|
*/
|
|
215
|
-
|
|
216
|
-
|
|
217
188
|
exports.interpolateString = interpolateString;
|
|
218
|
-
|
|
219
|
-
var victoryInterpolator = function (a, b) {
|
|
189
|
+
const victoryInterpolator = function (a, b) {
|
|
220
190
|
// If the values are strictly equal, or either value is not interpolatable,
|
|
221
191
|
// just use either the start value `a` or end value `b` at every step, as
|
|
222
192
|
// there is no reasonable in-between value.
|
|
223
193
|
if (a === b || !isInterpolatable(a) || !isInterpolatable(b)) {
|
|
224
194
|
return interpolateImmediate(a, b);
|
|
225
195
|
}
|
|
226
|
-
|
|
227
196
|
if (typeof a === "function" || typeof b === "function") {
|
|
228
197
|
return interpolateFunction(a, b);
|
|
229
198
|
}
|
|
230
|
-
|
|
231
199
|
if ((0, _isPlainObject2.default)(a) || (0, _isPlainObject2.default)(b)) {
|
|
232
200
|
// @ts-expect-error These generics are tough, but they work :)
|
|
233
201
|
return interpolateObject(a, b);
|
|
234
202
|
}
|
|
235
|
-
|
|
236
203
|
if (typeof a === "string" || typeof b === "string") {
|
|
237
204
|
return interpolateString(a, b);
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
|
|
205
|
+
}
|
|
206
|
+
// @ts-expect-error These generics are tough, but they work :)
|
|
241
207
|
return (0, _d3Interpolate.interpolate)(a, b);
|
|
242
208
|
};
|
|
243
|
-
|
|
244
209
|
exports.victoryInterpolator = victoryInterpolator;
|
|
@@ -4,90 +4,65 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.VictoryAnimation = void 0;
|
|
7
|
-
|
|
8
7
|
var _react = _interopRequireDefault(require("react"));
|
|
9
|
-
|
|
10
8
|
var d3Ease = _interopRequireWildcard(require("victory-vendor/d3-ease"));
|
|
11
|
-
|
|
12
9
|
var _util = require("./util");
|
|
13
|
-
|
|
14
10
|
var _timerContext = _interopRequireDefault(require("../victory-util/timer-context"));
|
|
15
|
-
|
|
16
|
-
function
|
|
17
|
-
|
|
18
|
-
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
19
|
-
|
|
11
|
+
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
12
|
+
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
20
13
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
14
|
+
/**
|
|
15
|
+
* Single animation object to interpolate
|
|
16
|
+
*/
|
|
21
17
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
27
|
-
|
|
28
|
-
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
|
|
29
|
-
|
|
30
|
-
function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_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; }
|
|
31
|
-
|
|
32
|
-
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
18
|
+
/**
|
|
19
|
+
* Animation styles to interpolate
|
|
20
|
+
*/
|
|
33
21
|
|
|
34
22
|
/** d3-ease changed the naming scheme for ease from "linear" -> "easeLinear" etc. */
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
return
|
|
23
|
+
const formatAnimationName = name => {
|
|
24
|
+
const capitalizedName = name.charAt(0).toUpperCase() + name.slice(1);
|
|
25
|
+
return `ease${capitalizedName}`;
|
|
38
26
|
};
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
children = _ref.children,
|
|
51
|
-
onEnd = _ref.onEnd;
|
|
52
|
-
|
|
53
|
-
var _React$useState = _react.default.useState({
|
|
27
|
+
const DEFAULT_DURATION = 1000;
|
|
28
|
+
const VictoryAnimation = _ref => {
|
|
29
|
+
let {
|
|
30
|
+
duration = DEFAULT_DURATION,
|
|
31
|
+
easing = "quadInOut",
|
|
32
|
+
delay = 0,
|
|
33
|
+
data,
|
|
34
|
+
children,
|
|
35
|
+
onEnd
|
|
36
|
+
} = _ref;
|
|
37
|
+
const [state, setState] = _react.default.useState({
|
|
54
38
|
data: Array.isArray(data) ? data[0] : data,
|
|
55
39
|
animationInfo: {
|
|
56
40
|
progress: 0,
|
|
57
41
|
animating: false
|
|
58
42
|
}
|
|
59
|
-
})
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
var queue = _react.default.useRef(Array.isArray(data) ? data.slice(1) : []);
|
|
67
|
-
|
|
68
|
-
var interpolator = _react.default.useRef(null);
|
|
69
|
-
|
|
70
|
-
var loopID = _react.default.useRef(undefined);
|
|
71
|
-
|
|
72
|
-
var ease = d3Ease[formatAnimationName(easing)];
|
|
73
|
-
|
|
74
|
-
_react.default.useEffect(function () {
|
|
43
|
+
});
|
|
44
|
+
const timer = _react.default.useContext(_timerContext.default).animationTimer;
|
|
45
|
+
const queue = _react.default.useRef(Array.isArray(data) ? data.slice(1) : []);
|
|
46
|
+
const interpolator = _react.default.useRef(null);
|
|
47
|
+
const loopID = _react.default.useRef(undefined);
|
|
48
|
+
const ease = d3Ease[formatAnimationName(easing)];
|
|
49
|
+
_react.default.useEffect(() => {
|
|
75
50
|
// Length check prevents us from triggering `onEnd` in `traverseQueue`.
|
|
76
51
|
if (queue.current.length) {
|
|
77
52
|
traverseQueue();
|
|
78
|
-
}
|
|
79
|
-
|
|
53
|
+
}
|
|
80
54
|
|
|
81
|
-
|
|
55
|
+
// Clean up the animation loop
|
|
56
|
+
return () => {
|
|
82
57
|
if (loopID.current) {
|
|
83
58
|
timer.unsubscribe(loopID.current);
|
|
84
59
|
} else {
|
|
85
60
|
timer.stop();
|
|
86
61
|
}
|
|
87
|
-
};
|
|
62
|
+
};
|
|
63
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
88
64
|
}, []);
|
|
89
|
-
|
|
90
|
-
_react.default.useEffect(function () {
|
|
65
|
+
_react.default.useEffect(() => {
|
|
91
66
|
// If the previous animation didn't finish, force it to complete before starting a new one
|
|
92
67
|
if (interpolator.current && state.animationInfo && state.animationInfo.progress < 1) {
|
|
93
68
|
setState({
|
|
@@ -100,23 +75,24 @@ var VictoryAnimation = function (_ref) {
|
|
|
100
75
|
});
|
|
101
76
|
} else {
|
|
102
77
|
// Cancel existing loop if it exists
|
|
103
|
-
timer.unsubscribe(loopID.current);
|
|
104
|
-
|
|
105
|
-
queue.current = Array.isArray(data) ? data : [data];
|
|
106
|
-
|
|
78
|
+
timer.unsubscribe(loopID.current);
|
|
79
|
+
// Set the tween queue to the new data
|
|
80
|
+
queue.current = Array.isArray(data) ? data : [data];
|
|
81
|
+
// Start traversing the tween queue
|
|
107
82
|
traverseQueue();
|
|
108
|
-
}
|
|
109
|
-
|
|
83
|
+
}
|
|
84
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
110
85
|
}, [data]);
|
|
111
|
-
|
|
112
|
-
var traverseQueue = function () {
|
|
86
|
+
const traverseQueue = () => {
|
|
113
87
|
if (queue.current.length) {
|
|
114
|
-
|
|
88
|
+
const nextData = queue.current[0];
|
|
115
89
|
|
|
116
|
-
|
|
90
|
+
// Compare cached version to next props
|
|
91
|
+
interpolator.current = (0, _util.victoryInterpolator)(state.data, nextData);
|
|
117
92
|
|
|
93
|
+
// Reset step to zero
|
|
118
94
|
if (delay) {
|
|
119
|
-
setTimeout(
|
|
95
|
+
setTimeout(() => {
|
|
120
96
|
loopID.current = timer.subscribe(functionToBeRunEachFrame, duration);
|
|
121
97
|
}, delay);
|
|
122
98
|
} else {
|
|
@@ -126,13 +102,12 @@ var VictoryAnimation = function (_ref) {
|
|
|
126
102
|
onEnd();
|
|
127
103
|
}
|
|
128
104
|
};
|
|
105
|
+
const functionToBeRunEachFrame = elapsed => {
|
|
106
|
+
if (!interpolator.current) return;
|
|
129
107
|
|
|
130
|
-
|
|
131
|
-
if (!interpolator.current) return; // Step can generate imprecise values, sometimes greater than 1
|
|
108
|
+
// Step can generate imprecise values, sometimes greater than 1
|
|
132
109
|
// if this happens set the state to 1 and return, cancelling the timer
|
|
133
|
-
|
|
134
|
-
var step = duration ? elapsed / duration : 1;
|
|
135
|
-
|
|
110
|
+
const step = duration ? elapsed / duration : 1;
|
|
136
111
|
if (step >= 1) {
|
|
137
112
|
setState({
|
|
138
113
|
data: interpolator.current(1),
|
|
@@ -142,19 +117,17 @@ var VictoryAnimation = function (_ref) {
|
|
|
142
117
|
terminating: true
|
|
143
118
|
}
|
|
144
119
|
});
|
|
145
|
-
|
|
146
120
|
if (loopID.current) {
|
|
147
121
|
timer.unsubscribe(loopID.current);
|
|
148
122
|
}
|
|
149
|
-
|
|
150
123
|
queue.current.shift();
|
|
151
124
|
traverseQueue();
|
|
152
125
|
return;
|
|
153
|
-
}
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
// If we're not at the end of the timer, set the state by passing
|
|
154
129
|
// current step value that's transformed by the ease function to the
|
|
155
130
|
// interpolator, which is cached for performance whenever props are received
|
|
156
|
-
|
|
157
|
-
|
|
158
131
|
setState({
|
|
159
132
|
data: interpolator.current(ease(step)),
|
|
160
133
|
animationInfo: {
|
|
@@ -163,8 +136,6 @@ var VictoryAnimation = function (_ref) {
|
|
|
163
136
|
}
|
|
164
137
|
});
|
|
165
138
|
};
|
|
166
|
-
|
|
167
139
|
return children(state.data, state.animationInfo);
|
|
168
140
|
};
|
|
169
|
-
|
|
170
141
|
exports.VictoryAnimation = VictoryAnimation;
|