victory-core 36.6.7 → 36.6.10

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.
@@ -144,5 +144,5 @@ export function useVictoryProviderSync(props) {
144
144
 
145
145
  React.useEffect(function () {
146
146
  updateChildProps(myId, props);
147
- }, [updateChildProps, props]);
147
+ }, [updateChildProps, props, myId]);
148
148
  }
@@ -7,14 +7,13 @@
7
7
  export declare const convertLengthToPixels: (length: string, fontSize?: number) => number;
8
8
  export interface TextSizeStyleInterface {
9
9
  angle?: number;
10
- characterConstant?: string;
11
10
  fontFamily?: string;
12
11
  fontSize?: number | string;
13
12
  letterSpacing?: string;
14
13
  lineHeight?: number;
15
14
  }
16
15
  export declare const _approximateTextSizeInternal: {
17
- impl: (text: string | string[], style?: TextSizeStyleInterface) => {
16
+ impl: (text: string | string[], style?: TextSizeStyleInterface, __debugForceApproximate?: boolean) => {
18
17
  width: number;
19
18
  height: number;
20
19
  };
@@ -1,6 +1,15 @@
1
+ import _memoize from "lodash/memoize";
1
2
  import _defaults from "lodash/defaults";
2
3
  import _assign from "lodash/assign";
3
4
 
5
+ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
6
+
7
+ 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."); }
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
+
4
13
  function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
5
14
 
6
15
  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."); }
@@ -253,21 +262,99 @@ var _approximateTextHeightInternal = function (text, style) {
253
262
  }, 0);
254
263
  };
255
264
 
265
+ var _approximateDimensionsInternal = function (text, style) {
266
+ var angle = Array.isArray(style) ? style[0] && style[0].angle : style && style.angle;
267
+
268
+ var height = _approximateTextHeightInternal(text, style);
269
+
270
+ var width = _approximateTextWidthInternal(text, style);
271
+
272
+ var widthWithRotate = angle ? _getSizeWithRotate(width, height, angle) : width;
273
+ var heightWithRotate = angle ? _getSizeWithRotate(height, width, angle) : height;
274
+ return {
275
+ width: widthWithRotate,
276
+ height: heightWithRotate * coefficients.heightOverlapCoef
277
+ };
278
+ };
279
+
280
+ var _getMeasurementContainer = _memoize(function () {
281
+ var element = document.createElementNS("http://www.w3.org/2000/svg", "svg");
282
+ element.setAttribute("xlink", "http://www.w3.org/1999/xlink");
283
+ var containerElement = document.createElementNS("http://www.w3.org/2000/svg", "text");
284
+ element.appendChild(containerElement);
285
+ element.style.position = "fixed";
286
+ element.style.top = "-9999px";
287
+ element.style.left = "-9999px";
288
+ document.body.appendChild(element);
289
+ return containerElement;
290
+ });
291
+
292
+ var styleToKeyComponent = function (style) {
293
+ if (!style) {
294
+ return "null";
295
+ }
296
+
297
+ return "".concat(style.angle, ":").concat(style.fontFamily, ":").concat(style.fontSize, ":").concat(style.letterSpacing, ":").concat(style.lineHeight);
298
+ };
299
+
300
+ var _measureDimensionsInternal = _memoize(function (text, style) {
301
+ var containerElement = _getMeasurementContainer();
302
+
303
+ var lines = _splitToLines(text);
304
+
305
+ var heightAcc = 0;
306
+
307
+ for (var _ref of lines.entries()) {
308
+ var _ref2 = _slicedToArray(_ref, 2);
309
+
310
+ var i = _ref2[0];
311
+ var line = _ref2[1];
312
+ var textElement = document.createElementNS("http://www.w3.org/2000/svg", "tspan");
313
+
314
+ var params = _prepareParams(style, i);
315
+
316
+ textElement.style.fontFamily = params.fontFamily;
317
+ textElement.style.transform = "rotate(".concat(params.angle, ")");
318
+ textElement.style.fontSize = "".concat(params.fontSize, "px");
319
+ textElement.style.lineHeight = params.lineHeight;
320
+ textElement.style.fontFamily = params.fontFamily;
321
+ textElement.style.letterSpacing = params.letterSpacing;
322
+ textElement.textContent = line;
323
+ textElement.setAttribute("x", "0");
324
+ textElement.setAttribute("y", "".concat(heightAcc));
325
+ heightAcc += params.lineHeight * params.fontSize;
326
+ containerElement.appendChild(textElement);
327
+ }
328
+
329
+ var _containerElement$get = containerElement.getBoundingClientRect(),
330
+ width = _containerElement$get.width,
331
+ height = _containerElement$get.height;
332
+
333
+ containerElement.innerHTML = "";
334
+ return {
335
+ width: width,
336
+ height: height
337
+ };
338
+ }, function (text, style) {
339
+ var totalText = Array.isArray(text) ? text.join() : text;
340
+ var totalStyle = Array.isArray(style) ? style.map(styleToKeyComponent).join() : styleToKeyComponent(style);
341
+ return "".concat(totalText, "::").concat(totalStyle);
342
+ });
343
+
256
344
  // Stubbable implementation.
