victory-core 36.2.2 → 36.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (102) hide show
  1. package/dist/victory-core.js +14294 -14202
  2. package/dist/victory-core.min.js +1 -1
  3. package/es/index.d.ts +1 -0
  4. package/es/index.js +2 -0
  5. package/es/victory-accessible-group/victory-accessible-group.js +38 -40
  6. package/es/victory-animation/util.js +1 -1
  7. package/es/victory-animation/victory-animation.js +46 -48
  8. package/es/victory-clip-container/victory-clip-container.js +71 -73
  9. package/es/victory-container/victory-container.js +86 -94
  10. package/es/victory-label/victory-label.js +29 -24
  11. package/es/victory-portal/portal-context.js +1 -1
  12. package/es/victory-portal/portal.js +28 -26
  13. package/es/victory-portal/victory-portal.js +31 -41
  14. package/es/victory-primitives/arc.js +6 -4
  15. package/es/victory-primitives/background.js +8 -6
  16. package/es/victory-primitives/border.js +6 -4
  17. package/es/victory-primitives/circle.js +8 -4
  18. package/es/victory-primitives/clip-path.js +1 -1
  19. package/es/victory-primitives/line-segment.js +6 -4
  20. package/es/victory-primitives/line.js +8 -4
  21. package/es/victory-primitives/path.js +7 -3
  22. package/es/victory-primitives/point.js +6 -4
  23. package/es/victory-primitives/rect.js +8 -4
  24. package/es/victory-primitives/text.js +7 -3
  25. package/es/victory-primitives/tspan.js +1 -1
  26. package/es/victory-primitives/whisker.js +9 -7
  27. package/es/victory-transition/victory-transition.js +30 -32
  28. package/es/victory-util/add-events.js +327 -315
  29. package/es/victory-util/axis.js +12 -5
  30. package/es/victory-util/collection.js +8 -4
  31. package/es/victory-util/data.js +9 -5
  32. package/es/victory-util/domain.js +8 -4
  33. package/es/victory-util/events.js +8 -4
  34. package/es/victory-util/helpers.js +1 -1
  35. package/es/victory-util/hooks/use-animation-state.js +11 -5
  36. package/es/victory-util/line-helpers.js +1 -1
  37. package/es/victory-util/scale.js +19 -19
  38. package/es/victory-util/textsize.js +11 -7
  39. package/es/victory-util/timer-context.js +1 -1
  40. package/es/victory-util/timer.js +3 -5
  41. package/es/victory-util/user-props.js +110 -0
  42. package/es/victory-util/wrapper.js +18 -12
  43. package/lib/index.d.ts +1 -0
  44. package/lib/index.js +72 -58
  45. package/lib/victory-accessible-group/victory-accessible-group.js +38 -40
  46. package/lib/victory-animation/util.js +2 -2
  47. package/lib/victory-animation/victory-animation.js +49 -49
  48. package/lib/victory-clip-container/victory-clip-container.js +74 -74
  49. package/lib/victory-container/victory-container.js +90 -95
  50. package/lib/victory-label/victory-label.js +35 -27
  51. package/lib/victory-portal/portal-context.js +1 -1
  52. package/lib/victory-portal/portal.js +31 -27
  53. package/lib/victory-portal/victory-portal.js +34 -42
  54. package/lib/victory-primitives/arc.js +9 -5
  55. package/lib/victory-primitives/background.js +11 -7
  56. package/lib/victory-primitives/border.js +9 -5
  57. package/lib/victory-primitives/circle.js +8 -4
  58. package/lib/victory-primitives/clip-path.js +1 -1
  59. package/lib/victory-primitives/line-segment.js +9 -5
  60. package/lib/victory-primitives/line.js +8 -4
  61. package/lib/victory-primitives/path.js +7 -3
  62. package/lib/victory-primitives/point.js +9 -5
  63. package/lib/victory-primitives/rect.js +8 -4
  64. package/lib/victory-primitives/text.js +7 -3
  65. package/lib/victory-primitives/tspan.js +1 -1
  66. package/lib/victory-primitives/whisker.js +12 -8
  67. package/lib/victory-transition/victory-transition.js +33 -33
  68. package/lib/victory-util/add-events.js +328 -311
  69. package/lib/victory-util/axis.js +20 -11
  70. package/lib/victory-util/collection.js +11 -7
  71. package/lib/victory-util/common-props.js +4 -2
  72. package/lib/victory-util/data.js +13 -7
  73. package/lib/victory-util/default-transitions.js +1 -1
  74. package/lib/victory-util/domain.js +11 -5
  75. package/lib/victory-util/events.js +17 -11
  76. package/lib/victory-util/helpers.js +14 -14
  77. package/lib/victory-util/hooks/index.js +4 -4
  78. package/lib/victory-util/hooks/use-animation-state.js +14 -6
  79. package/lib/victory-util/immutable.js +3 -3
  80. package/lib/victory-util/label-helpers.js +6 -4
  81. package/lib/victory-util/line-helpers.js +4 -2
  82. package/lib/victory-util/prop-types.js +5 -3
  83. package/lib/victory-util/scale.js +24 -21
  84. package/lib/victory-util/selection.js +6 -4
  85. package/lib/victory-util/textsize.js +12 -8
  86. package/lib/victory-util/timer-context.js +1 -1
  87. package/lib/victory-util/timer.js +3 -5
  88. package/lib/victory-util/user-props.js +119 -0
  89. package/lib/victory-util/wrapper.js +31 -23
  90. package/package.json +4 -11
  91. package/src/index.d.ts +1 -0
  92. package/src/index.js +1 -0
  93. package/src/victory-animation/util.js +1 -1
  94. package/src/victory-animation/victory-animation.js +1 -1
  95. package/src/victory-container/victory-container.js +7 -1
  96. package/src/victory-label/victory-label.js +6 -6
  97. package/src/victory-util/add-events.js +6 -2
  98. package/src/victory-util/axis.js +3 -0
  99. package/src/victory-util/line-helpers.js +1 -1
  100. package/src/victory-util/scale.js +18 -9
  101. package/src/victory-util/timer.js +1 -1
  102. package/src/victory-util/user-props.js +81 -0
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.approximateTextSize = exports._approximateTextSizeInternal = exports.convertLengthToPixels = void 0;
6
+ exports.convertLengthToPixels = exports.approximateTextSize = exports._approximateTextSizeInternal = void 0;
7
7
 
