victory-core 37.3.1 → 37.3.3
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 +20 -0
- package/dist/victory-core.js +436 -405
- package/dist/victory-core.min.js +1 -1
- package/es/types/callbacks.d.ts +11 -11
- package/es/types/prop-types.d.ts +28 -28
- package/es/victory-animation/util.js +7 -7
- package/es/victory-animation/victory-animation.d.ts +3 -3
- package/es/victory-clip-container/victory-clip-container.d.ts +6 -1
- package/es/victory-clip-container/victory-clip-container.js +20 -12
- package/es/victory-container/victory-container.js +5 -5
- package/es/victory-label/victory-label.d.ts +3 -3
- package/es/victory-label/victory-label.js +12 -16
- package/es/victory-portal/victory-portal.js +4 -4
- package/es/victory-primitives/arc.js +2 -2
- package/es/victory-primitives/background.js +2 -2
- package/es/victory-primitives/border.js +2 -2
- package/es/victory-primitives/line-segment.js +2 -2
- package/es/victory-primitives/point.js +2 -2
- package/es/victory-primitives/tspan.d.ts +0 -1
- package/es/victory-primitives/types.d.ts +1 -1
- package/es/victory-primitives/whisker.d.ts +1 -1
- package/es/victory-primitives/whisker.js +2 -2
- package/es/victory-theme/types.d.ts +11 -11
- package/es/victory-transition/victory-transition.d.ts +1 -1
- package/es/victory-transition/victory-transition.js +8 -8
- package/es/victory-util/add-events.d.ts +8 -8
- package/es/victory-util/add-events.js +14 -14
- package/es/victory-util/axis.js +12 -12
- package/es/victory-util/data.js +16 -20
- package/es/victory-util/domain.js +13 -16
- package/es/victory-util/events.d.ts +5 -5
- package/es/victory-util/events.js +17 -23
- package/es/victory-util/helpers.d.ts +94 -19
- package/es/victory-util/helpers.js +95 -50
- package/es/victory-util/hooks/use-animation-state.d.ts +2 -2
- package/es/victory-util/hooks/use-animation-state.js +4 -4
- package/es/victory-util/label-helpers.d.ts +4 -3
- package/es/victory-util/label-helpers.js +3 -3
- package/es/victory-util/line-helpers.d.ts +1 -1
- package/es/victory-util/log.js +3 -2
- package/es/victory-util/merge-refs.d.ts +2 -2
- package/es/victory-util/scale.js +2 -3
- package/es/victory-util/selection.d.ts +3 -3
- package/es/victory-util/textsize.js +7 -5
- package/es/victory-util/timer.d.ts +1 -1
- package/es/victory-util/transitions.d.ts +1 -1
- package/es/victory-util/transitions.js +15 -19
- package/es/victory-util/type-helpers.d.ts +0 -1
- package/es/victory-util/type-helpers.js +0 -5
- package/es/victory-util/user-props.d.ts +2 -2
- package/es/victory-util/wrapper.js +12 -13
- package/lib/types/callbacks.d.ts +11 -11
- package/lib/types/prop-types.d.ts +28 -28
- package/lib/victory-animation/util.js +7 -7
- package/lib/victory-animation/victory-animation.d.ts +3 -3
- package/lib/victory-clip-container/victory-clip-container.d.ts +6 -1
- package/lib/victory-clip-container/victory-clip-container.js +20 -12
- package/lib/victory-container/victory-container.js +6 -6
- package/lib/victory-label/victory-label.d.ts +3 -3
- package/lib/victory-label/victory-label.js +12 -16
- package/lib/victory-portal/victory-portal.js +5 -5
- package/lib/victory-primitives/arc.js +2 -2
- package/lib/victory-primitives/background.js +2 -2
- package/lib/victory-primitives/border.js +2 -2
- package/lib/victory-primitives/line-segment.js +2 -2
- package/lib/victory-primitives/point.js +2 -2
- package/lib/victory-primitives/tspan.d.ts +0 -1
- package/lib/victory-primitives/types.d.ts +1 -1
- package/lib/victory-primitives/whisker.d.ts +1 -1
- package/lib/victory-primitives/whisker.js +2 -2
- package/lib/victory-theme/types.d.ts +11 -11
- package/lib/victory-transition/victory-transition.d.ts +1 -1
- package/lib/victory-transition/victory-transition.js +8 -8
- package/lib/victory-util/add-events.d.ts +8 -8
- package/lib/victory-util/add-events.js +14 -14
- package/lib/victory-util/axis.js +12 -12
- package/lib/victory-util/data.js +16 -21
- package/lib/victory-util/domain.js +13 -17
- package/lib/victory-util/events.d.ts +5 -5
- package/lib/victory-util/events.js +17 -24
- package/lib/victory-util/helpers.d.ts +94 -19
- package/lib/victory-util/helpers.js +96 -52
- package/lib/victory-util/hooks/use-animation-state.d.ts +2 -2
- package/lib/victory-util/hooks/use-animation-state.js +4 -4
- package/lib/victory-util/label-helpers.d.ts +4 -3
- package/lib/victory-util/label-helpers.js +3 -5
- package/lib/victory-util/line-helpers.d.ts +1 -1
- package/lib/victory-util/log.js +3 -2
- package/lib/victory-util/merge-refs.d.ts +2 -2
- package/lib/victory-util/scale.js +2 -4
- package/lib/victory-util/selection.d.ts +3 -3
- package/lib/victory-util/textsize.js +5 -5
- package/lib/victory-util/timer.d.ts +1 -1
- package/lib/victory-util/transitions.d.ts +1 -1
- package/lib/victory-util/transitions.js +15 -19
- package/lib/victory-util/type-helpers.d.ts +0 -1
- package/lib/victory-util/type-helpers.js +0 -6
- package/lib/victory-util/user-props.d.ts +2 -2
- package/lib/victory-util/wrapper.js +12 -13
- package/package.json +6 -38
- package/src/victory-animation/util.ts +4 -2
- package/src/victory-clip-container/victory-clip-container.tsx +26 -11
- package/src/victory-container/victory-container.tsx +4 -4
- package/src/victory-label/victory-label.tsx +5 -3
- package/src/victory-portal/victory-portal.tsx +3 -1
- package/src/victory-primitives/arc.tsx +1 -1
- package/src/victory-primitives/background.tsx +1 -1
- package/src/victory-primitives/border.tsx +1 -1
- package/src/victory-primitives/line-segment.tsx +1 -1
- package/src/victory-primitives/point.tsx +3 -3
- package/src/victory-primitives/whisker.tsx +1 -1
- package/src/victory-transition/victory-transition.tsx +5 -3
- package/src/victory-util/add-events.tsx +6 -3
- package/src/victory-util/axis.tsx +8 -4
- package/src/victory-util/common-props.tsx +3 -3
- package/src/victory-util/data.ts +9 -13
- package/src/victory-util/domain.ts +8 -6
- package/src/victory-util/events.ts +18 -13
- package/src/victory-util/helpers.ts +155 -40
- package/src/victory-util/hooks/use-animation-state.ts +1 -1
- package/src/victory-util/label-helpers.ts +1 -2
- package/src/victory-util/log.ts +3 -2
- package/src/victory-util/merge-refs.ts +2 -0
- package/src/victory-util/scale.ts +1 -2
- package/src/victory-util/textsize.ts +2 -1
- package/src/victory-util/transitions.ts +6 -6
- package/src/victory-util/type-helpers.ts +0 -5
- package/src/victory-util/user-props.ts +1 -1
- package/src/victory-util/wrapper.tsx +5 -2
package/lib/victory-util/data.js
CHANGED
|
@@ -14,15 +14,15 @@ exports.getStringsFromAxes = getStringsFromAxes;
|
|
|
14
14
|
exports.getStringsFromCategories = getStringsFromCategories;
|
|
15
15
|
exports.getStringsFromData = getStringsFromData;
|
|
16
16
|
exports.isDataComponent = isDataComponent;
|
|
17
|
-
var _omitBy2 = _interopRequireDefault(require("lodash/omitBy"));
|
|
18
|
-
var _isUndefined2 = _interopRequireDefault(require("lodash/isUndefined"));
|
|
19
|
-
var _isEqual2 = _interopRequireDefault(require("lodash/isEqual"));
|
|
20
|
-
var _isEmpty2 = _interopRequireDefault(require("lodash/isEmpty"));
|
|
21
|
-
var _orderBy2 = _interopRequireDefault(require("lodash/orderBy"));
|
|
22
|
-
var _property2 = _interopRequireDefault(require("lodash/property"));
|
|
23
|
-
var _isPlainObject2 = _interopRequireDefault(require("lodash/isPlainObject"));
|
|
24
|
-
var _uniq2 = _interopRequireDefault(require("lodash/uniq"));
|
|
25
17
|
var _react = _interopRequireDefault(require("react"));
|
|
18
|
+
var _isEmpty = _interopRequireDefault(require("lodash/isEmpty"));
|
|
19
|
+
var _isEqual = _interopRequireDefault(require("lodash/isEqual"));
|
|
20
|
+
var _isPlainObject = _interopRequireDefault(require("lodash/isPlainObject"));
|
|
21
|
+
var _isUndefined = _interopRequireDefault(require("lodash/isUndefined"));
|
|
22
|
+
var _omitBy = _interopRequireDefault(require("lodash/omitBy"));
|
|
23
|
+
var _orderBy = _interopRequireDefault(require("lodash/orderBy"));
|
|
24
|
+
var _property = _interopRequireDefault(require("lodash/property"));
|
|
25
|
+
var _uniq = _interopRequireDefault(require("lodash/uniq"));
|
|
26
26
|
var Helpers = _interopRequireWildcard(require("./helpers"));
|
|
27
27
|
var Collection = _interopRequireWildcard(require("./collection"));
|
|
28
28
|
var Scale = _interopRequireWildcard(require("./scale"));
|
|
@@ -30,8 +30,6 @@ var Immutable = _interopRequireWildcard(require("./immutable"));
|
|
|
30
30
|
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); }
|
|
31
31
|
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; }
|
|
32
32
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
33
|
-
/* eslint-disable no-use-before-define */
|
|
34
|
-
|
|
35
33
|
// Private Functions
|
|
36
34
|
|
|
37
35
|
function parseDatum(datum) {
|
|
@@ -47,7 +45,7 @@ function getLength(data) {
|
|
|
47
45
|
|
|
48
46
|
// Returns generated data for a given axis based on domain and sample from props
|
|
49
47
|
function generateDataArray(props, axis) {
|
|
50
|
-
const propsDomain = (0,
|
|
48
|
+
const propsDomain = (0, _isPlainObject.default)(props.domain) ? props.domain[axis] : props.domain;
|
|
51
49
|
const domain = propsDomain || Scale.getBaseScale(props, axis).domain();
|
|
52
50
|
const samples = props.samples || 1;
|
|
53
51
|
const domainMax = Math.max(...domain);
|
|
@@ -72,7 +70,7 @@ function sortData(dataset, sortKey, sortOrder) {
|
|
|
72
70
|
formattedSortKey = `_${sortKey}`;
|
|
73
71
|
}
|
|
74
72
|
const order = sortOrder === "ascending" ? "asc" : "desc";
|
|
75
|
-
return (0,
|
|
73
|
+
return (0, _orderBy.default)(dataset, formattedSortKey, order);
|
|
76
74
|
}
|
|
77
75
|
|
|
78
76
|
// This method will remove data points that break certain scales. (log scale only)
|
|
@@ -116,7 +114,7 @@ function getEventKey(key) {
|
|
|
116
114
|
return () => undefined;
|
|
117
115
|
}
|
|
118
116
|
// otherwise, assume it is an array index, property key or path (_.property handles all three)
|
|
119
|
-
return (0,
|
|
117
|
+
return (0, _property.default)(key);
|
|
120
118
|
}
|
|
121
119
|
|
|
122
120
|
// Returns data with an eventKey prop added to each datum
|
|
@@ -151,8 +149,6 @@ function formatDataFromDomain(dataset, domain, defaultBaseline) {
|
|
|
151
149
|
const isUnderMinY = underMin(minDomainY);
|
|
152
150
|
const isOverMaxX = overMax(maxDomainX);
|
|
153
151
|
const isOverMaxY = overMax(maxDomainY);
|
|
154
|
-
|
|
155
|
-
// eslint-disable-next-line complexity
|
|
156
152
|
return dataset.map(datum => {
|
|
157
153
|
let {
|
|
158
154
|
_x,
|
|
@@ -177,12 +173,12 @@ function formatDataFromDomain(dataset, domain, defaultBaseline) {
|
|
|
177
173
|
if (isUnderMinY(baseline) && !isUnderMinY(value)) _y0 = minDomainY;
|
|
178
174
|
// baseline and value with only baseline above max, set baseline to maxDomainY
|
|
179
175
|
if (isOverMaxY(baseline) && !isOverMaxY(value)) _y0 = maxDomainY;
|
|
180
|
-
return Object.assign({}, datum, (0,
|
|
176
|
+
return Object.assign({}, datum, (0, _omitBy.default)({
|
|
181
177
|
_x,
|
|
182
178
|
_y,
|
|
183
179
|
_y0,
|
|
184
180
|
_y1
|
|
185
|
-
},
|
|
181
|
+
}, _isUndefined.default));
|
|
186
182
|
});
|
|
187
183
|
}
|
|
188
184
|
|
|
@@ -196,7 +192,7 @@ function createStringMap(props, axis) {
|
|
|
196
192
|
const stringsFromAxes = getStringsFromAxes(props, axis);
|
|
197
193
|
const stringsFromCategories = getStringsFromCategories(props, axis);
|
|
198
194
|
const stringsFromData = getStringsFromData(props, axis);
|
|
199
|
-
const allStrings = (0,
|
|
195
|
+
const allStrings = (0, _uniq.default)([...stringsFromAxes, ...stringsFromCategories, ...stringsFromData]);
|
|
200
196
|
return allStrings.length === 0 ? null : allStrings.reduce((memo, string, index) => {
|
|
201
197
|
memo[string] = index + 1;
|
|
202
198
|
return memo;
|
|
@@ -252,7 +248,7 @@ function formatData(dataset, props, expectedKeys) {
|
|
|
252
248
|
memo[type] = createAccessor(type);
|
|
253
249
|
return memo;
|
|
254
250
|
}, {});
|
|
255
|
-
const preformattedData = (0,
|
|
251
|
+
const preformattedData = (0, _isEqual.default)(expectedKeys, defaultKeys) && props.x === "_x" && props.y === "_y" && props.y0 === "_y0";
|
|
256
252
|
let stringMap;
|
|
257
253
|
if (preformattedData === false) {
|
|
258
254
|
// stringMap is not required if the data is preformatted
|
|
@@ -263,7 +259,6 @@ function formatData(dataset, props, expectedKeys) {
|
|
|
263
259
|
};
|
|
264
260
|
}
|
|
265
261
|
const data = preformattedData ? dataset : dataset.reduce((dataArr, datum, index) => {
|
|
266
|
-
// eslint-disable-line complexity
|
|
267
262
|
const parsedDatum = parseDatum(datum);
|
|
268
263
|
const fallbackValues = {
|
|
269
264
|
x: index,
|
|
@@ -283,7 +278,7 @@ function formatData(dataset, props, expectedKeys) {
|
|
|
283
278
|
return memo;
|
|
284
279
|
}, {});
|
|
285
280
|
const formattedDatum = Object.assign({}, processedValues, parsedDatum);
|
|
286
|
-
if (!(0,
|
|
281
|
+
if (!(0, _isEmpty.default)(formattedDatum)) {
|
|
287
282
|
dataArr.push(formattedDatum);
|
|
288
283
|
}
|
|
289
284
|
return dataArr;
|
|
@@ -15,10 +15,10 @@ exports.getMaxFromProps = getMaxFromProps;
|
|
|
15
15
|
exports.getMinFromProps = getMinFromProps;
|
|
16
16
|
exports.getSymmetricDomain = getSymmetricDomain;
|
|
17
17
|
exports.isDomainComponent = isDomainComponent;
|
|
18
|
-
var _isDate2 = _interopRequireDefault(require("lodash/isDate"));
|
|
19
|
-
var _sortedUniq2 = _interopRequireDefault(require("lodash/sortedUniq"));
|
|
20
|
-
var _isPlainObject2 = _interopRequireDefault(require("lodash/isPlainObject"));
|
|
21
18
|
var _react = _interopRequireDefault(require("react"));
|
|
19
|
+
var _isDate = _interopRequireDefault(require("lodash/isDate"));
|
|
20
|
+
var _isPlainObject = _interopRequireDefault(require("lodash/isPlainObject"));
|
|
21
|
+
var _sortedUniq = _interopRequireDefault(require("lodash/sortedUniq"));
|
|
22
22
|
var Data = _interopRequireWildcard(require("./data"));
|
|
23
23
|
var Scale = _interopRequireWildcard(require("./scale"));
|
|
24
24
|
var Helpers = _interopRequireWildcard(require("./helpers"));
|
|
@@ -26,8 +26,6 @@ var Collection = _interopRequireWildcard(require("./collection"));
|
|
|
26
26
|
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); }
|
|
27
27
|
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; }
|
|
28
28
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
29
|
-
/* eslint-disable no-use-before-define */
|
|
30
|
-
|
|
31
29
|
// Private Methods
|
|
32
30
|
|
|
33
31
|
function cleanDomain(domain, props, axis) {
|
|
@@ -53,7 +51,7 @@ function getDomainPadding(props, axis) {
|
|
|
53
51
|
right: padding
|
|
54
52
|
};
|
|
55
53
|
};
|
|
56
|
-
return (0,
|
|
54
|
+
return (0, _isPlainObject.default)(props.domainPadding) ? formatPadding(props.domainPadding[axis]) : formatPadding(props.domainPadding);
|
|
57
55
|
}
|
|
58
56
|
function getFlatData(dataset, axis) {
|
|
59
57
|
const axisKey = `_${axis}`;
|
|
@@ -77,8 +75,6 @@ function getExtremeFromData(dataset, axis, type) {
|
|
|
77
75
|
}, initialValue);
|
|
78
76
|
return containsDate ? new Date(result) : result;
|
|
79
77
|
}
|
|
80
|
-
|
|
81
|
-
// eslint-disable-next-line max-statements
|
|
82
78
|
function padDomain(domain, props, axis) {
|
|
83
79
|
if (!props.domainPadding) {
|
|
84
80
|
return domain;
|
|
@@ -104,10 +100,10 @@ function padDomain(domain, props, axis) {
|
|
|
104
100
|
min: min.valueOf() - simplePadding.left,
|
|
105
101
|
max: max.valueOf() + simplePadding.right
|
|
106
102
|
};
|
|
107
|
-
const singleQuadrantDomainPadding = (0,
|
|
108
|
-
const addsQuadrants = min >= 0 && paddedDomain.min <= 0 || max <= 0 && paddedDomain.max >= 0;
|
|
103
|
+
const singleQuadrantDomainPadding = (0, _isPlainObject.default)(props.singleQuadrantDomainPadding) ? props.singleQuadrantDomainPadding[axis] : props.singleQuadrantDomainPadding;
|
|
104
|
+
const addsQuadrants = min.valueOf() >= 0 && paddedDomain.min <= 0 || max.valueOf() <= 0 && paddedDomain.max >= 0;
|
|
109
105
|
const adjust = (val, type) => {
|
|
110
|
-
const coerce = type === "min" && min >= 0 && val <= 0 || type === "max" && max <= 0 && val >= 0;
|
|
106
|
+
const coerce = type === "min" && min.valueOf() >= 0 && val <= 0 || type === "max" && max.valueOf() <= 0 && val >= 0;
|
|
111
107
|
return coerce ? 0 : val;
|
|
112
108
|
};
|
|
113
109
|
if (addsQuadrants && singleQuadrantDomainPadding !== false) {
|
|
@@ -276,7 +272,7 @@ function getDomainFromMinMax(min, max) {
|
|
|
276
272
|
function getDomainFromProps(props, axis) {
|
|
277
273
|
const minDomain = getMinFromProps(props, axis);
|
|
278
274
|
const maxDomain = getMaxFromProps(props, axis);
|
|
279
|
-
if ((0,
|
|
275
|
+
if ((0, _isPlainObject.default)(props.domain) && props.domain[axis]) {
|
|
280
276
|
return props.domain[axis];
|
|
281
277
|
} else if (Array.isArray(props.domain)) {
|
|
282
278
|
return props.domain;
|
|
@@ -327,10 +323,10 @@ function getDomainWithZero(props, axis) {
|
|
|
327
323
|
* @returns {Number|Date|undefined} the maxDomain based on props
|
|
328
324
|
*/
|
|
329
325
|
function getMaxFromProps(props, axis) {
|
|
330
|
-
if ((0,
|
|
326
|
+
if ((0, _isPlainObject.default)(props.maxDomain) && props.maxDomain[axis] !== undefined) {
|
|
331
327
|
return props.maxDomain[axis];
|
|
332
328
|
}
|
|
333
|
-
return typeof props.maxDomain === "number" || (0,
|
|
329
|
+
return typeof props.maxDomain === "number" || (0, _isDate.default)(props.maxDomain) ? props.maxDomain : undefined;
|
|
334
330
|
}
|
|
335
331
|
|
|
336
332
|
/**
|
|
@@ -340,10 +336,10 @@ function getMaxFromProps(props, axis) {
|
|
|
340
336
|
* @returns {Number|Date|undefined} the minDomain based on props
|
|
341
337
|
*/
|
|
342
338
|
function getMinFromProps(props, axis) {
|
|
343
|
-
if ((0,
|
|
339
|
+
if ((0, _isPlainObject.default)(props.minDomain) && props.minDomain[axis] !== undefined) {
|
|
344
340
|
return props.minDomain[axis];
|
|
345
341
|
}
|
|
346
|
-
return typeof props.minDomain === "number" || (0,
|
|
342
|
+
return typeof props.minDomain === "number" || (0, _isDate.default)(props.minDomain) ? props.minDomain : undefined;
|
|
347
343
|
}
|
|
348
344
|
|
|
349
345
|
/**
|
|
@@ -354,7 +350,7 @@ function getMinFromProps(props, axis) {
|
|
|
354
350
|
* @returns {Array} the symmetric domain
|
|
355
351
|
*/
|
|
356
352
|
function getSymmetricDomain(domain, values) {
|
|
357
|
-
const processedData = (0,
|
|
353
|
+
const processedData = (0, _sortedUniq.default)(values.sort((a, b) => a - b));
|
|
358
354
|
const step = processedData[1] - processedData[0];
|
|
359
355
|
return [domain[0], domain[1] + step];
|
|
360
356
|
}
|
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
|
|
1
|
+
import React from "react";
|
|
2
2
|
import type { EventMixinCalculatedValues } from "./add-events";
|
|
3
|
-
|
|
3
|
+
type ComponentEventKey = string | number;
|
|
4
4
|
export interface ComponentEvent {
|
|
5
5
|
target?: "parent" | string;
|
|
6
6
|
eventKey?: ComponentEventKey | ComponentEventKey[];
|
|
7
7
|
eventHandlers: ComponentEventHandlers;
|
|
8
8
|
}
|
|
9
|
-
export
|
|
9
|
+
export type ComponentEventName = string;
|
|
10
10
|
export interface ComponentEventHandlers {
|
|
11
11
|
[k: ComponentEventName]: ComponentEventHandler;
|
|
12
12
|
}
|
|
13
|
-
export
|
|
14
|
-
export
|
|
13
|
+
export type ComponentEventHandler = (evt: React.SyntheticEvent, childProps: unknown, eventKey: ComponentEventKey, eventName: ComponentEventName) => UpdatedProps;
|
|
14
|
+
export type UpdatedProps = any;
|
|
15
15
|
interface ComponentWithEvents extends EventMixinCalculatedValues {
|
|
16
16
|
state: any;
|
|
17
17
|
setState: any;
|
|
@@ -15,14 +15,12 @@ exports.getGlobalEvents = void 0;
|
|
|
15
15
|
exports.getPartialEvents = getPartialEvents;
|
|
16
16
|
exports.getScopedEvents = getScopedEvents;
|
|
17
17
|
exports.omitGlobalEvents = void 0;
|
|
18
|
-
var
|
|
19
|
-
var
|
|
20
|
-
var
|
|
21
|
-
var
|
|
18
|
+
var _isEmpty = _interopRequireDefault(require("lodash/isEmpty"));
|
|
19
|
+
var _pickBy = _interopRequireDefault(require("lodash/pickBy"));
|
|
20
|
+
var _omitBy = _interopRequireDefault(require("lodash/omitBy"));
|
|
21
|
+
var _uniq = _interopRequireDefault(require("lodash/uniq"));
|
|
22
22
|
var _helpers = require("./helpers");
|
|
23
23
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
24
|
-
/* eslint-disable no-use-before-define */
|
|
25
|
-
|
|
26
24
|
const GLOBAL_EVENT_REGEX = /^onGlobal(.*)$/;
|
|
27
25
|
|
|
28
26
|
// Normally we'd use Template Literal Types, but we're avoiding it to maximize TS compatibility with TS < 4.1
|
|
@@ -69,11 +67,10 @@ getScopedEvents) {
|
|
|
69
67
|
*/
|
|
70
68
|
const getAllEvents = () => {
|
|
71
69
|
// Mandatory usage: `getEvents.bind(this)`
|
|
72
|
-
|
|
70
|
+
|
|
73
71
|
if (Array.isArray(this.componentEvents)) {
|
|
74
72
|
return Array.isArray(props.events) ? this.componentEvents.concat(...props.events) : this.componentEvents;
|
|
75
73
|
}
|
|
76
|
-
/* eslint-enable no-invalid-this */
|
|
77
74
|
return props.events;
|
|
78
75
|
};
|
|
79
76
|
const allEvents = getAllEvents();
|
|
@@ -93,12 +90,12 @@ getScopedEvents) {
|
|
|
93
90
|
*/
|
|
94
91
|
// eslint-disable-next-line max-params
|
|
95
92
|
function getScopedEvents(events, namespace, childType, baseProps) {
|
|
96
|
-
if ((0,
|
|
93
|
+
if ((0, _isEmpty.default)(events)) {
|
|
97
94
|
return {};
|
|
98
95
|
}
|
|
99
96
|
|
|
100
97
|
// Mandatory usage: `getScopedEvents.bind(this)`
|
|
101
|
-
|
|
98
|
+
|
|
102
99
|
const newBaseProps = baseProps || this.baseProps;
|
|
103
100
|
// returns the original base props or base state of a given target element
|
|
104
101
|
const getTargetProps = (identifier, type) => {
|
|
@@ -107,7 +104,6 @@ function getScopedEvents(events, namespace, childType, baseProps) {
|
|
|
107
104
|
target,
|
|
108
105
|
key
|
|
109
106
|
} = identifier;
|
|
110
|
-
// eslint-disable-next-line no-invalid-this
|
|
111
107
|
const baseType = type === "props" ? newBaseProps : this.state || {};
|
|
112
108
|
const base = childName === undefined || childName === null || !baseType[childName] ? baseType : baseType[childName];
|
|
113
109
|
return key === "parent" ? base.parent : base[key] && base[key][target];
|
|
@@ -134,7 +130,6 @@ function getScopedEvents(events, namespace, childType, baseProps) {
|
|
|
134
130
|
|
|
135
131
|
// returns the state object with mutated props applied for a single key
|
|
136
132
|
const getMutationObject = (key, childName) => {
|
|
137
|
-
// eslint-disable-next-line no-invalid-this
|
|
138
133
|
const baseState = this.state || {};
|
|
139
134
|
if (!(0, _helpers.isFunction)(eventReturn.mutation)) {
|
|
140
135
|
return baseState;
|
|
@@ -207,11 +202,9 @@ function getScopedEvents(events, namespace, childType, baseProps) {
|
|
|
207
202
|
// into a state mutation, and calls setState
|
|
208
203
|
// eslint-disable-next-line max-params
|
|
209
204
|
const onEvent = (evt, childProps, eventKey, eventName) => {
|
|
210
|
-
// eslint-disable-next-line no-invalid-this
|
|
211
205
|
const eventReturn = events[eventName](evt, childProps, eventKey, this);
|
|
212
|
-
if (!(0,
|
|
206
|
+
if (!(0, _isEmpty.default)(eventReturn)) {
|
|
213
207
|
const callbacks = compileCallbacks(eventReturn);
|
|
214
|
-
// eslint-disable-next-line no-invalid-this
|
|
215
208
|
this.setState(parseEventReturn(eventReturn, eventKey), callbacks);
|
|
216
209
|
}
|
|
217
210
|
};
|
|
@@ -241,7 +234,7 @@ function getPartialEvents(events, eventKey, childProps) {
|
|
|
241
234
|
// eslint-disable-next-line max-params
|
|
242
235
|
function getEventState(eventKey, namespace, childType) {
|
|
243
236
|
// Mandatory usage: `getEventState.bind(this)`
|
|
244
|
-
|
|
237
|
+
|
|
245
238
|
const state = this.state || {};
|
|
246
239
|
if (!childType) {
|
|
247
240
|
return eventKey === "parent" ? state[eventKey] && state[eventKey][namespace] || state[eventKey] : state[eventKey] && state[eventKey][namespace];
|
|
@@ -271,7 +264,7 @@ function getExternalMutationsWithChildren(mutations, baseProps, baseState, child
|
|
|
271
264
|
const childState = baseState[childName];
|
|
272
265
|
const mutation = getExternalMutations(mutations, baseProps[childName], baseState[childName], childName);
|
|
273
266
|
memo[childName] = mutation ? mutation : childState;
|
|
274
|
-
return (0,
|
|
267
|
+
return (0, _pickBy.default)(memo, v => !(0, _isEmpty.default)(v));
|
|
275
268
|
}, {});
|
|
276
269
|
}
|
|
277
270
|
|
|
@@ -307,7 +300,7 @@ function getExternalMutations(mutations, baseProps, baseState, childName) {
|
|
|
307
300
|
} else {
|
|
308
301
|
// use keys from both state and props so that elements not intially included in baseProps
|
|
309
302
|
// will be used. (i.e. labels)
|
|
310
|
-
const targets = (0,
|
|
303
|
+
const targets = (0, _uniq.default)(Object.keys(keyProps).concat(Object.keys(keyState)));
|
|
311
304
|
memo[eventKey] = targets.reduce((m, target) => {
|
|
312
305
|
const identifier = {
|
|
313
306
|
eventKey,
|
|
@@ -316,10 +309,10 @@ function getExternalMutations(mutations, baseProps, baseState, childName) {
|
|
|
316
309
|
};
|
|
317
310
|
const mutation = getExternalMutation(mutations, keyProps[target], keyState[target], identifier);
|
|
318
311
|
m[target] = mutation !== undefined ? Object.assign({}, keyState[target], mutation) : keyState[target];
|
|
319
|
-
return (0,
|
|
312
|
+
return (0, _pickBy.default)(m, v => !(0, _isEmpty.default)(v));
|
|
320
313
|
}, {});
|
|
321
314
|
}
|
|
322
|
-
return (0,
|
|
315
|
+
return (0, _pickBy.default)(memo, v => !(0, _isEmpty.default)(v));
|
|
323
316
|
}, {});
|
|
324
317
|
}
|
|
325
318
|
|
|
@@ -351,11 +344,11 @@ function getExternalMutation(mutations, baseProps, baseState, identifier) {
|
|
|
351
344
|
}
|
|
352
345
|
// find any mutation objects that match the target
|
|
353
346
|
const targetMutations = scopedMutations.filter(m => filterMutations(m, "target"));
|
|
354
|
-
if ((0,
|
|
347
|
+
if ((0, _isEmpty.default)(targetMutations)) {
|
|
355
348
|
return undefined;
|
|
356
349
|
}
|
|
357
350
|
const keyMutations = targetMutations.filter(m => filterMutations(m, "eventKey"));
|
|
358
|
-
if ((0,
|
|
351
|
+
if ((0, _isEmpty.default)(keyMutations)) {
|
|
359
352
|
return undefined;
|
|
360
353
|
}
|
|
361
354
|
return keyMutations.reduce((memo, curr) => {
|
|
@@ -381,9 +374,9 @@ function getGlobalEventNameFromKey(key) {
|
|
|
381
374
|
const match = key.match(GLOBAL_EVENT_REGEX);
|
|
382
375
|
return match && match[1] && match[1].toLowerCase();
|
|
383
376
|
}
|
|
384
|
-
const getGlobalEvents = events => (0,
|
|
377
|
+
const getGlobalEvents = events => (0, _pickBy.default)(events, (_, key) => GLOBAL_EVENT_REGEX.test(key));
|
|
385
378
|
exports.getGlobalEvents = getGlobalEvents;
|
|
386
|
-
const omitGlobalEvents = events => (0,
|
|
379
|
+
const omitGlobalEvents = events => (0, _omitBy.default)(events, (_, key) => GLOBAL_EVENT_REGEX.test(key));
|
|
387
380
|
exports.omitGlobalEvents = omitGlobalEvents;
|
|
388
381
|
const emulateReactEvent = event => Object.assign(event, {
|
|
389
382
|
nativeEvent: event
|
|
@@ -1,6 +1,27 @@
|
|
|
1
1
|
import React from "react";
|
|
2
|
-
import { CallbackArgs } from "../types/callbacks";
|
|
3
2
|
import { ValueOrAccessor } from "../types/prop-types";
|
|
3
|
+
export type ElementPadding = {
|
|
4
|
+
top: number;
|
|
5
|
+
bottom: number;
|
|
6
|
+
left: number;
|
|
7
|
+
right: number;
|
|
8
|
+
};
|
|
9
|
+
export type MaybePointData = {
|
|
10
|
+
x?: number;
|
|
11
|
+
x0?: number;
|
|
12
|
+
x1?: number;
|
|
13
|
+
y?: number;
|
|
14
|
+
y0?: number;
|
|
15
|
+
y1?: number;
|
|
16
|
+
_x?: number;
|
|
17
|
+
_x0?: number;
|
|
18
|
+
_x1?: number;
|
|
19
|
+
_y?: number;
|
|
20
|
+
_y0?: number;
|
|
21
|
+
_y1?: number;
|
|
22
|
+
_voronoiX?: number;
|
|
23
|
+
_voronoiY?: number;
|
|
24
|
+
};
|
|
4
25
|
/**
|
|
5
26
|
* Creates an object composed of the inverted keys and values of object.
|
|
6
27
|
* If object contains duplicate values, subsequent values overwrite property assignments of previous values.
|
|
@@ -14,32 +35,83 @@ export declare function invert(original: Record<string, string | number>): {};
|
|
|
14
35
|
* @returns {Object} new object with same properties as originalObject
|
|
15
36
|
*/
|
|
16
37
|
export declare function omit<T, Keys extends keyof T>(originalObject: T, ks?: Array<Keys>): Omit<T, Keys>;
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
export declare function
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
38
|
+
/**
|
|
39
|
+
* Coalesce the x and y values from a data point
|
|
40
|
+
*/
|
|
41
|
+
export declare function getPoint(datum: MaybePointData): MaybePointData;
|
|
42
|
+
/**
|
|
43
|
+
* Scale a point based on the origin, direction, and given scale function
|
|
44
|
+
*/
|
|
45
|
+
export declare function scalePoint(props: {
|
|
46
|
+
scale: {
|
|
47
|
+
x: (x?: number) => number;
|
|
48
|
+
y: (y?: number) => number;
|
|
49
|
+
};
|
|
50
|
+
polar?: boolean;
|
|
51
|
+
horizontal?: boolean;
|
|
52
|
+
origin?: {
|
|
53
|
+
x: number;
|
|
54
|
+
y: number;
|
|
55
|
+
};
|
|
56
|
+
}, datum: MaybePointData): {
|
|
57
|
+
x: number;
|
|
58
|
+
x0: number;
|
|
59
|
+
y: number;
|
|
60
|
+
y0: number;
|
|
29
61
|
};
|
|
30
|
-
|
|
62
|
+
/**
|
|
63
|
+
* Returns a padding value from a number or partial padding values
|
|
64
|
+
*/
|
|
65
|
+
export declare function getPadding(padding?: number | Partial<ElementPadding>): ElementPadding;
|
|
66
|
+
/**
|
|
67
|
+
* Returns true if the component is defined as a tooltip
|
|
68
|
+
*/
|
|
69
|
+
export declare function isTooltip(component?: {
|
|
70
|
+
type?: {
|
|
71
|
+
role?: string;
|
|
72
|
+
};
|
|
73
|
+
}): boolean;
|
|
31
74
|
export declare function getDefaultStyles(props: any, role: any): any;
|
|
32
75
|
export declare function getStyles(style: any, defaultStyles: any): any;
|
|
33
|
-
|
|
76
|
+
/**
|
|
77
|
+
* Returns the value of a prop or accessor function with the given props
|
|
78
|
+
*/
|
|
79
|
+
export declare function evaluateProp<TValue>(prop: ValueOrAccessor<TValue, Record<string, any>>, props: Record<string, any>): TValue;
|
|
34
80
|
export declare function evaluateStyle(style: any, props: any): any;
|
|
35
81
|
export declare function degreesToRadians(degrees: any): any;
|
|
36
82
|
export declare function radiansToDegrees(radians: any): any;
|
|
37
|
-
|
|
38
|
-
|
|
83
|
+
/**
|
|
84
|
+
* Get the maximum radius that will fit in the container
|
|
85
|
+
*/
|
|
86
|
+
export declare function getRadius(options: {
|
|
87
|
+
height: number;
|
|
88
|
+
width: number;
|
|
89
|
+
padding: ElementPadding;
|
|
90
|
+
}): number;
|
|
91
|
+
/**
|
|
92
|
+
* Returns the origin for a polar chart within the padded area
|
|
93
|
+
*/
|
|
94
|
+
export declare function getPolarOrigin(props: {
|
|
95
|
+
height: number;
|
|
96
|
+
width: number;
|
|
97
|
+
padding: ElementPadding;
|
|
98
|
+
}): {
|
|
39
99
|
x: number;
|
|
40
100
|
y: number;
|
|
41
101
|
};
|
|
42
|
-
|
|
102
|
+
/**
|
|
103
|
+
* Determine the range of an axis based on the given props
|
|
104
|
+
*/
|
|
105
|
+
export declare function getRange(props: {
|
|
106
|
+
range?: [number, number];
|
|
107
|
+
polar?: boolean;
|
|
108
|
+
innerRadius?: number;
|
|
109
|
+
startAngle?: number;
|
|
110
|
+
endAngle?: number;
|
|
111
|
+
height: number;
|
|
112
|
+
width: number;
|
|
113
|
+
padding: number | Partial<ElementPadding>;
|
|
114
|
+
}, axis: "x" | "y"): any;
|
|
43
115
|
/**
|
|
44
116
|
* Checks if `value` is `null` or `undefined`.
|
|
45
117
|
* @returns {boolean} Returns `true` if `value` is nullish, else `false`.
|
|
@@ -93,5 +165,8 @@ export declare function reduceChildren<TChildren extends React.ReactNode, TItem,
|
|
|
93
165
|
* @returns {Boolean} returns true if the props object contains `horizontal: true` of if any
|
|
94
166
|
* children or nested children are horizontal
|
|
95
167
|
*/
|
|
96
|
-
export declare function isHorizontal(props:
|
|
168
|
+
export declare function isHorizontal(props: {
|
|
169
|
+
horizontal?: boolean;
|
|
170
|
+
children?: React.ReactNode;
|
|
171
|
+
}): any;
|
|
97
172
|
//# sourceMappingURL=helpers.d.ts.map
|