257
345
  export var _approximateTextSizeInternal = {
258
346
  impl: function (text, style) {
259
- var angle = Array.isArray(style) ? style[0] && style[0].angle : style && style.angle;
347
+ var __debugForceApproximate = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
260
348
 
261
- var height = _approximateTextHeightInternal(text, style);
349
+ // Attempt to first measure the element in DOM. If there is no DOM, fallback
350
+ // to the less accurate approximation algorithm.
351
+ var isClient = typeof window !== "undefined" && typeof window.document !== "undefined" && typeof window.document.createElement !== "undefined";
262
352
 
263
- var width = _approximateTextWidthInternal(text, style);
353
+ if (!isClient || __debugForceApproximate) {
354
+ return _approximateDimensionsInternal(text, style);
355
+ }
264
356
 
265
- var widthWithRotate = angle ? _getSizeWithRotate(width, height, angle) : width;
266
- var heightWithRotate = angle ? _getSizeWithRotate(height, width, angle) : height;
267
- return {
268
- width: widthWithRotate,
269
- height: heightWithRotate * coefficients.heightOverlapCoef
270
- };
357
+ return _measureDimensionsInternal(text, style);
271
358
  }
272
359
  };
273
360
  /**
@@ -171,5 +171,5 @@ function useVictoryProviderSync(props) {
171
171
 
172
172
  React.useEffect(function () {
173
173
  updateChildProps(myId, props);
174
- }, [updateChildProps, props]);
174
+ }, [updateChildProps, props, myId]);
175
175
  }
@@ -7,14 +7,13 @@
7
7
  export declare const convertLengthToPixels: (length: string, fontSize?: number) => number;
8
8
  export interface TextSizeStyleInterface {
9
9
  angle?: number;
10
- characterConstant?: string;
11
10
  fontFamily?: string;
12
11
  fontSize?: number | string;
13
12
  letterSpacing?: string;
14
13
  lineHeight?: number;
15
14
  }
16
15
  export declare const _approximateTextSizeInternal: {
17
- impl: (text: string | string[], style?: TextSizeStyleInterface) => {
16
+ impl: (text: string | string[], style?: TextSizeStyleInterface, __debugForceApproximate?: boolean) => {
18
17
  width: number;
19
18
  height: number;
20
19
  };
@@ -5,12 +5,22 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.convertLengthToPixels = exports.approximateTextSize = exports._approximateTextSizeInternal = void 0;
7
7
 
8
+ var _memoize2 = _interopRequireDefault(require("lodash/memoize"));
9
+
8
10
  var _defaults2 = _interopRequireDefault(require("lodash/defaults"));
9
11
 
10
12
  var _assign2 = _interopRequireDefault(require("lodash/assign"));
11
13
 
12
14
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
13
15
 
16
+ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
17
+
18
+ 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."); }
19
+
20
+ 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; }
21
+
22
+ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
23
+
14
24
  function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
15
25
 
16
26
  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."); }
@@ -263,21 +273,99 @@ var _approximateTextHeightInternal = function (text, style) {
263
273
  }, 0);
264
274
  };
265
275
 
276
+ var _approximateDimensionsInternal = function (text, style) {
277
+ var angle = Array.isArray(style) ? style[0] && style[0].angle : style && style.angle;
278
+
279
+ var height = _approximateTextHeightInternal(text, style);
280
+
281
+ var width = _approximateTextWidthInternal(text, style);
282
+
283
+ var widthWithRotate = angle ? _getSizeWithRotate(width, height, angle) : width;
284
+ var heightWithRotate = angle ? _getSizeWithRotate(height, width, angle) : height;
285
+ return {
286
+ width: widthWithRotate,
287
+ height: heightWithRotate * coefficients.heightOverlapCoef
288
+ };
289
+ };
290
+
291
+ var _getMeasurementContainer = (0, _memoize2.default)(function () {
292
+ var element = document.createElementNS("http://www.w3.org/2000/svg", "svg");
293
+ element.setAttribute("xlink", "http://www.w3.org/1999/xlink");
294
+ var containerElement = document.createElementNS("http://www.w3.org/2000/svg", "text");
295
+ element.appendChild(containerElement);
296
+ element.style.position = "fixed";
297
+ element.style.top = "-9999px";
298
+ element.style.left = "-9999px";
299
+ document.body.appendChild(element);
300
+ return containerElement;
301
+ });
302
+
303
+ var styleToKeyComponent = function (style) {
304
+ if (!style) {
305
+ return "null";
306
+ }
307
+
308
+ return "".concat(style.angle, ":").concat(style.fontFamily, ":").concat(style.fontSize, ":").concat(style.letterSpacing, ":").concat(style.lineHeight);
309
+ };
310
+
311
+ var _measureDimensionsInternal = (0, _memoize2.default)(function (text, style) {
312
+ var containerElement = _getMeasurementContainer();
313
+
314
+ var lines = _splitToLines(text);
315
+
316
+ var heightAcc = 0;
317
+
318
+ for (var _ref of lines.entries()) {
319
+ var _ref2 = _slicedToArray(_ref, 2);
320
+
321
+ var i = _ref2[0];
322
+ var line = _ref2[1];
323
+ var textElement = document.createElementNS("http://www.w3.org/2000/svg", "tspan");
324
+
325
+ var params = _prepareParams(style, i);
326
+
327
+ textElement.style.fontFamily = params.fontFamily;
328
+ textElement.style.transform = "rotate(".concat(params.angle, ")");
329
+ textElement.style.fontSize = "".concat(params.fontSize, "px");
330
+ textElement.style.lineHeight = params.lineHeight;
331
+ textElement.style.fontFamily = params.fontFamily;
332
+ textElement.style.letterSpacing = params.letterSpacing;
333
+ textElement.textContent = line;
334
+ textElement.setAttribute("x", "0");
335
+ textElement.setAttribute("y", "".concat(heightAcc));
336
+ heightAcc += params.lineHeight * params.fontSize;
337
+ containerElement.appendChild(textElement);
338
+ }
339
+
340
+ var _containerElement$get = containerElement.getBoundingClientRect(),
341
+ width = _containerElement$get.width,
342
+ height = _containerElement$get.height;
343
+
344
+ containerElement.innerHTML = "";
345
+ return {
346
+ width: width,
347
+ height: height
348
+ };
349
+ }, function (text, style) {
350
+ var totalText = Array.isArray(text) ? text.join() : text;
351
+ var totalStyle = Array.isArray(style) ? style.map(styleToKeyComponent).join() : styleToKeyComponent(style);
352
+ return "".concat(totalText, "::").concat(totalStyle);
353
+ });
354
+
266
355
  // Stubbable implementation.
267
356
  var _approximateTextSizeInternal = {
268
357
  impl: function (text, style) {
269
- var angle = Array.isArray(style) ? style[0] && style[0].angle : style && style.angle;
358
+ var __debugForceApproximate = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
270
359
 
271
- var height = _approximateTextHeightInternal(text, style);
360
+ // Attempt to first measure the element in DOM. If there is no DOM, fallback
361
+ // to the less accurate approximation algorithm.
362
+ var isClient = typeof window !== "undefined" && typeof window.document !== "undefined" && typeof window.document.createElement !== "undefined";
272
363
 
273
- var width = _approximateTextWidthInternal(text, style);
364
+ if (!isClient || __debugForceApproximate) {
365
+ return _approximateDimensionsInternal(text, style);
366
+ }
274
367
 
275
- var widthWithRotate = angle ? _getSizeWithRotate(width, height, angle) : width;
276
- var heightWithRotate = angle ? _getSizeWithRotate(height, width, angle) : height;
277
- return {
278
- width: widthWithRotate,
279
- height: heightWithRotate * coefficients.heightOverlapCoef
280
- };
368
+ return _measureDimensionsInternal(text, style);
281
369
  }
282
370
  };
283
371
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "victory-core",
3
- "version": "36.6.7",
3
+ "version": "36.6.10",
4
4
  "description": "Victory Core",
5
5
  "keywords": [
6
6
  "data visualization",
@@ -10,7 +10,7 @@
10
10
  ],
11
11
  "repository": {
12
12
  "type": "git",
13
- "url": "https://github.com/formidablelabs/victory.git"
13
+ "url": "https://github.com/FormidableLabs/victory"
14
14
  },
15
15
  "homepage": "https://formidable.com/open-source/victory",
16
16
  "sideEffects": false,
@@ -23,7 +23,7 @@
23
23
  "lodash": "^4.17.21",
24
24
  "prop-types": "^15.8.1",
25
25
  "react-fast-compare": "^3.2.0",
26
- "victory-vendor": "^36.6.7"
26
+ "victory-vendor": "^36.6.10"
27
27
  },
28
28
  "peerDependencies": {
29
29
  "react": ">=16.6.0"
@@ -34,6 +34,9 @@
34
34
  "victory-core": "*",
35
35
  "victory-line": "*"
36
36
  },
37
+ "publishConfig": {
38
+ "provenance": true
39
+ },
37
40
  "wireit": {
38
41
  "### THESE WIREIT CONFIGS ARE GENERATED ####": {},
39
42
  "### DO NOT MODIFY THESE MANUALLY ####": {},
@@ -1,4 +1,3 @@
1
- import * as React from "react";
2
1
  import { get, isNil, orderBy } from "lodash";
3
2
  import { Datum, DatumValue } from "../../../types/prop-types";
4
3
  import { isKeyValueObject } from "../../../victory-util/type-helpers";
@@ -99,6 +99,8 @@ function useNormalizedProps(): ContextType {
99
99
 
100
100
  export function VictoryProvider({
101
101
  children,
102
+ // Disabled due to TODO below which will require this obj. spread
103
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
102
104
  ...providerProps
103
105
  }: VictoryProviderProps) {
104
106
  const value = useNormalizedProps();
@@ -146,5 +148,5 @@ export function useVictoryProviderSync(props: VictoryCalculatedStateProps) {
146
148
 
147
149
  React.useEffect(() => {
148
150
  updateChildProps(myId, props);
149
- }, [updateChildProps, props]);
151
+ }, [updateChildProps, props, myId]);
150
152
  }
@@ -1,6 +1,6 @@
1
1
  // http://www.pearsonified.com/2012/01/characters-per-line.php
2
2
  /* eslint-disable no-magic-numbers */