8
8
  var _defaults2 = _interopRequireDefault(require("lodash/defaults"));
9
9
 
@@ -11,13 +11,17 @@ var _assign2 = _interopRequireDefault(require("lodash/assign"));
11
11
 
12
12
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
13
13
 
14
- function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _nonIterableSpread(); }
14
+ function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
15
15
 
16
- function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance"); }
16
+ 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."); }
17
17
 
18
- function _iterableToArray(iter) { if (Symbol.iterator in Object(iter) || Object.prototype.toString.call(iter) === "[object Arguments]") return Array.from(iter); }
18
+ 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); }
19
19
 
20
- function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = new Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } }
20
+ function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
21
+
22
+ function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
23
+
24
+ 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; }
21
25
 
22
26
  // Based on measuring specific character widths
23
27
  // as in the following example https://bl.ocks.org/tophtucker/62f93a4658387bb61e4510c37e2e97cf
@@ -126,10 +130,10 @@ var fonts = {
126
130
  Verdana: {
127
131
  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],
128
132
  avg: 0.6171875000000003
129
- } //https://developer.mozilla.org/en/docs/Web/CSS/length
130
- // Absolute sizes in pixels for obsolete measurement units.
133
+ }
134
+ }; //https://developer.mozilla.org/en/docs/Web/CSS/length
135
+ // Absolute sizes in pixels for obsolete measurement units.
131
136
 
132
- };
133
137
  var absoluteMeasurementUnitsToPixels = {
134
138
  mm: 3.8,
135
139
  sm: 38,
@@ -15,7 +15,7 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
15
15
  * The React context object consumers may use to access or override the global
16
16
  * timer.
17
17
  */
18
- var TimerContext = _react.default.createContext({
18
+ var TimerContext = /*#__PURE__*/_react.default.createContext({
19
19
  transitionTimer: new _timer.default(),
20
20
  animationTimer: new _timer.default()
21
21
  });
@@ -5,17 +5,15 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.default = void 0;
7
7
 
8
- var _d3Timer = require("d3-timer");
8
+ var _d3Timer = require("victory-vendor/d3-timer");
9
9
 
10
10
  function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
11
11
 
12
12
  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); } }
