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