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.
Files changed (110) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/dist/victory-core.js +4371 -5749
  3. package/dist/victory-core.min.js +1 -1
  4. package/es/victory-accessible-group/victory-accessible-group.js +9 -15
  5. package/es/victory-animation/util.js +28 -47
  6. package/es/victory-animation/victory-animation.js +51 -67
  7. package/es/victory-clip-container/victory-clip-container.js +153 -229
  8. package/es/victory-container/victory-container.js +157 -216
  9. package/es/victory-label/victory-label.js +246 -323
  10. package/es/victory-portal/portal-context.js +1 -2
  11. package/es/victory-portal/portal.js +30 -76
  12. package/es/victory-portal/victory-portal.js +47 -104
  13. package/es/victory-primitives/arc.js +44 -47
  14. package/es/victory-primitives/background.js +14 -17
  15. package/es/victory-primitives/border.js +20 -24
  16. package/es/victory-primitives/circle.js +13 -27
  17. package/es/victory-primitives/clip-path.js +3 -7
  18. package/es/victory-primitives/line-segment.js +20 -24
  19. package/es/victory-primitives/line.js +13 -27
  20. package/es/victory-primitives/path.js +13 -27
  21. package/es/victory-primitives/point.js +36 -40
  22. package/es/victory-primitives/rect.js +13 -27
  23. package/es/victory-primitives/text.js +15 -28
  24. package/es/victory-primitives/tspan.js +13 -26
  25. package/es/victory-primitives/whisker.js +43 -47
  26. package/es/victory-theme/grayscale.js +22 -22
  27. package/es/victory-theme/material.js +46 -46
  28. package/es/victory-theme/victory-theme.js +3 -3
  29. package/es/victory-transition/victory-transition.js +126 -206
  30. package/es/victory-util/add-events.js +263 -374
  31. package/es/victory-util/axis.js +126 -222
  32. package/es/victory-util/collection.js +13 -41
  33. package/es/victory-util/data.js +159 -214
  34. package/es/victory-util/default-transitions.js +33 -51
  35. package/es/victory-util/domain.js +122 -171
  36. package/es/victory-util/events.js +168 -258
  37. package/es/victory-util/helpers.js +153 -178
  38. package/es/victory-util/hooks/use-animation-state.js +61 -99
  39. package/es/victory-util/hooks/use-previous-props.js +2 -2
  40. package/es/victory-util/immutable.js +6 -8
  41. package/es/victory-util/label-helpers.js +128 -130
  42. package/es/victory-util/line-helpers.js +29 -41
  43. package/es/victory-util/log.js +1 -1
  44. package/es/victory-util/point-path-helpers.js +89 -49
  45. package/es/victory-util/scale.js +24 -42
  46. package/es/victory-util/selection.js +39 -40
  47. package/es/victory-util/style.js +8 -13
  48. package/es/victory-util/textsize.js +80 -154
  49. package/es/victory-util/timer-context.js +2 -2
  50. package/es/victory-util/timer.js +40 -76
  51. package/es/victory-util/transitions.js +110 -150
  52. package/es/victory-util/type-helpers.js +2 -3
  53. package/es/victory-util/user-props.js +24 -49
  54. package/es/victory-util/wrapper.js +184 -247
  55. package/lib/index.js +0 -30
  56. package/lib/victory-accessible-group/victory-accessible-group.js +9 -19
  57. package/lib/victory-animation/util.js +28 -63
  58. package/lib/victory-animation/victory-animation.js +54 -83
  59. package/lib/victory-clip-container/victory-clip-container.js +156 -243
  60. package/lib/victory-container/victory-container.js +160 -232
  61. package/lib/victory-label/victory-label.js +248 -344
  62. package/lib/victory-portal/portal-context.js +1 -6
  63. package/lib/victory-portal/portal.js +31 -81
  64. package/lib/victory-portal/victory-portal.js +50 -116
  65. package/lib/victory-primitives/arc.js +48 -57
  66. package/lib/victory-primitives/background.js +16 -28
  67. package/lib/victory-primitives/border.js +22 -34
  68. package/lib/victory-primitives/circle.js +16 -36
  69. package/lib/victory-primitives/clip-path.js +3 -11
  70. package/lib/victory-primitives/index.js +0 -28
  71. package/lib/victory-primitives/line-segment.js +22 -34
  72. package/lib/victory-primitives/line.js +16 -36
  73. package/lib/victory-primitives/path.js +16 -36
  74. package/lib/victory-primitives/point.js +38 -52
  75. package/lib/victory-primitives/rect.js +16 -36
  76. package/lib/victory-primitives/text.js +15 -33
  77. package/lib/victory-primitives/tspan.js +13 -31
  78. package/lib/victory-primitives/whisker.js +45 -57
  79. package/lib/victory-theme/grayscale.js +23 -24
  80. package/lib/victory-theme/material.js +47 -48
  81. package/lib/victory-theme/victory-theme.js +2 -7
  82. package/lib/victory-transition/victory-transition.js +129 -224
  83. package/lib/victory-util/add-events.js +263 -380
  84. package/lib/victory-util/axis.js +128 -241
  85. package/lib/victory-util/collection.js +13 -50
  86. package/lib/victory-util/data.js +160 -239
  87. package/lib/victory-util/default-transitions.js +33 -54
  88. package/lib/victory-util/domain.js +123 -193
  89. package/lib/victory-util/events.js +167 -274
  90. package/lib/victory-util/helpers.js +156 -207
  91. package/lib/victory-util/hooks/index.js +0 -2
  92. package/lib/victory-util/hooks/use-animation-state.js +63 -113
  93. package/lib/victory-util/hooks/use-previous-props.js +2 -7
  94. package/lib/victory-util/immutable.js +6 -18
  95. package/lib/victory-util/index.js +2 -51
  96. package/lib/victory-util/label-helpers.js +130 -141
  97. package/lib/victory-util/line-helpers.js +31 -49
  98. package/lib/victory-util/log.js +1 -2
  99. package/lib/victory-util/point-path-helpers.js +91 -63
  100. package/lib/victory-util/scale.js +26 -57
  101. package/lib/victory-util/selection.js +41 -49
  102. package/lib/victory-util/style.js +8 -16
  103. package/lib/victory-util/textsize.js +80 -157
  104. package/lib/victory-util/timer-context.js +2 -8
  105. package/lib/victory-util/timer.js +40 -76
  106. package/lib/victory-util/transitions.js +110 -152
  107. package/lib/victory-util/type-helpers.js +2 -9
  108. package/lib/victory-util/user-props.js +25 -59
  109. package/lib/victory-util/wrapper.js +186 -281
  110. package/package.json +2 -2