13
13
 
14
- function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
14
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
15
15
 
16
- var Timer =
17
- /*#__PURE__*/
18
- function () {
16
+ var Timer = /*#__PURE__*/function () {
19
17
  function Timer() {
20
18
  _classCallCheck(this, Timer);
21
19
 
@@ -0,0 +1,119 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.getSafeUserProps = void 0;
7
+
8
+ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
9
+
10
+ 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."); }
11
+
12
+ 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); }
13
+
14
+ 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; }
15
+
16
+ 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; }
17
+
18
+ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
19
+
20
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
21
+
22
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
23
+
24
+ function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
25
+
26
+ /*
27
+ USER_PROPS_SAFELIST is to contain any string deemed safe for user props.
28
+ The startsWidth array will contain the start of any accepted user-prop that
29
+ starts with these characters.
30
+ The exactMatch will contain a list of exact prop names that are accepted.
31
+ */
32
+ var USER_PROPS_SAFELIST = {
33
+ startsWith: ["data-", "aria-"],
34
+ exactMatch: []
35
+ };
36
+ /**
37
+ * doesPropStartWith: Function that takes a prop's key and runs it against all
38
+ * options in the USER_PROPS_SAFELIST and checks to see if it starts with any
39
+ * of those options.
40
+ * @param {string} key: prop key to be tested against whitelist
41
+ * @returns {Boolean}: returns true if the key starts with an option or false if
42
+ * otherwise
43
+ */
44
+
45
+ var doesPropStartWith = function (key) {
46
+ var startsWith = false;
47
+ USER_PROPS_SAFELIST.startsWith.forEach(function (starterString) {
48
+ var regex = new RegExp("\\b(".concat(starterString, ")(\\w|-)+"), "g");
49
+ if (regex.test(key)) startsWith = true;
50
+ });
51
+ return startsWith;
52
+ };
53
+ /**
54
+ * isExactMatch: checks to see if the given key matches any of the 'exactMatch'
55
+ * items in the whitelist
56
+ * @param {String} key: prop key to be tested against the whitelist-exact match
57
+ * array.
58
+ * @returns {Boolean}: return true if whitelist contains that key, otherwise
59
+ * returns false.
60
+ */
61
+
62
+
63
+ var isExactMatch = function (key) {
64
+ return USER_PROPS_SAFELIST.exactMatch.includes(key);
65
+ };
66
+ /**
67
+ * testIfSafeProp: tests prop's key against both startsWith and exactMatch values
68
+ * @param {String} key: prop key to be tested against the whitelist
69
+ * @returns {Boolean}: returns true if found in whitelist, otherwise returns false
70
+ */
71
+
72
+
73
+ var testIfSafeProp = function (key) {
74
+ if (doesPropStartWith(key) || isExactMatch(key)) return true;
75
+ return false;
76
+ };
77
+ /**
78
+ * Gets the value from props if a function value is provided
79
+ * @param {any} value: maybe function value
80
+ * @param {Object} props: props object
81
+ * @returns {any} newValue
82
+ */
83
+
84
+
85
+ var getValue = function (value, props) {
86
+ if (typeof value === "function") {
87
+ return value(props);
88
+ }
89
+
90
+ return value;
91
+ };
92
+ /**
93
+ * getSafeUserProps - function that takes in a props object and removes any
94
+ * key-value entries that do not match filter strings in the USER_PROPS_SAFELIST
95
+ * object.
96
+ *
97
+ * @param {Object} props: props to be filtered against USER_PROPS_SAFELIST
98
+ * @returns {Object}: object containing remaining acceptable props
99
+ */
100
+
101
+
102
+ var getSafeUserProps = function (props) {
103
+ var propsToFilter = _objectSpread({}, props);
104
+
105
+ return Object.fromEntries(Object.entries(propsToFilter).filter(function (_ref) {
106
+ var _ref2 = _slicedToArray(_ref, 1),
107
+ key = _ref2[0];
108
+
109
+ return testIfSafeProp(key);
110
+ }).map(function (_ref3) {
111
+ var _ref4 = _slicedToArray(_ref3, 2),
112
+ key = _ref4[0],
113
+ value = _ref4[1];
114
+
115
+ return [key, getValue(value, props)];
116
+ }));
117
+ };
118
+
119
+ exports.getSafeUserProps = getSafeUserProps;
@@ -4,22 +4,22 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.addBinsToParentPropsIfHistogram = addBinsToParentPropsIfHistogram;
7
- exports.getDataFromChildren = getDataFromChildren;
7
+ exports.getAllEvents = getAllEvents;
8
+ exports.getCategories = getCategories;
9
+ exports.getCategoryAndAxisStringsFromChildren = getCategoryAndAxisStringsFromChildren;
10
+ exports.getChildStyle = getChildStyle;
11
+ exports.getColor = getColor;
8
12
  exports.getData = getData;