3
- import { assign, defaults } from "lodash";
3
+ import { assign, defaults, memoize } from "lodash";
4
4
 
5
5
  // Based on measuring specific character widths
6
6
  // as in the following example https://bl.ocks.org/tophtucker/62f93a4658387bb61e4510c37e2e97cf
@@ -243,9 +243,97 @@ const _approximateTextHeightInternal = (text: string | string[], style) => {
243
243
  }, 0);
244
244
  };
245
245
 
246
+ const _approximateDimensionsInternal = (
247
+ text: string | string[],
248
+ style?: TextSizeStyleInterface,
249
+ ) => {
250
+ const angle = Array.isArray(style)
251
+ ? style[0] && style[0].angle
252
+ : style && style.angle;
253
+ const height = _approximateTextHeightInternal(text, style);
254
+ const width = _approximateTextWidthInternal(text, style);
255
+ const widthWithRotate = angle
256
+ ? _getSizeWithRotate(width, height, angle)
257
+ : width;
258
+ const heightWithRotate = angle
259
+ ? _getSizeWithRotate(height, width, angle)
260
+ : height;
261
+ return {
262
+ width: widthWithRotate,
263
+ height: heightWithRotate * coefficients.heightOverlapCoef,
264
+ };
265
+ };
266
+
267
+ const _getMeasurementContainer = memoize(() => {
268
+ const element = document.createElementNS("http://www.w3.org/2000/svg", "svg");
269
+ element.setAttribute("xlink", "http://www.w3.org/1999/xlink");
270
+
271
+ const containerElement = document.createElementNS(
272
+ "http://www.w3.org/2000/svg",
273
+ "text",
274
+ );
275
+ element.appendChild(containerElement);
276
+
277
+ element.style.position = "fixed";
278
+ element.style.top = "-9999px";
279
+ element.style.left = "-9999px";
280
+
281
+ document.body.appendChild(element);
282
+
283
+ return containerElement;
284
+ });
285
+
286
+ const styleToKeyComponent = (style) => {
287
+ if (!style) {
288
+ return "null";
289
+ }
290
+
291
+ return `${style.angle}:${style.fontFamily}:${style.fontSize}:${style.letterSpacing}:${style.lineHeight}`;
292
+ };
293
+
294
+ const _measureDimensionsInternal = memoize(
295
+ (text: string | string[], style?: TextSizeStyleInterface) => {
296
+ const containerElement = _getMeasurementContainer();
297
+
298
+ const lines = _splitToLines(text);
299
+ let heightAcc = 0;
300
+ for (const [i, line] of lines.entries()) {
301
+ const textElement = document.createElementNS(
302
+ "http://www.w3.org/2000/svg",
303
+ "tspan",
304
+ );
305
+ const params = _prepareParams(style, i);
306
+ textElement.style.fontFamily = params.fontFamily;
307
+ textElement.style.transform = `rotate(${params.angle})`;
308
+ textElement.style.fontSize = `${params.fontSize}px`;
309
+ textElement.style.lineHeight = params.lineHeight;
310
+ textElement.style.fontFamily = params.fontFamily;
311
+ textElement.style.letterSpacing = params.letterSpacing;
312
+ textElement.textContent = line;
313
+ textElement.setAttribute("x", "0");
314
+ textElement.setAttribute("y", `${heightAcc}`);
315
+ heightAcc += params.lineHeight * params.fontSize;
316
+
317
+ containerElement.appendChild(textElement);
318
+ }
319
+
320
+ const { width, height } = containerElement.getBoundingClientRect();
321
+
322
+ containerElement.innerHTML = "";
323
+
324
+ return { width, height };
325
+ },
326
+ (text, style) => {
327
+ const totalText = Array.isArray(text) ? text.join() : text;
328
+ const totalStyle = Array.isArray(style)
329
+ ? style.map(styleToKeyComponent).join()
330
+ : styleToKeyComponent(style);
331
+ return `${totalText}::${totalStyle}`;
332
+ },
333
+ );
334
+
246
335
  export interface TextSizeStyleInterface {
247
336
  angle?: number;
248
- characterConstant?: string;
249
337
  fontFamily?: string;
250
338
  fontSize?: number | string;
251
339
  letterSpacing?: string;
@@ -254,22 +342,23 @@ export interface TextSizeStyleInterface {
254
342
 
255
343
  // Stubbable implementation.
256
344
  export const _approximateTextSizeInternal = {
257
- impl: (text: string | string[], style?: TextSizeStyleInterface) => {
258
- const angle = Array.isArray(style)
259
- ? style[0] && style[0].angle
260
- : style && style.angle;
261
- const height = _approximateTextHeightInternal(text, style);
262
- const width = _approximateTextWidthInternal(text, style);
263
- const widthWithRotate = angle
264
- ? _getSizeWithRotate(width, height, angle)
265
- : width;
266
- const heightWithRotate = angle
267
- ? _getSizeWithRotate(height, width, angle)
268
- : height;
269
- return {
270
- width: widthWithRotate,
271
- height: heightWithRotate * coefficients.heightOverlapCoef,
272
- };
345
+ impl: (
346
+ text: string | string[],
347
+ style?: TextSizeStyleInterface,
348
+ __debugForceApproximate = false,
349
+ ) => {
350
+ // Attempt to first measure the element in DOM. If there is no DOM, fallback
351
+ // to the less accurate approximation algorithm.
352
+ const isClient =
353
+ typeof window !== "undefined" &&
354
+ typeof window.document !== "undefined" &&
355
+ typeof window.document.createElement !== "undefined";
356
+
357
+ if (!isClient || __debugForceApproximate) {
358
+ return _approximateDimensionsInternal(text, style);
359
+ }
360
+
361
+ return _measureDimensionsInternal(text, style);
273
362
  },
274
363
  };
275
364