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