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
|
@@ -1,19 +1,13 @@
|
|
|
1
|
-
var _excluded = ["desc", "children", "tabIndex", "className"];
|
|
2
|
-
|
|
3
|
-
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
|
|
4
|
-
|
|
5
|
-
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
|
6
|
-
|
|
7
1
|
import React from "react";
|
|
8
|
-
export
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
2
|
+
export const VictoryAccessibleGroup = _ref => {
|
|
3
|
+
let {
|
|
4
|
+
desc,
|
|
5
|
+
children,
|
|
6
|
+
tabIndex,
|
|
7
|
+
className = "VictoryAccessibleGroup",
|
|
8
|
+
...props
|
|
9
|
+
} = _ref;
|
|
10
|
+
const descId = desc && (props["aria-describedby"] || desc.split(" ").join("-"));
|
|
17
11
|
return desc ? /*#__PURE__*/React.createElement("g", {
|
|
18
12
|
"aria-label": props["aria-label"],
|
|
19
13
|
"aria-describedby": descId,
|
|
@@ -1,33 +1,28 @@
|
|
|
1
1
|
import _orderBy from "lodash/orderBy";
|
|
2
2
|
import _isPlainObject from "lodash/isPlainObject";
|
|
3
3
|
import { interpolate } from "victory-vendor/d3-interpolate";
|
|
4
|
-
export
|
|
4
|
+
export const isInterpolatable = function (obj) {
|
|
5
5
|
// d3 turns null into 0 and undefined into NaN, which we don't want.
|
|
6
6
|
if (obj !== null) {
|
|
7
7
|
switch (typeof obj) {
|
|
8
8
|
case "undefined":
|
|
9
9
|
return false;
|
|
10
|
-
|
|
11
10
|
case "number":
|
|
12
11
|
// The standard `isNaN` is fine in this case since we already know the
|
|
13
12
|
// type is number.
|
|
14
13
|
return !isNaN(obj) && obj !== Number.POSITIVE_INFINITY && obj !== Number.NEGATIVE_INFINITY;
|
|
15
|
-
|
|
16
14
|
case "string":
|
|
17
15
|
// d3 might not *actually* be able to interpolate the string, but it
|
|
18
16
|
// won't cause any issues to let it try.
|
|
19
17
|
return true;
|
|
20
|
-
|
|
21
18
|
case "boolean":
|
|
22
19
|
// d3 turns Booleans into integers, which we don't want. Sure, we could
|
|
23
20
|
// interpolate from 0 -> 1, but we'd be sending a non-Boolean to
|
|
24
21
|
// something expecting a Boolean.
|
|
25
22
|
return false;
|
|
26
|
-
|
|
27
23
|
case "object":
|
|
28
24
|
// Don't try to interpolate class instances (except Date or Array).
|
|
29
25
|
return obj instanceof Date || Array.isArray(obj) || _isPlainObject(obj);
|
|
30
|
-
|
|
31
26
|
case "function":
|
|
32
27
|
// Careful! There may be extra properties on function objects that the
|
|
33
28
|
// component expects to access - for instance, it may be a `d3.scale()`
|
|
@@ -42,9 +37,9 @@ export var isInterpolatable = function (obj) {
|
|
|
42
37
|
return true;
|
|
43
38
|
}
|
|
44
39
|
}
|
|
45
|
-
|
|
46
40
|
return false;
|
|
47
41
|
};
|
|
42
|
+
|
|
48
43
|
/**
|
|
49
44
|
* Interpolate immediately to the end value at the given step `when`.
|
|
50
45
|
* Some nicer default behavior might be to jump at the halfway point or return
|
|
@@ -60,13 +55,15 @@ export var isInterpolatable = function (obj) {
|
|
|
60
55
|
* @param {Number} when - Step value (0 to 1) at which to jump to `b`.
|
|
61
56
|
* @returns {Function} An interpolation function.
|
|
62
57
|
*/
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
58
|
+
export const interpolateImmediate = function (a, b, when) {
|
|
59
|
+
if (when === void 0) {
|
|
60
|
+
when = 0;
|
|
61
|
+
}
|
|
66
62
|
return function (t) {
|
|
67
63
|
return t < when ? a : b;
|
|
68
64
|
};
|
|
69
65
|
};
|
|
66
|
+
|
|
70
67
|
/**
|
|
71
68
|
* Interpolate to or from a function. The interpolated value will be a function
|
|
72
69
|
* that calls `a` (if it's a function) and `b` (if it's a function) and calls
|
|
@@ -79,21 +76,20 @@ export var interpolateImmediate = function (a, b) {
|
|
|
79
76
|
* @param {any} b - End value.
|
|
80
77
|
* @returns {Function} An interpolation function.
|
|
81
78
|
*/
|
|
82
|
-
|
|
83
|
-
export var interpolateFunction = function (a, b) {
|
|
79
|
+
export const interpolateFunction = function (a, b) {
|
|
84
80
|
return function (t) {
|
|
85
81
|
if (t >= 1) {
|
|
86
82
|
return b;
|
|
87
83
|
}
|
|
88
|
-
|
|
89
84
|
return function () {
|
|
90
85
|
/* eslint-disable no-invalid-this, prefer-rest-params */
|
|
91
|
-
|
|
92
|
-
|
|
86
|
+
const aval = typeof a === "function" ? a.apply(this, arguments) : a;
|
|
87
|
+
const bval = typeof b === "function" ? b.apply(this, arguments) : b;
|
|
93
88
|
return interpolate(aval, bval)(t);
|
|
94
89
|
};
|
|
95
90
|
};
|
|
96
91
|
};
|
|
92
|
+
|
|
97
93
|
/**
|
|
98
94
|
* Interpolate to or from an object. This method is a modification of the object interpolator in
|
|
99
95
|
* d3-interpolate https://github.com/d3/d3-interpolate/blob/master/src/object.js. This interpolator
|
|
@@ -104,44 +100,36 @@ export var interpolateFunction = function (a, b) {
|
|
|
104
100
|
* @param {any} endValue - End value.
|
|
105
101
|
* @returns {Function} An interpolation function.
|
|
106
102
|
*/
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
var interpolateTypes = function (x, y) {
|
|
103
|
+
export const interpolateObject = function (startValue, endValue) {
|
|
104
|
+
const interpolateTypes = (x, y) => {
|
|
110
105
|
if (x === y || !isInterpolatable(x) || !isInterpolatable(y)) {
|
|
111
106
|
return interpolateImmediate(x, y);
|
|
112
107
|
}
|
|
113
|
-
|
|
114
108
|
if (typeof x === "function" || typeof y === "function") {
|
|
115
109
|
return interpolateFunction(x, y);
|
|
116
110
|
}
|
|
117
|
-
|
|
118
111
|
if (typeof x === "object" && _isPlainObject(x) || typeof y === "object" && _isPlainObject(y)) {
|
|
119
112
|
return interpolateObject(x, y);
|
|
120
113
|
}
|
|
121
|
-
|
|
122
114
|
return interpolate(x, y);
|
|
123
|
-
};
|
|
124
|
-
// based on "key" instead of index
|
|
125
|
-
|
|
115
|
+
};
|
|
126
116
|
|
|
127
|
-
|
|
117
|
+
// When the value is an array, attempt to sort by "key" so that animating nodes may be identified
|
|
118
|
+
// based on "key" instead of index
|
|
119
|
+
const keyData = val => {
|
|
128
120
|
return Array.isArray(val) ? _orderBy(val, "key") : val;
|
|
129
121
|
};
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
var k;
|
|
136
|
-
|
|
122
|
+
const i = {};
|
|
123
|
+
const c = {};
|
|
124
|
+
let a = startValue;
|
|
125
|
+
let b = endValue;
|
|
126
|
+
let k;
|
|
137
127
|
if (a === null || typeof a !== "object") {
|
|
138
128
|
a = {};
|
|
139
129
|
}
|
|
140
|
-
|
|
141
130
|
if (b === null || typeof b !== "object") {
|
|
142
131
|
b = {};
|
|
143
132
|
}
|
|
144
|
-
|
|
145
133
|
for (k in b) {
|
|
146
134
|
if (k in a) {
|
|
147
135
|
i[k] = interpolateTypes(keyData(a[k]), keyData(b[k]));
|
|
@@ -149,22 +137,20 @@ export var interpolateObject = function (startValue, endValue) {
|
|
|
149
137
|
c[k] = b[k];
|
|
150
138
|
}
|
|
151
139
|
}
|
|
152
|
-
|
|
153
140
|
return function (t) {
|
|
154
141
|
for (k in i) {
|
|
155
142
|
c[k] = i[k](t);
|
|
156
143
|
}
|
|
157
|
-
|
|
158
144
|
return c;
|
|
159
145
|
};
|
|
160
146
|
};
|
|
161
|
-
export
|
|
162
|
-
|
|
147
|
+
export const interpolateString = function (a, b) {
|
|
148
|
+
const format = val => {
|
|
163
149
|
return typeof val === "string" ? val.replace(/,/g, "") : val;
|
|
164
150
|
};
|
|
165
|
-
|
|
166
151
|
return interpolate(format(a), format(b));
|
|
167
152
|
};
|
|
153
|
+
|
|
168
154
|
/**
|
|
169
155
|
* By default, the list of interpolators used by `d3.interpolate` has a few
|
|
170
156
|
* downsides:
|
|
@@ -188,28 +174,23 @@ export var interpolateString = function (a, b) {
|
|
|
188
174
|
* @param {any} b - End value.
|
|
189
175
|
* @returns {Function|undefined} An interpolation function, if necessary.
|
|
190
176
|
*/
|
|
191
|
-
|
|
192
|
-
export var victoryInterpolator = function (a, b) {
|
|
177
|
+
export const victoryInterpolator = function (a, b) {
|
|
193
178
|
// If the values are strictly equal, or either value is not interpolatable,
|
|
194
179
|
// just use either the start value `a` or end value `b` at every step, as
|
|
195
180
|
// there is no reasonable in-between value.
|
|
196
181
|
if (a === b || !isInterpolatable(a) || !isInterpolatable(b)) {
|
|
197
182
|
return interpolateImmediate(a, b);
|
|
198
183
|
}
|
|
199
|
-
|
|
200
184
|
if (typeof a === "function" || typeof b === "function") {
|
|
201
185
|
return interpolateFunction(a, b);
|
|
202
186
|
}
|
|
203
|
-
|
|
204
187
|
if (_isPlainObject(a) || _isPlainObject(b)) {
|
|
205
188
|
// @ts-expect-error These generics are tough, but they work :)
|
|
206
189
|
return interpolateObject(a, b);
|
|
207
190
|
}
|
|
208
|
-
|
|
209
191
|
if (typeof a === "string" || typeof b === "string") {
|
|
210
192
|
return interpolateString(a, b);
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
|
|
193
|
+
}
|
|
194
|
+
// @ts-expect-error These generics are tough, but they work :)
|
|
214
195
|
return interpolate(a, b);
|
|
215
196
|
};
|
|
@@ -1,73 +1,60 @@
|
|
|
1
|
-
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
2
|
-
|
|
3
|
-
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
4
|
-
|
|
5
|
-
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); }
|
|
6
|
-
|
|
7
|
-
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; }
|
|
8
|
-
|
|
9
|
-
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; }
|
|
10
|
-
|
|
11
|
-
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
12
|
-
|
|
13
1
|
import React from "react";
|
|
14
2
|
import * as d3Ease from "victory-vendor/d3-ease";
|
|
15
3
|
import { victoryInterpolator } from "./util";
|
|
16
4
|
import TimerContext from "../victory-util/timer-context";
|
|
5
|
+
|
|
17
6
|
/**
|
|
18
7
|
* Single animation object to interpolate
|
|
19
8
|
*/
|
|
20
9
|
|
|
10
|
+
/**
|
|
11
|
+
* Animation styles to interpolate
|
|
12
|
+
*/
|
|
13
|
+
|
|
21
14
|
/** d3-ease changed the naming scheme for ease from "linear" -> "easeLinear" etc. */
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
return
|
|
15
|
+
const formatAnimationName = name => {
|
|
16
|
+
const capitalizedName = name.charAt(0).toUpperCase() + name.slice(1);
|
|
17
|
+
return `ease${capitalizedName}`;
|
|
25
18
|
};
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
onEnd = _ref.onEnd;
|
|
38
|
-
|
|
39
|
-
var _React$useState = React.useState({
|
|
19
|
+
const DEFAULT_DURATION = 1000;
|
|
20
|
+
export const VictoryAnimation = _ref => {
|
|
21
|
+
let {
|
|
22
|
+
duration = DEFAULT_DURATION,
|
|
23
|
+
easing = "quadInOut",
|
|
24
|
+
delay = 0,
|
|
25
|
+
data,
|
|
26
|
+
children,
|
|
27
|
+
onEnd
|
|
28
|
+
} = _ref;
|
|
29
|
+
const [state, setState] = React.useState({
|
|
40
30
|
data: Array.isArray(data) ? data[0] : data,
|
|
41
31
|
animationInfo: {
|
|
42
32
|
progress: 0,
|
|
43
33
|
animating: false
|
|
44
34
|
}
|
|
45
|
-
})
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
var interpolator = React.useRef(null);
|
|
53
|
-
var loopID = React.useRef(undefined);
|
|
54
|
-
var ease = d3Ease[formatAnimationName(easing)];
|
|
55
|
-
React.useEffect(function () {
|
|
35
|
+
});
|
|
36
|
+
const timer = React.useContext(TimerContext).animationTimer;
|
|
37
|
+
const queue = React.useRef(Array.isArray(data) ? data.slice(1) : []);
|
|
38
|
+
const interpolator = React.useRef(null);
|
|
39
|
+
const loopID = React.useRef(undefined);
|
|
40
|
+
const ease = d3Ease[formatAnimationName(easing)];
|
|
41
|
+
React.useEffect(() => {
|
|
56
42
|
// Length check prevents us from triggering `onEnd` in `traverseQueue`.
|
|
57
43
|
if (queue.current.length) {
|
|
58
44
|
traverseQueue();
|
|
59
|
-
}
|
|
60
|
-
|
|
45
|
+
}
|
|
61
46
|
|
|
62
|
-
|
|
47
|
+
// Clean up the animation loop
|
|
48
|
+
return () => {
|
|
63
49
|
if (loopID.current) {
|
|
64
50
|
timer.unsubscribe(loopID.current);
|
|
65
51
|
} else {
|
|
66
52
|
timer.stop();
|
|
67
53
|
}
|
|
68
|
-
};
|
|
54
|
+
};
|
|
55
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
69
56
|
}, []);
|
|
70
|
-
React.useEffect(
|
|
57
|
+
React.useEffect(() => {
|
|
71
58
|
// If the previous animation didn't finish, force it to complete before starting a new one
|
|
72
59
|
if (interpolator.current && state.animationInfo && state.animationInfo.progress < 1) {
|
|
73
60
|
setState({
|
|
@@ -80,23 +67,24 @@ export var VictoryAnimation = function (_ref) {
|
|
|
80
67
|
});
|
|
81
68
|
} else {
|
|
82
69
|
// Cancel existing loop if it exists
|
|
83
|
-
timer.unsubscribe(loopID.current);
|
|
84
|
-
|
|
85
|
-
queue.current = Array.isArray(data) ? data : [data];
|
|
86
|
-
|
|
70
|
+
timer.unsubscribe(loopID.current);
|
|
71
|
+
// Set the tween queue to the new data
|
|
72
|
+
queue.current = Array.isArray(data) ? data : [data];
|
|
73
|
+
// Start traversing the tween queue
|
|
87
74
|
traverseQueue();
|
|
88
|
-
}
|
|
89
|
-
|
|
75
|
+
}
|
|
76
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
90
77
|
}, [data]);
|
|
91
|
-
|
|
92
|
-
var traverseQueue = function () {
|
|
78
|
+
const traverseQueue = () => {
|
|
93
79
|
if (queue.current.length) {
|
|
94
|
-
|
|
80
|
+
const nextData = queue.current[0];
|
|
95
81
|
|
|
96
|
-
|
|
82
|
+
// Compare cached version to next props
|
|
83
|
+
interpolator.current = victoryInterpolator(state.data, nextData);
|
|
97
84
|
|
|
85
|
+
// Reset step to zero
|
|
98
86
|
if (delay) {
|
|
99
|
-
setTimeout(
|
|
87
|
+
setTimeout(() => {
|
|
100
88
|
loopID.current = timer.subscribe(functionToBeRunEachFrame, duration);
|
|
101
89
|
}, delay);
|
|
102
90
|
} else {
|
|
@@ -106,13 +94,12 @@ export var VictoryAnimation = function (_ref) {
|
|
|
106
94
|
onEnd();
|
|
107
95
|
}
|
|
108
96
|
};
|
|
97
|
+
const functionToBeRunEachFrame = elapsed => {
|
|
98
|
+
if (!interpolator.current) return;
|
|
109
99
|
|
|
110
|
-
|
|
111
|
-
if (!interpolator.current) return; // Step can generate imprecise values, sometimes greater than 1
|
|
100
|
+
// Step can generate imprecise values, sometimes greater than 1
|
|
112
101
|
// if this happens set the state to 1 and return, cancelling the timer
|
|
113
|
-
|
|
114
|
-
var step = duration ? elapsed / duration : 1;
|
|
115
|
-
|
|
102
|
+
const step = duration ? elapsed / duration : 1;
|
|
116
103
|
if (step >= 1) {
|
|
117
104
|
setState({
|
|
118
105
|
data: interpolator.current(1),
|
|
@@ -122,19 +109,17 @@ export var VictoryAnimation = function (_ref) {
|
|
|
122
109
|
terminating: true
|
|
123
110
|
}
|
|
124
111
|
});
|
|
125
|
-
|
|
126
112
|
if (loopID.current) {
|
|
127
113
|
timer.unsubscribe(loopID.current);
|
|
128
114
|
}
|
|
129
|
-
|
|
130
115
|
queue.current.shift();
|
|
131
116
|
traverseQueue();
|
|
132
117
|
return;
|
|
133
|
-
}
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
// If we're not at the end of the timer, set the state by passing
|
|
134
121
|
// current step value that's transformed by the ease function to the
|
|
135
122
|
// interpolator, which is cached for performance whenever props are received
|
|
136
|
-
|
|
137
|
-
|
|
138
123
|
setState({
|
|
139
124
|
data: interpolator.current(ease(step)),
|
|
140
125
|
animationInfo: {
|
|
@@ -143,6 +128,5 @@ export var VictoryAnimation = function (_ref) {
|
|
|
143
128
|
}
|
|
144
129
|
});
|
|
145
130
|
};
|
|
146
|
-
|
|
147
131
|
return children(state.data, state.animationInfo);
|
|
148
132
|
};
|