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,30 +1,10 @@
|
|
|
1
1
|
import _memoize from "lodash/memoize";
|
|
2
|
-
import _defaults from "lodash/defaults";
|
|
3
|
-
|
|
4
|
-
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
5
|
-
|
|
6
|
-
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."); }
|
|
7
|
-
|
|
8
|
-
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; }
|
|
9
|
-
|
|
10
|
-
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
11
|
-
|
|
12
|
-
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
|
13
|
-
|
|
14
|
-
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
15
|
-
|
|
16
|
-
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); }
|
|
17
|
-
|
|
18
|
-
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
|
|
19
|
-
|
|
20
|
-
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
|
|
21
|
-
|
|
22
|
-
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; }
|
|
23
|
-
|
|
2
|
+
import _defaults from "lodash/defaults"; // http://www.pearsonified.com/2012/01/characters-per-line.php
|
|
3
|
+
/* eslint-disable no-magic-numbers */
|
|
24
4
|
// Based on measuring specific character widths
|
|
25
5
|
// as in the following example https://bl.ocks.org/tophtucker/62f93a4658387bb61e4510c37e2e97cf
|
|
26
6
|
// prettier-ignore
|
|
27
|
-
|
|
7
|
+
const fonts = {
|
|
28
8
|
"American Typewriter": {
|
|
29
9
|
widths: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.25, 0.4203125, 0.3296875, 0.6, 0.6375, 0.8015625, 0.8203125, 0.1875, 0.45625, 0.45625, 0.6375, 0.5, 0.2734375, 0.309375, 0.2734375, 0.4390625, 0.6375, 0.6375, 0.6375, 0.6375, 0.6375, 0.6375, 0.6375, 0.6375, 0.6375, 0.6375, 0.2734375, 0.2734375, 0.5, 0.5, 0.5, 0.6, 0.6921875, 0.7640625, 0.6921875, 0.6375, 0.728125, 0.6734375, 0.6203125, 0.7109375, 0.784375, 0.3828125, 0.6421875, 0.7859375, 0.6375, 0.9484375, 0.7640625, 0.65625, 0.6375, 0.65625, 0.7296875, 0.6203125, 0.6375, 0.7109375, 0.740625, 0.940625, 0.784375, 0.7578125, 0.6203125, 0.4375, 0.5, 0.4375, 0.5, 0.5, 0.4921875, 0.5734375, 0.5890625, 0.5109375, 0.6, 0.528125, 0.43125, 0.5578125, 0.6375, 0.3109375, 0.40625, 0.6234375, 0.309375, 0.928125, 0.6375, 0.546875, 0.6, 0.58125, 0.4921875, 0.4921875, 0.4, 0.6203125, 0.625, 0.825, 0.6375, 0.640625, 0.528125, 0.5, 0.5, 0.5, 0.6671875],
|
|
30
10
|
avg: 0.5793421052631578
|
|
@@ -129,10 +109,11 @@ var fonts = {
|
|
|
129
109
|
widths: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.35, 0.39375, 0.459375, 0.81875, 0.6359375, 1.0765625, 0.759375, 0.26875, 0.4546875, 0.4546875, 0.6359375, 0.81875, 0.3640625, 0.4546875, 0.3640625, 0.4703125, 0.6359375, 0.6359375, 0.6359375, 0.6359375, 0.6359375, 0.6359375, 0.6359375, 0.6359375, 0.6359375, 0.6359375, 0.4546875, 0.4546875, 0.81875, 0.81875, 0.81875, 0.546875, 1, 0.684375, 0.6859375, 0.6984375, 0.771875, 0.6328125, 0.575, 0.7765625, 0.7515625, 0.421875, 0.4546875, 0.69375, 0.5578125, 0.84375, 0.7484375, 0.7875, 0.603125, 0.7875, 0.7, 0.684375, 0.6171875, 0.7328125, 0.684375, 0.9890625, 0.6859375, 0.615625, 0.6859375, 0.4546875, 0.46875, 0.4546875, 0.81875, 0.6421875, 0.6359375, 0.6015625, 0.6234375, 0.521875, 0.6234375, 0.596875, 0.384375, 0.6234375, 0.6328125, 0.275, 0.3765625, 0.5921875, 0.275, 0.9734375, 0.6328125, 0.6078125, 0.6234375, 0.6234375, 0.43125, 0.521875, 0.3953125, 0.6328125, 0.5921875, 0.81875, 0.5921875, 0.5921875, 0.5265625, 0.6359375, 0.4546875, 0.6359375, 0.81875],
|
|
130
110
|
avg: 0.6171875000000003
|
|
131
111
|
}
|
|
132
|
-
};
|
|
133
|
-
// Absolute sizes in pixels for obsolete measurement units.
|
|
112
|
+
};
|
|
134
113
|
|
|
135
|
-
|
|
114
|
+
// https://developer.mozilla.org/en/docs/Web/CSS/length
|
|
115
|
+
// Absolute sizes in pixels for obsolete measurement units.
|
|
116
|
+
const absoluteMeasurementUnitsToPixels = {
|
|
136
117
|
mm: 3.8,
|
|
137
118
|
sm: 38,
|
|
138
119
|
pt: 1.33,
|
|
@@ -140,62 +121,46 @@ var absoluteMeasurementUnitsToPixels = {
|
|
|
140
121
|
in: 96,
|
|
141
122
|
px: 1
|
|
142
123
|
};
|
|
143
|
-
|
|
124
|
+
const relativeMeasurementUnitsCoef = {
|
|
144
125
|
em: 1,
|
|
145
126
|
ex: 0.5
|
|
146
127
|
};
|
|
147
|
-
|
|
128
|
+
const coefficients = {
|
|
148
129
|
heightOverlapCoef: 1.05,
|
|
149
130
|
// Coefficient for height value to prevent overlap.
|
|
150
131
|
lineCapitalCoef: 1.15 // Coefficient for height value. Reserve space for capital chars.
|
|
151
|
-
|
|
152
132
|
};
|
|
153
|
-
|
|
133
|
+
const defaultStyle = {
|
|
154
134
|
lineHeight: 1,
|
|
155
135
|
letterSpacing: "0px",
|
|
156
136
|
fontSize: 0,
|
|
157
137
|
angle: 0,
|
|
158
138
|
fontFamily: ""
|
|
159
139
|
};
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
var _getFontData = function (fontFamily) {
|
|
166
|
-
var possibleFonts = fontFamily.split(",").map(function (f) {
|
|
167
|
-
return f.replace(/'|"/g, "");
|
|
168
|
-
});
|
|
169
|
-
var fontMatch = possibleFonts.find(function (f) {
|
|
170
|
-
return fonts[f];
|
|
171
|
-
}) || "Helvetica";
|
|
140
|
+
const _degreeToRadian = angle => angle * Math.PI / 180;
|
|
141
|
+
const _getFontData = fontFamily => {
|
|
142
|
+
const possibleFonts = fontFamily.split(",").map(f => f.replace(/'|"/g, ""));
|
|
143
|
+
const fontMatch = possibleFonts.find(f => fonts[f]) || "Helvetica";
|
|
172
144
|
return fonts[fontMatch];
|
|
173
145
|
};
|
|
174
|
-
|
|
175
|
-
var _splitToLines = function (text) {
|
|
146
|
+
const _splitToLines = text => {
|
|
176
147
|
return Array.isArray(text) ? text : text.toString().split(/\r\n|\r|\n/g);
|
|
177
148
|
};
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
var angleInRadian = _degreeToRadian(angle);
|
|
181
|
-
|
|
149
|
+
const _getSizeWithRotate = (axisSize, dependentSize, angle) => {
|
|
150
|
+
const angleInRadian = _degreeToRadian(angle);
|
|
182
151
|
return Math.abs(Math.cos(angleInRadian) * axisSize) + Math.abs(Math.sin(angleInRadian) * dependentSize);
|
|
183
152
|
};
|
|
153
|
+
|
|
184
154
|
/**
|
|
185
155
|
* Convert length-type parameters from specific measurement units to pixels
|
|
186
156
|
* @param {string} length Css length string value.
|
|
187
157
|
* @param {number} fontSize Current text font-size.
|
|
188
158
|
* @returns {number} Approximate Css length in pixels.
|
|
189
159
|
*/
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
var attribute = (_length$match = length.match(/[a-zA-Z%]+/)) === null || _length$match === void 0 ? void 0 : _length$match[0];
|
|
196
|
-
var value = Number(length.match(/[0-9.,]+/));
|
|
197
|
-
var result;
|
|
198
|
-
|
|
160
|
+
export const convertLengthToPixels = (length, fontSize) => {
|
|
161
|
+
const attribute = length.match(/[a-zA-Z%]+/)?.[0];
|
|
162
|
+
const value = Number(length.match(/[0-9.,]+/));
|
|
163
|
+
let result;
|
|
199
164
|
if (!attribute) {
|
|
200
165
|
result = value || 0;
|
|
201
166
|
} else if (absoluteMeasurementUnitsToPixels.hasOwnProperty(attribute)) {
|
|
@@ -205,85 +170,66 @@ export var convertLengthToPixels = function (length, fontSize) {
|
|
|
205
170
|
} else {
|
|
206
171
|
result = value;
|
|
207
172
|
}
|
|
208
|
-
|
|
209
173
|
return result;
|
|
210
174
|
};
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
var style = _defaults({}, lineStyle, defaultStyle);
|
|
216
|
-
|
|
175
|
+
const _prepareParams = (inputStyle, index) => {
|
|
176
|
+
const lineStyle = Array.isArray(inputStyle) ? inputStyle[index] : inputStyle;
|
|
177
|
+
const style = _defaults({}, lineStyle, defaultStyle);
|
|
217
178
|
return Object.assign({}, style, {
|
|
218
179
|
fontFamily: style.fontFamily,
|
|
219
180
|
letterSpacing: typeof style.letterSpacing === "number" ? style.letterSpacing : convertLengthToPixels(String(style.letterSpacing), style.fontSize),
|
|
220
181
|
fontSize: typeof style.fontSize === "number" ? style.fontSize : convertLengthToPixels(String(style.fontSize))
|
|
221
182
|
});
|
|
222
183
|
};
|
|
223
|
-
|
|
224
|
-
var _approximateTextWidthInternal = function (text, style) {
|
|
184
|
+
const _approximateTextWidthInternal = (text, style) => {
|
|
225
185
|
if (text === undefined || text === "" || text === null) {
|
|
226
186
|
return 0;
|
|
227
187
|
}
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
var fontData = _getFontData(fontFamily);
|
|
238
|
-
|
|
239
|
-
var width = line.toString().split("").map(function (c) {
|
|
188
|
+
const widths = _splitToLines(text).map((line, index) => {
|
|
189
|
+
const len = line.toString().length;
|
|
190
|
+
const {
|
|
191
|
+
fontSize,
|
|
192
|
+
letterSpacing,
|
|
193
|
+
fontFamily
|
|
194
|
+
} = _prepareParams(style, index);
|
|
195
|
+
const fontData = _getFontData(fontFamily);
|
|
196
|
+
const width = line.toString().split("").map(c => {
|
|
240
197
|
return c.charCodeAt(0) < fontData.widths.length ? fontData.widths[c.charCodeAt(0)] : fontData.avg;
|
|
241
|
-
}).reduce(
|
|
242
|
-
return acc + cur;
|
|
243
|
-
}, 0) * fontSize;
|
|
198
|
+
}).reduce((cur, acc) => acc + cur, 0) * fontSize;
|
|
244
199
|
return width + letterSpacing * Math.max(len - 1, 0);
|
|
245
200
|
});
|
|
246
|
-
|
|
247
|
-
return Math.max.apply(Math, _toConsumableArray(widths));
|
|
201
|
+
return Math.max(...widths);
|
|
248
202
|
};
|
|
249
|
-
|
|
250
|
-
var _approximateTextHeightInternal = function (text, style) {
|
|
203
|
+
const _approximateTextHeightInternal = (text, style) => {
|
|
251
204
|
if (text === undefined || text === "" || text === null) {
|
|
252
205
|
return 0;
|
|
253
206
|
}
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
var containsCaps = line.toString().match(/[(A-Z)(0-9)]/);
|
|
259
|
-
var height = containsCaps ? lineStyle.fontSize * coefficients.lineCapitalCoef : lineStyle.fontSize;
|
|
207
|
+
return _splitToLines(text).reduce((total, line, index) => {
|
|
208
|
+
const lineStyle = _prepareParams(style, index);
|
|
209
|
+
const containsCaps = line.toString().match(/[(A-Z)(0-9)]/);
|
|
210
|
+
const height = containsCaps ? lineStyle.fontSize * coefficients.lineCapitalCoef : lineStyle.fontSize;
|
|
260
211
|
return total + lineStyle.lineHeight * height;
|
|
261
212
|
}, 0);
|
|
262
213
|
};
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
var width = _approximateTextWidthInternal(text, style);
|
|
270
|
-
|
|
271
|
-
var widthWithRotate = angle ? _getSizeWithRotate(width, height, angle) : width;
|
|
272
|
-
var heightWithRotate = angle ? _getSizeWithRotate(height, width, angle) : height;
|
|
214
|
+
const _approximateDimensionsInternal = (text, style) => {
|
|
215
|
+
const angle = Array.isArray(style) ? style[0] && style[0].angle : style && style.angle;
|
|
216
|
+
const height = _approximateTextHeightInternal(text, style);
|
|
217
|
+
const width = _approximateTextWidthInternal(text, style);
|
|
218
|
+
const widthWithRotate = angle ? _getSizeWithRotate(width, height, angle) : width;
|
|
219
|
+
const heightWithRotate = angle ? _getSizeWithRotate(height, width, angle) : height;
|
|
273
220
|
return {
|
|
274
221
|
width: widthWithRotate,
|
|
275
222
|
height: heightWithRotate * coefficients.heightOverlapCoef
|
|
276
223
|
};
|
|
277
224
|
};
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
var element = document.createElementNS("http://www.w3.org/2000/svg", "svg");
|
|
225
|
+
const _getMeasurementContainer = _memoize(() => {
|
|
226
|
+
const element = document.createElementNS("http://www.w3.org/2000/svg", "svg");
|
|
281
227
|
element.setAttribute("xlink", "http://www.w3.org/1999/xlink");
|
|
282
228
|
element.setAttribute("width", "300");
|
|
283
229
|
element.setAttribute("height", "300");
|
|
284
230
|
element.setAttribute("viewBox", "0 0 300 300");
|
|
285
231
|
element.setAttribute("aria-hidden", "true");
|
|
286
|
-
|
|
232
|
+
const containerElement = document.createElementNS("http://www.w3.org/2000/svg", "text");
|
|
287
233
|
element.appendChild(containerElement);
|
|
288
234
|
element.style.position = "fixed";
|
|
289
235
|
element.style.top = "-9999px";
|
|
@@ -291,80 +237,63 @@ var _getMeasurementContainer = _memoize(function () {
|
|
|
291
237
|
document.body.appendChild(element);
|
|
292
238
|
return containerElement;
|
|
293
239
|
});
|
|
294
|
-
|
|
295
|
-
var styleToKeyComponent = function (style) {
|
|
240
|
+
const styleToKeyComponent = style => {
|
|
296
241
|
if (!style) {
|
|
297
242
|
return "null";
|
|
298
243
|
}
|
|
299
|
-
|
|
300
|
-
return "".concat(style.angle, ":").concat(style.fontFamily, ":").concat(style.fontSize, ":").concat(style.letterSpacing, ":").concat(style.lineHeight);
|
|
244
|
+
return `${style.angle}:${style.fontFamily}:${style.fontSize}:${style.letterSpacing}:${style.lineHeight}`;
|
|
301
245
|
};
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
var containerElement = _getMeasurementContainer();
|
|
305
|
-
|
|
246
|
+
const _measureDimensionsInternal = _memoize((text, style) => {
|
|
247
|
+
let containerElement = _getMeasurementContainer();
|
|
306
248
|
if (!containerElement.isConnected) {
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
(_getMeasurementContai = (_getMeasurementContai2 = _getMeasurementContainer.cache).clear) === null || _getMeasurementContai === void 0 ? void 0 : _getMeasurementContai.call(_getMeasurementContai2);
|
|
249
|
+
_getMeasurementContainer.cache.clear?.();
|
|
310
250
|
containerElement = _getMeasurementContainer();
|
|
311
251
|
}
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
for (var _ref of lines.entries()) {
|
|
318
|
-
var _ref2 = _slicedToArray(_ref, 2);
|
|
319
|
-
|
|
320
|
-
var i = _ref2[0];
|
|
321
|
-
var line = _ref2[1];
|
|
322
|
-
var textElement = document.createElementNS("http://www.w3.org/2000/svg", "tspan");
|
|
323
|
-
|
|
324
|
-
var params = _prepareParams(style, i);
|
|
325
|
-
|
|
252
|
+
const lines = _splitToLines(text);
|
|
253
|
+
let heightAcc = 0;
|
|
254
|
+
for (const [i, line] of lines.entries()) {
|
|
255
|
+
const textElement = document.createElementNS("http://www.w3.org/2000/svg", "tspan");
|
|
256
|
+
const params = _prepareParams(style, i);
|
|
326
257
|
textElement.style.fontFamily = params.fontFamily;
|
|
327
|
-
textElement.style.fontSize =
|
|
258
|
+
textElement.style.fontSize = `${params.fontSize}px`;
|
|
328
259
|
textElement.style.lineHeight = params.lineHeight;
|
|
329
260
|
textElement.style.fontFamily = params.fontFamily;
|
|
330
261
|
textElement.style.letterSpacing = params.letterSpacing;
|
|
331
262
|
textElement.textContent = line;
|
|
332
263
|
textElement.setAttribute("x", "0");
|
|
333
|
-
textElement.setAttribute("y",
|
|
264
|
+
textElement.setAttribute("y", `${heightAcc}`);
|
|
334
265
|
containerElement.appendChild(textElement);
|
|
335
266
|
heightAcc += params.lineHeight * textElement.getBoundingClientRect().height;
|
|
336
267
|
}
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
268
|
+
const {
|
|
269
|
+
width
|
|
270
|
+
} = containerElement.getBoundingClientRect();
|
|
341
271
|
containerElement.innerHTML = "";
|
|
342
272
|
return {
|
|
343
|
-
width: style
|
|
344
|
-
height: style
|
|
273
|
+
width: style?.angle ? _getSizeWithRotate(width, heightAcc, style?.angle) : width,
|
|
274
|
+
height: style?.angle ? _getSizeWithRotate(heightAcc, width, style?.angle) : heightAcc
|
|
345
275
|
};
|
|
346
|
-
},
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
return
|
|
276
|
+
}, (text, style) => {
|
|
277
|
+
const totalText = Array.isArray(text) ? text.join() : text;
|
|
278
|
+
const totalStyle = Array.isArray(style) ? style.map(styleToKeyComponent).join() : styleToKeyComponent(style);
|
|
279
|
+
return `${totalText}::${totalStyle}`;
|
|
350
280
|
});
|
|
351
|
-
|
|
352
281
|
// Stubbable implementation.
|
|
353
|
-
export
|
|
354
|
-
impl: function (text, style) {
|
|
355
|
-
|
|
356
|
-
|
|
282
|
+
export const _approximateTextSizeInternal = {
|
|
283
|
+
impl: function (text, style, __debugForceApproximate) {
|
|
284
|
+
if (__debugForceApproximate === void 0) {
|
|
285
|
+
__debugForceApproximate = false;
|
|
286
|
+
}
|
|
357
287
|
// Attempt to first measure the element in DOM. If there is no DOM, fallback
|
|
358
288
|
// to the less accurate approximation algorithm.
|
|
359
|
-
|
|
360
|
-
|
|
289
|
+
const isClient = typeof window !== "undefined" && typeof window.document !== "undefined" && typeof window.document.createElement !== "undefined";
|
|
361
290
|
if (!isClient || __debugForceApproximate) {
|
|
362
291
|
return _approximateDimensionsInternal(text, style);
|
|
363
292
|
}
|
|
364
|
-
|
|
365
293
|
return _measureDimensionsInternal(text, style);
|
|
366
294
|
}
|
|
367
295
|
};
|
|
296
|
+
|
|
368
297
|
/**
|
|
369
298
|
* Predict text size by font params.
|
|
370
299
|
* @param {string|string[]} text Content for width calculation.
|
|
@@ -376,7 +305,4 @@ export var _approximateTextSizeInternal = {
|
|
|
376
305
|
* @param {number} style.lineHeight Line height coefficient.
|
|
377
306
|
* @returns {number} Approximate text label height.
|
|
378
307
|
*/
|
|
379
|
-
|
|
380
|
-
export var approximateTextSize = function (text, style) {
|
|
381
|
-
return _approximateTextSizeInternal.impl(text, style);
|
|
382
|
-
};
|
|
308
|
+
export const approximateTextSize = (text, style) => _approximateTextSizeInternal.impl(text, style);
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import React from "react";
|
|
2
2
|
import Timer from "./timer";
|
|
3
|
+
|
|
3
4
|
/**
|
|
4
5
|
* The React context object consumers may use to access or override the global
|
|
5
6
|
* timer.
|
|
6
7
|
*/
|
|
7
|
-
|
|
8
|
-
var TimerContext = /*#__PURE__*/React.createContext({
|
|
8
|
+
const TimerContext = /*#__PURE__*/React.createContext({
|
|
9
9
|
transitionTimer: new Timer(),
|
|
10
10
|
animationTimer: new Timer()
|
|
11
11
|
});
|
package/es/victory-util/timer.js
CHANGED
|
@@ -1,86 +1,50 @@
|
|
|
1
|
-
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
2
|
-
|
|
3
|
-
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
|
|
4
|
-
|
|
5
|
-
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
6
|
-
|
|
7
1
|
import { timer, now } from "victory-vendor/d3-timer";
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
function Timer() {
|
|
11
|
-
var _this = this;
|
|
12
|
-
|
|
13
|
-
_classCallCheck(this, Timer);
|
|
14
|
-
|
|
15
|
-
this.shouldAnimate = void 0;
|
|
16
|
-
this.subscribers = void 0;
|
|
17
|
-
this.activeSubscriptions = void 0;
|
|
18
|
-
this.timer = void 0;
|
|
19
|
-
|
|
20
|
-
this.loop = function () {
|
|
21
|
-
_this.subscribers.forEach(function (s) {
|
|
22
|
-
s.callback(now() - s.startTime, s.duration);
|
|
23
|
-
});
|
|
24
|
-
};
|
|
25
|
-
|
|
2
|
+
export default class Timer {
|
|
3
|
+
constructor() {
|
|
26
4
|
this.shouldAnimate = true;
|
|
27
5
|
this.subscribers = [];
|
|
28
6
|
this.timer = null;
|
|
29
7
|
this.activeSubscriptions = 0;
|
|
30
8
|
}
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
if (!this.timer) {
|
|
46
|
-
this.timer = timer(this.loop);
|
|
47
|
-
}
|
|
9
|
+
bypassAnimation() {
|
|
10
|
+
this.shouldAnimate = false;
|
|
11
|
+
}
|
|
12
|
+
resumeAnimation() {
|
|
13
|
+
this.shouldAnimate = true;
|
|
14
|
+
}
|
|
15
|
+
loop = () => {
|
|
16
|
+
this.subscribers.forEach(s => {
|
|
17
|
+
s.callback(now() - s.startTime, s.duration);
|
|
18
|
+
});
|
|
19
|
+
};
|
|
20
|
+
start() {
|
|
21
|
+
if (!this.timer) {
|
|
22
|
+
this.timer = timer(this.loop);
|
|
48
23
|
}
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
this.timer = null;
|
|
55
|
-
}
|
|
24
|
+
}
|
|
25
|
+
stop() {
|
|
26
|
+
if (this.timer) {
|
|
27
|
+
this.timer.stop();
|
|
28
|
+
this.timer = null;
|
|
56
29
|
}
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
30
|
+
}
|
|
31
|
+
subscribe(callback, duration) {
|
|
32
|
+
const subscriptionID = this.subscribers.push({
|
|
33
|
+
startTime: now(),
|
|
34
|
+
callback,
|
|
35
|
+
duration: this.shouldAnimate ? duration : 0
|
|
36
|
+
});
|
|
37
|
+
this.activeSubscriptions++;
|
|
38
|
+
this.start();
|
|
39
|
+
return subscriptionID;
|
|
40
|
+
}
|
|
41
|
+
unsubscribe(id) {
|
|
42
|
+
if (id !== null && this.subscribers[id - 1]) {
|
|
43
|
+
delete this.subscribers[id - 1];
|
|
44
|
+
this.activeSubscriptions--;
|
|
68
45
|
}
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
value: function unsubscribe(id) {
|
|
72
|
-
if (id !== null && this.subscribers[id - 1]) {
|
|
73
|
-
delete this.subscribers[id - 1];
|
|
74
|
-
this.activeSubscriptions--;
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
if (this.activeSubscriptions === 0) {
|
|
78
|
-
this.stop();
|
|
79
|
-
}
|
|
46
|
+
if (this.activeSubscriptions === 0) {
|
|
47
|
+
this.stop();
|
|
80
48
|
}
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
return Timer;
|
|
84
|
-
}();
|
|
85
|
-
|
|
86
|
-
export { Timer as default };
|
|
49
|
+
}
|
|
50
|
+
}
|