@@ -1,55 +1,24 @@
1
1
  import _pick from "lodash/pick";
2
2
  import _isEmpty from "lodash/isEmpty";
3
3
  import _defaults from "lodash/defaults";
4
-
5
- function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
6
-
7
- 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."); }
8
-
9
- 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); }
10
-
11
- function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
12
-
13
- function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
14
-
15
- 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; }
16
-
17
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
18
-
19
- 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); } }
20
-
21
- function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
22
-
23
- function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
24
-
25
- function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
26
-
27
- function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
28
-
29
- function _possibleConstructorReturn(self, call) { if (call && (typeof call === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
30
-
31
- function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
32
-
33
- function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
34
-
35
- function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
36
-
37
4
  import React from "react";
38
5
  import isEqual from "react-fast-compare";
39
6
  import { VictoryTransition } from "../victory-transition/victory-transition";
40
7
  import { difference } from "./collection";
41
8
  import * as Events from "./events";
42
- import { isFunction, isNil } from "./helpers"; // DISCLAIMER:
9
+ import { isFunction, isNil } from "./helpers";
10
+
11
+ // DISCLAIMER:
43
12
  // This file is not currently tested, and it is first on the list of files
44
13
  // to refactor in our current refactoring effort. Please do not make changes
45
14
  // to this file without manual testing and/or refactoring and adding tests.
46
15
 
47
- var datumHasXandY = function (datum) {
16
+ const datumHasXandY = datum => {
48
17
  return !isNil(datum._x) && !isNil(datum._y);
49
- }; // used for checking state changes. Expected components can be passed in via options
50
-
18
+ };
51
19
 
52
- var defaultComponents = [{
20
+ // used for checking state changes. Expected components can be passed in via options
21
+ const defaultComponents = [{
53
22
  name: "parent",
54
23
  index: "parent"
55
24
  }, {
@@ -57,361 +26,281 @@ var defaultComponents = [{
57
26
  }, {
58
27
  name: "labels"
59
28
  }];
60
- export function addEvents(WrappedComponent) {
61
- var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
62
29
 
30
+ /**
31
+ * These methods will be implemented by the Mixin,
32
+ * and are accessible to the Wrapped Component.
33
+ *
34
+ * To make your Wrapped Component type-safe, use "interface merging" like so:
35
+ * @example
36
+ * interface MyComponent extends EventsMixinClass<MyProps> {}
37
+ * class MyComponent extends React.Component<MyProps> { ... }
38
+ */
39
+
40
+ /**
41
+ * These fields are calculated by the Mixin
42
+ */
43
+
44
+ /**
45
+ * These are the common roles that we care about internally.
46
+ */
47
+
48
+ /**
49
+ * A component can have any "role",
50
+ * but there are certain ones that we actually care about internally
51
+ */
52
+
53
+ /**
54
+ * Static component fields used by Victory for common behavior
55
+ */
56
+
57
+ /**
58
+ * This represents the class itself, including static fields
59
+ */
60
+
61
+ export function addEvents(WrappedComponent, options) {
62
+ if (options === void 0) {
63
+ options = {};
64
+ } // eslint-disable-next-line @typescript-eslint/no-empty-interface
63
65
  // @ts-expect-error "TS2545: A mixin class must have a constructor with a single rest parameter of type 'any[]'."
64
- var AddEventsMixin = /*#__PURE__*/function (_WrappedComponent) {
65
- _inherits(AddEventsMixin, _WrappedComponent);
66
-
67
- var _super = _createSuper(AddEventsMixin);
68
-
69
- function AddEventsMixin(props) {
70
- var _this;
71
-
72
- _classCallCheck(this, AddEventsMixin);
73
-
74
- _this = _super.call(this, props);
75
- _this.state = {};
76
- _this.getEventState = Events.getEventState.bind(_assertThisInitialized(_this));
77
- _this.getScopedEvents = Events.getScopedEvents.bind(_assertThisInitialized(_this));
78
-
79
- _this.getEvents = function (p, target, eventKey) {
80
- return Events.getEvents.call(_assertThisInitialized(_this), p, target, eventKey, _this.getScopedEvents);
81
- };
82
-
83
- _this.externalMutations = _this.getExternalMutations(_this.props);
84
- _this.calculatedState = _this.getStateChanges(_this.props);
85
- _this.globalEvents = {};
86
- _this.prevGlobalEventKeys = [];
87
- _this.boundGlobalEvents = {};
88
-
89
- _this.cacheValues(_this.getCalculatedValues(props));
90
-
91
- return _this;
66
+ class AddEventsMixin extends WrappedComponent {
67
+ constructor(props) {
68
+ super(props);
69
+ this.cacheValues(this.getCalculatedValues(props));
92
70
  }
93
-
94
- _createClass(AddEventsMixin, [{
95
- key: "shouldComponentUpdate",
96
- value: function shouldComponentUpdate(nextProps) {
97
- var externalMutations = this.getExternalMutations(nextProps); // @ts-expect-error "Property 'animating' does not exist on type EventMixinCommonProps"
98
-
99
- var animating = this.props.animating || this.props.animate;
100
- var newMutation = !isEqual(externalMutations, this.externalMutations);
101
-
102
- if (animating || newMutation) {
103
- this.cacheValues(this.getCalculatedValues(nextProps));
104
- this.externalMutations = externalMutations;
105
- this.applyExternalMutations(nextProps, externalMutations);
106
- return true;
107
- }
108
-
109
- var calculatedState = this.getStateChanges(nextProps);
110
-
111
- if (!isEqual(this.calculatedState, calculatedState)) {
112
- this.cacheValues(this.getCalculatedValues(nextProps));
113
- return true;
114
- }
115
-
116
- if (!isEqual(this.props, nextProps)) {
117
- this.cacheValues(this.getCalculatedValues(nextProps));
118
- return true;
119
- }
120
-
121
- return false;
122
- }
123
- }, {
124
- key: "componentDidMount",
125
- value: function componentDidMount() {
126
- var _this2 = this;
127
-
128
- var globalEventKeys = Object.keys(this.globalEvents);
129
- globalEventKeys.forEach(function (key) {
130
- return _this2.addGlobalListener(key);
131
- });
132
- this.prevGlobalEventKeys = globalEventKeys;
133
- }
134
- }, {
135
- key: "componentDidUpdate",
136
- value: function componentDidUpdate(prevProps) {
137
- var _this3 = this;
138
-
139
- var calculatedState = this.getStateChanges(prevProps);
140
- this.calculatedState = calculatedState;
141
- var globalEventKeys = Object.keys(this.globalEvents);
142
- var removedGlobalEventKeys = difference(this.prevGlobalEventKeys, globalEventKeys);
143
- removedGlobalEventKeys.forEach(function (key) {
144
- return _this3.removeGlobalListener(key);
145
- });
146
- var addedGlobalEventKeys = difference(globalEventKeys, this.prevGlobalEventKeys);
147
- addedGlobalEventKeys.forEach(function (key) {
148
- return _this3.addGlobalListener(key);
149
- });
150
- this.prevGlobalEventKeys = globalEventKeys;
71
+ state = {};
72
+ getEventState = Events.getEventState.bind(this);
73
+ getScopedEvents = Events.getScopedEvents.bind(this);
74
+ getEvents = (p, target, eventKey) => {
75
+ return Events.getEvents.call(this, p, target, eventKey, this.getScopedEvents);
76
+ };
77
+ externalMutations = this.getExternalMutations(this.props);
78
+ calculatedState = this.getStateChanges(this.props);
79
+ globalEvents = {};
80
+ prevGlobalEventKeys = [];
81
+ boundGlobalEvents = {};
82
+ shouldComponentUpdate(nextProps) {
83
+ const externalMutations = this.getExternalMutations(nextProps);
84
+ // @ts-expect-error "Property 'animating' does not exist on type EventMixinCommonProps"
85
+ const animating = this.props.animating || this.props.animate;
86
+ const newMutation = !isEqual(externalMutations, this.externalMutations);
87
+ if (animating || newMutation) {
88
+ this.cacheValues(this.getCalculatedValues(nextProps));
89
+ this.externalMutations = externalMutations;
90
+ this.applyExternalMutations(nextProps, externalMutations);
91
+ return true;
151
92
  }
152
- }, {
153
- key: "componentWillUnmount",
154
- value: function componentWillUnmount() {
155
- var _this4 = this;
156
-
157
- this.prevGlobalEventKeys.forEach(function (key) {
158
- return _this4.removeGlobalListener(key);
159
- });
93
+ const calculatedState = this.getStateChanges(nextProps);
94
+ if (!isEqual(this.calculatedState, calculatedState)) {
95
+ this.cacheValues(this.getCalculatedValues(nextProps));
96
+ return true;
160
97
  }
161
- }, {
162
- key: "addGlobalListener",
163
- value: function addGlobalListener(key) {
164
- var _this5 = this;
165
-
166
- var boundListener = function (event) {
167
- var listener = _this5.globalEvents[key];
168
- return listener && listener(Events.emulateReactEvent(event));
169
- };
170
-
171
- this.boundGlobalEvents[key] = boundListener;
172
- window.addEventListener(Events.getGlobalEventNameFromKey(key), boundListener);
98
+ if (!isEqual(this.props, nextProps)) {
99
+ this.cacheValues(this.getCalculatedValues(nextProps));
100
+ return true;
173
101
  }
174
- }, {
175
- key: "removeGlobalListener",
176
- value: function removeGlobalListener(key) {
177
- window.removeEventListener(Events.getGlobalEventNameFromKey(key), this.boundGlobalEvents[key]);
178
- } // compile all state changes from own and parent state. Order doesn't matter, as any state
179
- // state change should trigger a re-render
180
-
181
- }, {
182
- key: "getStateChanges",
183
- value: function getStateChanges(props) {
184
- var _this6 = this;
185
-
186
- if (!this.hasEvents) {
187
- return {};
188
- }
189
-
190
- var getState = function (key, type) {
191
- var result = _defaults({}, _this6.getEventState(key, type), _this6.getSharedEventState(key, type));
192
-
193
- return _isEmpty(result) ? undefined : result;
194
- };
195
-
196
- var components = options.components || defaultComponents;
197
- var stateChanges = components.map(function (component) {
198
- if (!props.standalone && component.name === "parent") {
199
- // don't check for changes on parent props for non-standalone components
200
- return undefined;
201
- }
102
+ return false;
103
+ }
104
+ componentDidMount() {
105
+ const globalEventKeys = Object.keys(this.globalEvents);
106
+ globalEventKeys.forEach(key => this.addGlobalListener(key));
107
+ this.prevGlobalEventKeys = globalEventKeys;
108
+ }
109
+ componentDidUpdate(prevProps) {
110
+ const calculatedState = this.getStateChanges(prevProps);
111
+ this.calculatedState = calculatedState;
112
+ const globalEventKeys = Object.keys(this.globalEvents);
113
+ const removedGlobalEventKeys = difference(this.prevGlobalEventKeys, globalEventKeys);
114
+ removedGlobalEventKeys.forEach(key => this.removeGlobalListener(key));
115
+ const addedGlobalEventKeys = difference(globalEventKeys, this.prevGlobalEventKeys);
116
+ addedGlobalEventKeys.forEach(key => this.addGlobalListener(key));
117
+ this.prevGlobalEventKeys = globalEventKeys;
118
+ }
119
+ componentWillUnmount() {
120
+ this.prevGlobalEventKeys.forEach(key => this.removeGlobalListener(key));
121
+ }
122
+ addGlobalListener(key) {
123
+ const boundListener = event => {
124
+ const listener = this.globalEvents[key];
125
+ return listener && listener(Events.emulateReactEvent(event));
126
+ };
127
+ this.boundGlobalEvents[key] = boundListener;
128
+ window.addEventListener(Events.getGlobalEventNameFromKey(key), boundListener);
129
+ }
130
+ removeGlobalListener(key) {
131
+ window.removeEventListener(Events.getGlobalEventNameFromKey(key), this.boundGlobalEvents[key]);
132
+ }
202
133
 
203
- return component.index !== undefined ? getState(component.index, component.name) : _this6.dataKeys.map(function (key) {
204
- return getState(key, component.name);
205
- }).filter(Boolean);
206
- }).filter(Boolean);
207
- return stateChanges;
134
+ // compile all state changes from own and parent state. Order doesn't matter, as any state
135
+ // state change should trigger a re-render
136
+ getStateChanges(props) {
137
+ if (!this.hasEvents) {
138
+ return {};
208
139
  }
209
- }, {
210
- key: "applyExternalMutations",
211
- value: function applyExternalMutations(props, externalMutations) {
212
- if (!_isEmpty(externalMutations)) {
213
- var callbacks = props.externalEventMutations.reduce(function (memo, mutation) {
214
- return isFunction(mutation.callback) ? memo.concat(mutation.callback) : memo;
215
- }, []);
216
- var compiledCallbacks = callbacks.length ? function () {
217
- callbacks.forEach(function (c) {
218
- return c();
219
- });
220
- } : undefined;
221
- this.setState(externalMutations, compiledCallbacks);
140
+ const getState = (key, type) => {
141
+ const result = _defaults({}, this.getEventState(key, type), this.getSharedEventState(key, type));
142
+ return _isEmpty(result) ? undefined : result;
143
+ };
144
+ const components = options.components || defaultComponents;
145
+ const stateChanges = components.map(component => {
146
+ if (!props.standalone && component.name === "parent") {
147
+ // don't check for changes on parent props for non-standalone components
148
+ return undefined;
222
149
  }
150
+ return component.index !== undefined ? getState(component.index, component.name) : this.dataKeys.map(key => getState(key, component.name)).filter(Boolean);
151
+ }).filter(Boolean);
152
+ return stateChanges;
153
+ }
154
+ applyExternalMutations(props, externalMutations) {
155
+ if (!_isEmpty(externalMutations)) {
156
+ const callbacks = props.externalEventMutations.reduce((memo, mutation) => isFunction(mutation.callback) ? memo.concat(mutation.callback) : memo, []);
157
+ const compiledCallbacks = callbacks.length ? () => {
158
+ callbacks.forEach(c => c());
159
+ } : undefined;
160
+ this.setState(externalMutations, compiledCallbacks);
223
161
  }
224
- }, {
225
- key: "getCalculatedValues",
226
- value: function getCalculatedValues(props) {
227
- var sharedEvents = props.sharedEvents;
228
- var components = WrappedComponent.expectedComponents;
229
- var componentEvents = Events.getComponentEvents(props, components);
230
- var getSharedEventState = sharedEvents && isFunction(sharedEvents.getEventState) ? sharedEvents.getEventState : function () {
231
- return undefined;
232
- };
233
- var baseProps = this.getBaseProps(props, getSharedEventState);
234
- var dataKeys = Object.keys(baseProps).filter(function (key) {
235
- return key !== "parent";
236
- });
237
- var hasEvents = props.events || props.sharedEvents || componentEvents;
238
- var events = this.getAllEvents(props);
239
- return {
240
- componentEvents: componentEvents,
241
- getSharedEventState: getSharedEventState,
242
- baseProps: baseProps,
243
- dataKeys: dataKeys,
244
- hasEvents: hasEvents,
245
- events: events
246
- };
162
+ }
163
+ getCalculatedValues(props) {
164
+ const {
165
+ sharedEvents
166
+ } = props;
167
+ const components = WrappedComponent.expectedComponents;
168
+ const componentEvents = Events.getComponentEvents(props, components);
169
+ const getSharedEventState = sharedEvents && isFunction(sharedEvents.getEventState) ? sharedEvents.getEventState : () => undefined;
170
+ const baseProps = this.getBaseProps(props, getSharedEventState);
171
+ const dataKeys = Object.keys(baseProps).filter(key => key !== "parent");
172
+ const hasEvents = props.events || props.sharedEvents || componentEvents;
173
+ const events = this.getAllEvents(props);
174
+ return {
175
+ componentEvents,
176
+ getSharedEventState,
177
+ baseProps,
178
+ dataKeys,
179
+ hasEvents,
180
+ events
181
+ };
182
+ }
183
+ getExternalMutations(props) {
184
+ const {
185
+ sharedEvents,
186
+ externalEventMutations
187
+ } = props;
188
+ return _isEmpty(externalEventMutations) || sharedEvents ? undefined : Events.getExternalMutations(externalEventMutations, this.baseProps, this.state);
189
+ }
190
+ cacheValues(obj) {
191
+ Object.keys(obj).forEach(key => {
192
+ this[key] = obj[key];
193
+ });
194
+ }
195
+ getBaseProps(props, getSharedEventState) {
196
+ const getSharedEventStateFunction = getSharedEventState || this.getSharedEventState.bind(this);
197
+ const sharedParentState = getSharedEventStateFunction("parent", "parent");
198
+ const parentState = this.getEventState("parent", "parent");
199
+ const baseParentProps = _defaults({}, parentState, sharedParentState);
200
+ const parentPropsList = baseParentProps.parentControlledProps;
201
+ const parentProps = parentPropsList ? _pick(baseParentProps, parentPropsList) : {};
202
+ const modifiedProps = _defaults({}, parentProps, props);
203
+ return typeof WrappedComponent.getBaseProps === "function" ? WrappedComponent.getBaseProps(modifiedProps) : {};
204
+ }
205
+ getAllEvents(props) {
206
+ if (Array.isArray(this.componentEvents)) {
207
+ return Array.isArray(props.events) ? this.componentEvents.concat(...props.events) : this.componentEvents;
247
208
  }
248
- }, {
249
- key: "getExternalMutations",
250
- value: function getExternalMutations(props) {
251
- var sharedEvents = props.sharedEvents,
252
- externalEventMutations = props.externalEventMutations;
253
- return _isEmpty(externalEventMutations) || sharedEvents ? undefined : Events.getExternalMutations(externalEventMutations, this.baseProps, this.state);
209
+ return props.events;
210
+ }
211
+ getComponentProps(component, type, index) {
212
+ const name = this.props.name || WrappedComponent.role;
213
+ const key = this.dataKeys && this.dataKeys[index] || index;
214
+ const id = `${name}-${type}-${key}`;
215
+ const baseProps = this.baseProps[key] && this.baseProps[key][type] || this.baseProps[key];
216
+ if (!baseProps && !this.hasEvents) {
217
+ return undefined;
254
218
  }
255
- }, {
256
- key: "cacheValues",
257
- value: function cacheValues(obj) {
258
- var _this7 = this;
259
-
260
- Object.keys(obj).forEach(function (key) {
261
- _this7[key] = obj[key];
219
+ const currentProps = component && typeof component === "object" && "props" in component ? component.props : undefined;
220
+ if (this.hasEvents) {
221
+ const baseEvents = this.getEvents(this.props, type, key);
222
+ const componentProps = _defaults({
223
+ index,
224
+ key: id
225
+ }, this.getEventState(key, type), this.getSharedEventState(key, type), currentProps, baseProps, {
226
+ id
227
+ });
228
+ const events = _defaults({}, Events.getPartialEvents(baseEvents, key, componentProps), componentProps.events);
229
+ return Object.assign({}, componentProps, {
230
+ events
262
231
  });
263
232
  }
264
- }, {
265
- key: "getBaseProps",
266
- value: function getBaseProps(props, getSharedEventState) {
267
- var getSharedEventStateFunction = getSharedEventState || this.getSharedEventState.bind(this);
268
- var sharedParentState = getSharedEventStateFunction("parent", "parent");
269
- var parentState = this.getEventState("parent", "parent");
270
-
271
- var baseParentProps = _defaults({}, parentState, sharedParentState);
272
-
273
- var parentPropsList = baseParentProps.parentControlledProps;
274
- var parentProps = parentPropsList ? _pick(baseParentProps, parentPropsList) : {};
275
-
276
- var modifiedProps = _defaults({}, parentProps, props);
277
-
278
- return typeof WrappedComponent.getBaseProps === "function" ? WrappedComponent.getBaseProps(modifiedProps) : {};
233
+ return _defaults({
234
+ index,
235
+ key: id
236
+ }, currentProps, baseProps, {
237
+ id
238
+ });
239
+ }
240
+ renderContainer(component, children) {
241
+ const isContainer = component.type && component.type.role === "container";
242
+ const parentProps = isContainer ? this.getComponentProps(component, "parent", "parent") : {};
243
+ if (parentProps.events) {
244
+ this.globalEvents = Events.getGlobalEvents(parentProps.events);
245
+ parentProps.events = Events.omitGlobalEvents(parentProps.events);
279
246
  }
280
- }, {
281
- key: "getAllEvents",
282
- value: function getAllEvents(props) {
283
- if (Array.isArray(this.componentEvents)) {
284
- var _this$componentEvents;
247
+ return /*#__PURE__*/React.cloneElement(component, parentProps, children);
248
+ }
249
+ animateComponent(props, defaultAnimationWhitelist) {
250
+ const animationWhitelist = typeof props.animate === "object" && props.animate?.animationWhitelist || defaultAnimationWhitelist;
251
+ const Comp = this.constructor;
252
+ return /*#__PURE__*/React.createElement(VictoryTransition, {
253
+ animate: props.animate,
254
+ animationWhitelist: animationWhitelist
255
+ }, /*#__PURE__*/React.createElement(Comp, props));
256
+ }
285
257
 
286
- return Array.isArray(props.events) ? (_this$componentEvents = this.componentEvents).concat.apply(_this$componentEvents, _toConsumableArray(props.events)) : this.componentEvents;
258
+ // Used by `VictoryLine` and `VictoryArea`
259
+ renderContinuousData(props) {
260
+ const {
261
+ dataComponent,
262
+ labelComponent,
263
+ groupComponent
264
+ } = props;
265
+ const dataKeys = this.dataKeys.filter(value => value !== "all");
266
+ const labelComponents = dataKeys.reduce((memo, key) => {
267
+ let newMemo = memo;
268
+ const labelProps = this.getComponentProps(labelComponent, "labels", key);
269
+ if (labelProps && labelProps.text !== undefined && labelProps.text !== null) {
270
+ newMemo = newMemo.concat( /*#__PURE__*/React.cloneElement(labelComponent, labelProps));
287
271
  }
288
-
289
- return props.events;
272
+ return newMemo;
273
+ }, []);
274
+ const dataProps = this.getComponentProps(dataComponent, "data", "all");
275
+ const children = [/*#__PURE__*/React.cloneElement(dataComponent, dataProps), ...labelComponents];
276
+ return this.renderContainer(groupComponent, children);
277
+ }
278
+ renderData(props, shouldRenderDatum) {
279
+ if (shouldRenderDatum === void 0) {
280
+ shouldRenderDatum = datumHasXandY;
290
281
  }
291
- }, {
292
- key: "getComponentProps",
293
- value: function getComponentProps(component, type, index) {
294
- var name = this.props.name || WrappedComponent.role;
295
- var key = this.dataKeys && this.dataKeys[index] || index;
296
- var id = "".concat(name, "-").concat(type, "-").concat(key);
297
- var baseProps = this.baseProps[key] && this.baseProps[key][type] || this.baseProps[key];
298
-
299
- if (!baseProps && !this.hasEvents) {
300
- return undefined;
282
+ const {
283
+ dataComponent,
284
+ labelComponent,
285
+ groupComponent
286
+ } = props;
287
+ const dataComponents = this.dataKeys.reduce((validDataComponents, _dataKey, index) => {
288
+ const dataProps = this.getComponentProps(dataComponent, "data", index);
289
+ if (shouldRenderDatum(dataProps.datum)) {
290
+ validDataComponents.push( /*#__PURE__*/React.cloneElement(dataComponent, dataProps));
301
291
  }
302
-
303
- var currentProps = component && typeof component === "object" && "props" in component ? component.props : undefined;
304
-
305
- if (this.hasEvents) {
306
- var baseEvents = this.getEvents(this.props, type, key);
307
-
308
- var componentProps = _defaults({
309
- index: index,
310
- key: id
311
- }, this.getEventState(key, type), this.getSharedEventState(key, type), currentProps, baseProps, {
312
- id: id
313
- });
314
-
315
- var events = _defaults({}, Events.getPartialEvents(baseEvents, key, componentProps), componentProps.events);
316
-
317
- return Object.assign({}, componentProps, {
318
- events: events
319
- });
292
+ return validDataComponents;
293
+ }, []);
294
+ const labelComponents = this.dataKeys.map((_dataKey, index) => {
295
+ const labelProps = this.getComponentProps(labelComponent, "labels", index);
296
+ if (labelProps.text !== undefined && labelProps.text !== null) {
297
+ return /*#__PURE__*/React.cloneElement(labelComponent, labelProps);
320
298
  }
321
-
322
- return _defaults({
323
- index: index,
324
- key: id
325
- }, currentProps, baseProps, {
326
- id: id
327
- });
328
- }
329
- }, {
330
- key: "renderContainer",
331
- value: function renderContainer(component, children) {
332
- var isContainer = component.type && component.type.role === "container";
333
- var parentProps = isContainer ? this.getComponentProps(component, "parent", "parent") : {};
334
-
335
- if (parentProps.events) {
336
- this.globalEvents = Events.getGlobalEvents(parentProps.events);
337
- parentProps.events = Events.omitGlobalEvents(parentProps.events);
338
- }
339
-
340
- return /*#__PURE__*/React.cloneElement(component, parentProps, children);
341
- }
342
- }, {
343
- key: "animateComponent",
344
- value: function animateComponent(props, defaultAnimationWhitelist) {
345
- var _props$animate;
346
-
347
- var animationWhitelist = typeof props.animate === "object" && ((_props$animate = props.animate) === null || _props$animate === void 0 ? void 0 : _props$animate.animationWhitelist) || defaultAnimationWhitelist;
348
- var Comp = this.constructor;
349
- return /*#__PURE__*/React.createElement(VictoryTransition, {
350
- animate: props.animate,
351
- animationWhitelist: animationWhitelist
352
- }, /*#__PURE__*/React.createElement(Comp, props));
353
- } // Used by `VictoryLine` and `VictoryArea`
354
-
355
- }, {
356
- key: "renderContinuousData",
357
- value: function renderContinuousData(props) {
358
- var _this8 = this;
359
-
360
- var dataComponent = props.dataComponent,
361
- labelComponent = props.labelComponent,
362
- groupComponent = props.groupComponent;
363
- var dataKeys = this.dataKeys.filter(function (value) {
364
- return value !== "all";
365
- });
366
- var labelComponents = dataKeys.reduce(function (memo, key) {
367
- var newMemo = memo;
368
-
369
- var labelProps = _this8.getComponentProps(labelComponent, "labels", key);
370
-
371
- if (labelProps && labelProps.text !== undefined && labelProps.text !== null) {
372
- newMemo = newMemo.concat( /*#__PURE__*/React.cloneElement(labelComponent, labelProps));
373
- }
374
-
375
- return newMemo;
376
- }, []);
377
- var dataProps = this.getComponentProps(dataComponent, "data", "all");
378
- var children = [/*#__PURE__*/React.cloneElement(dataComponent, dataProps)].concat(_toConsumableArray(labelComponents));
379
- return this.renderContainer(groupComponent, children);
380
- }
381
- }, {
382
- key: "renderData",
383
- value: function renderData(props) {
384
- var _this9 = this;
385
-
386
- var shouldRenderDatum = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : datumHasXandY;
387
- var dataComponent = props.dataComponent,
388
- labelComponent = props.labelComponent,
389
- groupComponent = props.groupComponent;
390
- var dataComponents = this.dataKeys.reduce(function (validDataComponents, _dataKey, index) {
391
- var dataProps = _this9.getComponentProps(dataComponent, "data", index);
392
-
393
- if (shouldRenderDatum(dataProps.datum)) {
394
- validDataComponents.push( /*#__PURE__*/React.cloneElement(dataComponent, dataProps));
395
- }
396
-
397
- return validDataComponents;
398
- }, []);
399
- var labelComponents = this.dataKeys.map(function (_dataKey, index) {
400
- var labelProps = _this9.getComponentProps(labelComponent, "labels", index);
401
-
402
- if (labelProps.text !== undefined && labelProps.text !== null) {
403
- return /*#__PURE__*/React.cloneElement(labelComponent, labelProps);
404
- }
405
-
406
- return undefined;
407
- }).filter(Boolean);
408
- var children = [].concat(_toConsumableArray(dataComponents), _toConsumableArray(labelComponents));
409
- return this.renderContainer(groupComponent, children);
410
- }
411
- }]);
412
-
413
- return AddEventsMixin;
414
- }(WrappedComponent);
415
-
299
+ return undefined;
300
+ }).filter(Boolean);
301
+ const children = [...dataComponents, ...labelComponents];
302
+ return this.renderContainer(groupComponent, children);
303
+ }
304
+ }
416
305
  return AddEventsMixin;
417
306
  }