9
- exports.getWidth = getWidth;
13
+ exports.getDataFromChildren = getDataFromChildren;
10
14
  exports.getDefaultDomainPadding = getDefaultDomainPadding;
11
- exports.getDomainFromChildren = getDomainFromChildren;
12
15
  exports.getDomain = getDomain;
16
+ exports.getDomainFromChildren = getDomainFromChildren;
13
17
  exports.getScale = getScale;
14
- exports.getAllEvents = getAllEvents;
15
- exports.getColor = getColor;
16
- exports.getStyle = getStyle;
17
- exports.getChildStyle = getChildStyle;
18
18
  exports.getStringsFromCategories = getStringsFromCategories;
19
- exports.getStringsFromData = getStringsFromData;
20
- exports.getCategoryAndAxisStringsFromChildren = getCategoryAndAxisStringsFromChildren;
21
19
  exports.getStringsFromChildren = getStringsFromChildren;
22
- exports.getCategories = getCategories;
20
+ exports.getStringsFromData = getStringsFromData;
21
+ exports.getStyle = getStyle;
22
+ exports.getWidth = getWidth;
23
23
 
24
24
  var _isPlainObject2 = _interopRequireDefault(require("lodash/isPlainObject"));
25
25
 
@@ -59,19 +59,27 @@ var Scale = _interopRequireWildcard(require("./scale"));
59
59
 
60
60
  var Log = _interopRequireWildcard(require("./log"));
61
61
 
62
- function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; return newObj; } }
62
+ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
63
+
64
+ 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; }
63
65
 
64
66
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
65
67
 
66
- function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _nonIterableSpread(); }
68
+ function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
69
+
70
+ 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."); }
71
+
72
+ 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); }
73
+
74
+ function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
67
75
 
68
- function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance"); }
76
+ function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
69
77
 
70
- function _iterableToArray(iter) { if (Symbol.iterator in Object(iter) || Object.prototype.toString.call(iter) === "[object Arguments]") return Array.from(iter); }
78
+ 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; }
71
79
 
72
- function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = new Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } }
80
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
73
81
 
74
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; var ownKeys = Object.keys(source); if (typeof Object.getOwnPropertySymbols === 'function') { ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function (sym) { return Object.getOwnPropertyDescriptor(source, sym).enumerable; })); } ownKeys.forEach(function (key) { _defineProperty(target, key, source[key]); }); } return target; }
82
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
75
83
 
76
84
  function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
77
85
 
@@ -121,7 +129,7 @@ function addBinsToParentPropsIfHistogram(_ref) {
121
129
  }, []);
122
130
  }
123
131
 
124
- return _objectSpread({}, parentProps, {
132
+ return _objectSpread(_objectSpread({}, parentProps), {}, {
125
133
  bins: childBins
126
134
  });
127
135
  }
@@ -157,7 +165,7 @@ function getDataFromChildren(props, childComponents) {
157
165
  if (!Data.isDataComponent(child)) {
158
166
  return null;
159
167
  } else if (child.type && (0, _isFunction2.default)(child.type.getData)) {
160
- child = parent ? _react.default.cloneElement(child, parent.props) : child;
168
+ child = parent ? /*#__PURE__*/_react.default.cloneElement(child, parent.props) : child;
161
169
  childData = child.type.getData(childProps);
162
170
  } else {
163
171
  childData = Data.getData(childProps);
@@ -309,8 +317,8 @@ function getDomain(props, axis, childComponents) {
309
317
  var dataset = (props.data || props.y) && Data.getData(props);
310
318
  var dataDomain = dataset ? Domain.getDomainFromData(props, axis, dataset) : [];
311
319
  var childDomain = getDomainFromChildren(props, axis, childComponents);
312
- var min = minDomain || Collection.getMinValue(_toConsumableArray(dataDomain).concat(_toConsumableArray(childDomain)));
313
- var max = maxDomain || Collection.getMaxValue(_toConsumableArray(dataDomain).concat(_toConsumableArray(childDomain)));
320
+ var min = minDomain || Collection.getMinValue([].concat(_toConsumableArray(dataDomain), _toConsumableArray(childDomain)));
321
+ var max = maxDomain || Collection.getMaxValue([].concat(_toConsumableArray(dataDomain), _toConsumableArray(childDomain)));
314
322
  domain = Domain.getDomainFromMinMax(min, max);
315
323
  }
316
324
 
@@ -470,7 +478,7 @@ function getCategoryAndAxisStringsFromChildren(props, axis, childComponents) {
470
478
  var axisComponent = Axis.getAxisComponent(childComponents, axis);
471
479
  var axisStrings = axisComponent ? Data.getStringsFromAxes(axisComponent.props, axis) : [];
472
480
  var categoryStrings = categories || getStringsFromCategories(childComponents, axis);
473
- return (0, _uniq2.default)((0, _flatten2.default)(_toConsumableArray(categoryStrings).concat(_toConsumableArray(axisStrings))));
481
+ return (0, _uniq2.default)((0, _flatten2.default)([].concat(_toConsumableArray(categoryStrings), _toConsumableArray(axisStrings))));
474
482
  }
475
483
 
476
484
  function getStringsFromChildren(props, childComponents) {
@@ -479,8 +487,8 @@ function getStringsFromChildren(props, childComponents) {
479
487
  var yStrings = getCategoryAndAxisStringsFromChildren(props, "y", childComponents);
480
488
  var dataStrings = getStringsFromData(childComponents);
481
489
  return {
482
- x: (0, _uniq2.default)((0, _flatten2.default)(_toConsumableArray(xStrings).concat(_toConsumableArray(dataStrings.x)))),
483
- y: (0, _uniq2.default)((0, _flatten2.default)(_toConsumableArray(yStrings).concat(_toConsumableArray(dataStrings.y))))
490
+ x: (0, _uniq2.default)((0, _flatten2.default)([].concat(_toConsumableArray(xStrings), _toConsumableArray(dataStrings.x)))),
491
+ y: (0, _uniq2.default)((0, _flatten2.default)([].concat(_toConsumableArray(yStrings), _toConsumableArray(dataStrings.y))))
484
492
  };
485
493
  }
486
494
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "victory-core",
3
- "version": "36.2.2",
3
+ "version": "36.4.0",
4
4
  "description": "Victory Core",
5
5
  "keywords": [
6
6
  "data visualization",
@@ -19,17 +19,10 @@
19
19
  "author": "Formidable",
20
20
  "license": "MIT",
21
21
  "dependencies": {
22
- "d3-ease": "^1.0.0",
23
- "d3-interpolate": "^1.1.1",
24
- "d3-scale": "^1.0.0",
25
- "d3-shape": "^1.2.0",
26
- "d3-timer": "^1.0.0",
27
22
  "lodash": "^4.17.21",
28
23
  "prop-types": "^15.5.8",
29
- "react-fast-compare": "^2.0.0"
30
- },
31
- "resolutions": {
32
- "d3-interpolate/d3-color": "^3.0.0"
24
+ "react-fast-compare": "^2.0.0",
25
+ "victory-vendor": "^36.4.0"
33
26
  },
34
27
  "peerDependencies": {
35
28
  "react": "^16.6.0 || ^17.0.0"
@@ -38,5 +31,5 @@
38
31
  "version": "yarn run nps build-libs && nps build-dists"
39
32
  },
40
33
  "sideEffects": false,
41
- "gitHead": "e09146d4bede80e27ed095fcd7e1167c00fba864"
34
+ "gitHead": "2e05481eeb34f9801a90023a131a21aa7deff082"
42
35
  }
package/src/index.d.ts CHANGED
@@ -248,6 +248,7 @@ export interface VictoryLabelProps {
248
248
  style?: VictoryLabelStyleObject | VictoryLabelStyleObject[];
249
249
  tabIndex?: NumberOrCallback;
250
250
  text?: string[] | StringOrNumberOrCallback;
251
+ textComponent?: React.ReactElement;
251
252
  textAnchor?: TextAnchorType | { (): TextAnchorType };
252
253
  title?: string;
253
254
  transform?: string | {} | { (): string | {} };
package/src/index.js CHANGED
@@ -39,6 +39,7 @@ export * as Style from "./victory-util/style";
39
39
  export * as TextSize from "./victory-util/textsize";
40
40
  export { default as Timer } from "./victory-util/timer";
41
41
  export * as Transitions from "./victory-util/transitions";
42
+ export * as UserProps from "./victory-util/user-props";
42
43
  export * as CommonProps from "./victory-util/common-props";
43
44
  export * as Wrapper from "./victory-util/wrapper";
44
45
  export * as Axis from "./victory-util/axis";
@@ -1,4 +1,4 @@
1
- import { interpolate } from "d3-interpolate";
1
+ import { interpolate } from "victory-vendor/d3-interpolate";
2
2
  import { isPlainObject, orderBy } from "lodash";
3
3
 
4
4
  export const isInterpolatable = function (obj) {
@@ -1,7 +1,7 @@
1
1
  /*global setTimeout:false */
2
2
  import React from "react";
3
3
  import PropTypes from "prop-types";
4
- import * as d3Ease from "d3-ease";
4
+ import * as d3Ease from "victory-vendor/d3-ease";
5
5
  import { victoryInterpolator } from "./util";
6
6
  import TimerContext from "../victory-util/timer-context";
7
7
  import isEqual from "react-fast-compare";
@@ -6,6 +6,7 @@ import Portal from "../victory-portal/portal";
6
6
  import PortalContext from "../victory-portal/portal-context";
7
7
  import TimerContext from "../victory-util/timer-context";
8
8
  import * as Helpers from "../victory-util/helpers";
9
+ import * as UserProps from "../victory-util/user-props";
9
10
 
10
11
  export default class VictoryContainer extends React.Component {
11
12
  static displayName = "VictoryContainer";
@@ -192,9 +193,13 @@ export default class VictoryContainer extends React.Component {
192
193
  preserveAspectRatio,
193
194
  role
194
195
  } = this.props;
196
+
195
197
  const style = responsive
196
198
  ? this.props.style
197
199
  : Helpers.omit(this.props.style, ["height", "width"]);
200
+
201
+ const userProps = UserProps.getSafeUserProps(this.props);
202
+
198
203
  const svgProps = assign(
199
204
  {
200
205
  width,
@@ -213,7 +218,8 @@ export default class VictoryContainer extends React.Component {
213
218
  .filter(Boolean)
214
219
  .join(" ") || undefined,
215
220
  viewBox: responsive ? `0 0 ${width} ${height}` : undefined,
216
- preserveAspectRatio: responsive ? preserveAspectRatio : undefined
221
+ preserveAspectRatio: responsive ? preserveAspectRatio : undefined,
222
+ ...userProps
217
223
  },
218
224
  events
219
225
  );
@@ -1,17 +1,17 @@
1
1
  /*eslint no-magic-numbers: ["error", { "ignore": [-0.5, 0.5, 0, 1, 2] }]*/
2
- import React from "react";
2
+ import { assign, defaults, isEmpty } from "lodash";
3
3
  import PropTypes from "prop-types";
4
+ import React from "react";
4
5
  import VictoryPortal from "../victory-portal/victory-portal";
5
6
  import Rect from "../victory-primitives/rect";
6
- import * as CustomPropTypes from "../victory-util/prop-types";
7
+ import Text from "../victory-primitives/text";
8
+ import TSpan from "../victory-primitives/tspan";
7
9
  import * as Helpers from "../victory-util/helpers";
8
10
  import * as LabelHelpers from "../victory-util/label-helpers";
9
- import * as Style from "../victory-util/style";
10
11
  import * as Log from "../victory-util/log";
12
+ import * as CustomPropTypes from "../victory-util/prop-types";
13
+ import * as Style from "../victory-util/style";
11
14
  import * as TextSize from "../victory-util/textsize";
12
- import TSpan from "../victory-primitives/tspan";
13
- import Text from "../victory-primitives/text";
14
- import { assign, defaults, isEmpty } from "lodash";
15
15
 
16
16
  const defaultStyles = {
17
17
  fill: "#252525",
@@ -14,6 +14,7 @@ import {
14
14
  import * as Events from "./events";
15
15
  import isEqual from "react-fast-compare";
16
16
  import VictoryTransition from "../victory-transition/victory-transition";
17
+ import * as UserProps from "../victory-util/user-props";
17
18
 
18
19
  const datumHasXandY = (datum) => {
19
20
  return !isNil(datum._x) && !isNil(datum._y);
@@ -274,10 +275,12 @@ export default (WrappedComponent, options) => {
274
275
  const parentProps = isContainer
275
276
  ? this.getComponentProps(component, "parent", "parent")
276
277
  : {};
278
+
277
279
  if (parentProps.events) {
278
280
  this.globalEvents = Events.getGlobalEvents(parentProps.events);
279
281
  parentProps.events = Events.omitGlobalEvents(parentProps.events);
280
282
  }
283
+
281
284
  return React.cloneElement(component, parentProps, children);
282
285
  }
283
286
 
@@ -327,7 +330,7 @@ export default (WrappedComponent, options) => {
327
330
 
328
331
  renderData(props, shouldRenderDatum = datumHasXandY) {
329
332
  const { dataComponent, labelComponent, groupComponent } = props;
330
-
333
+ const userProps = UserProps.getSafeUserProps(props);
331
334
  const dataComponents = this.dataKeys.reduce(
332
335
  (validDataComponents, _dataKey, index) => {
333
336
  const dataProps = this.getComponentProps(
@@ -360,7 +363,8 @@ export default (WrappedComponent, options) => {
360
363
  .filter(Boolean);
361
364
 
362
365
  const children = [...dataComponents, ...labelComponents];
363
- return this.renderContainer(groupComponent, children);
366
+ const group = React.cloneElement(groupComponent, userProps, children);
367
+ return this.renderContainer(group, children);
364
368
  }
365
369
  };
366
370
  };
@@ -239,6 +239,9 @@ export function getTickFormat(props, scale) {
239
239
  const stringMap = props.stringMap && props.stringMap[axis];
240
240
  if (!tickFormat) {
241
241
  const defaultTickFormat = getDefaultTickFormat(props);
242
+ // If there is no user-provided tick format, we use d3's tickFormat function
243
+ // by default. This changed the default formatting for some scale types when
244
+ // we upgraded to d3-scale@4..
242
245
  const scaleTickFormat =
243
246
  scale.tickFormat && isFunction(scale.tickFormat)
244
247
  ? scale.tickFormat()
@@ -1,4 +1,4 @@
1
- import * as d3Shape from "d3-shape";
1
+ import * as d3Shape from "victory-vendor/d3-shape";
2
2
 
3
3
  const defined = (d) => {
4
4
  const y = d._y1 !== undefined ? d._y1 : d._y;
@@ -3,7 +3,7 @@
3
3
  import { includes, isFunction, isPlainObject } from "lodash";
4
4
  import * as Helpers from "./helpers";
5
5
  import * as Collection from "./collection";
6
- import * as d3Scale from "d3-scale";
6
+ import * as d3Scale from "victory-vendor/d3-scale";
7
7
 
8
8
  const supportedScaleStrings = ["linear", "time", "log", "sqrt"];
9
9
 
@@ -110,19 +110,28 @@ export function getScaleType(props, axis) {
110
110
  );
111
111
  }
112
112
 
113
+ // Ordered type inference off of function fields.
114
+ // **Note**: Brittle because reliant on d3 internals.
115
+ const DUCK_TYPES = [
116
+ { name: "quantile", method: "quantiles" },
117
+ { name: "log", method: "base" }
118
+ // TODO(2214): Re-evaluate (1) duck typing approach, and (2) if duck typing,
119
+ // do we need a different approach? (Multiple keys? Stringifying functions?)
120
+ // https://github.com/FormidableLabs/victory/issues/2214
121
+ // Below are matches that don't seem to otherwise occur in Victory code base.
122
+ // { name: "ordinal", method: "unknown" },
123
+ // { name: "pow-sqrt", method: "exponent" },
124
+ // { name: "quantize-threshold", method: "invertExtent" }
125
+ ];
126
+
113
127
  export function getType(scale) {
114
128
  if (typeof scale === "string") {
115
129
  return scale;
116
130
  }
117
- const duckTypes = [
118
- { name: "log", method: "base" },
119
- { name: "ordinal", method: "unknown" },
120
- { name: "pow-sqrt", method: "exponent" },
121
- { name: "quantile", method: "quantiles" },
122
- { name: "quantize-threshold", method: "invertExtent" }
123
- ];
124
- const scaleType = duckTypes.filter((type) => {
131
+
132
+ const scaleType = DUCK_TYPES.filter((type) => {
125
133
  return scale[type.method] !== undefined;
126
134
  })[0];
135
+
127
136
  return scaleType ? scaleType.name : undefined;
128
137
  }
@@ -1,4 +1,4 @@
1
- import { timer, now } from "d3-timer";
1
+ import { timer, now } from "victory-vendor/d3-timer";
2
2
 
3
3
  export default class Timer {
4
4
  constructor() {
@@ -0,0 +1,81 @@
1
+ /*
2
+ USER_PROPS_SAFELIST is to contain any string deemed safe for user props.
3
+ The startsWidth array will contain the start of any accepted user-prop that
4
+ starts with these characters.
5
+ The exactMatch will contain a list of exact prop names that are accepted.
6
+ */
7
+ const USER_PROPS_SAFELIST = {
8
+ startsWith: ["data-", "aria-"],
9
+ exactMatch: []
10
+ };
11
+
12
+ /**
13
+ * doesPropStartWith: Function that takes a prop's key and runs it against all
14
+ * options in the USER_PROPS_SAFELIST and checks to see if it starts with any
15
+ * of those options.
16
+ * @param {string} key: prop key to be tested against whitelist
17
+ * @returns {Boolean}: returns true if the key starts with an option or false if
18
+ * otherwise
19
+ */
20
+ const doesPropStartWith = (key) => {
21
+ let startsWith = false;
22
+
23
+ USER_PROPS_SAFELIST.startsWith.forEach((starterString) => {
24
+ const regex = new RegExp(`\\b(${starterString})(\\w|-)+`, "g");
25
+ if (regex.test(key)) startsWith = true;
26
+ });
27
+
28
+ return startsWith;
29
+ };
30
+
31
+ /**
32
+ * isExactMatch: checks to see if the given key matches any of the 'exactMatch'
33
+ * items in the whitelist
34
+ * @param {String} key: prop key to be tested against the whitelist-exact match
35
+ * array.
36
+ * @returns {Boolean}: return true if whitelist contains that key, otherwise
37
+ * returns false.
38
+ */
39
+ const isExactMatch = (key) => USER_PROPS_SAFELIST.exactMatch.includes(key);
40
+
41
+ /**
42
+ * testIfSafeProp: tests prop's key against both startsWith and exactMatch values
43
+ * @param {String} key: prop key to be tested against the whitelist
44
+ * @returns {Boolean}: returns true if found in whitelist, otherwise returns false
45
+ */
46
+ const testIfSafeProp = (key) => {
47
+ if (doesPropStartWith(key) || isExactMatch(key)) return true;
48
+ return false;
49
+ };
50
+
51
+ /**
52
+ * Gets the value from props if a function value is provided
53
+ * @param {any} value: maybe function value
54
+ * @param {Object} props: props object
55
+ * @returns {any} newValue
56
+ */
57
+ const getValue = (value, props) => {
58
+ if (typeof value === "function") {
59
+ return value(props);
60
+ }
61
+ return value;
62
+ };
63
+
64
+ /**
65
+ * getSafeUserProps - function that takes in a props object and removes any
66
+ * key-value entries that do not match filter strings in the USER_PROPS_SAFELIST
67
+ * object.
68
+ *
69
+ * @param {Object} props: props to be filtered against USER_PROPS_SAFELIST
70
+ * @returns {Object}: object containing remaining acceptable props
71
+ */
72
+ export const getSafeUserProps = (props) => {
73
+ const propsToFilter = { ...props };
74
+ return Object.fromEntries(
75
+ Object.entries(propsToFilter)
76
+ .filter(([key]) => testIfSafeProp(key))
77
+ .map(([key, value]) => {
78
+ return [key, getValue(value, props)];
79
+ })
80
+ );
81
+ };