victory-core 36.8.2 → 36.8.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 +12 -0
- package/dist/victory-core.js +177 -155
- package/dist/victory-core.min.js +1 -1
- package/es/types/callbacks.d.ts +4 -4
- package/es/victory-animation/util.d.ts +3 -3
- package/es/victory-animation/util.js +5 -3
- package/es/victory-animation/victory-animation.js +2 -2
- package/es/victory-label/victory-label.d.ts +1 -1
- package/es/victory-label/victory-label.js +7 -11
- package/es/victory-primitives/arc.d.ts +1 -1
- package/es/victory-primitives/arc.js +2 -2
- package/es/victory-primitives/background.d.ts +1 -1
- package/es/victory-primitives/background.js +2 -2
- package/es/victory-primitives/border.d.ts +1 -1
- package/es/victory-primitives/border.js +2 -2
- package/es/victory-primitives/line-segment.d.ts +1 -1
- package/es/victory-primitives/line-segment.js +2 -2
- package/es/victory-primitives/point.d.ts +1 -1
- package/es/victory-primitives/point.js +2 -2
- package/es/victory-primitives/whisker.d.ts +1 -1
- package/es/victory-primitives/whisker.js +16 -17
- package/es/victory-util/add-events.js +7 -6
- package/es/victory-util/axis.js +2 -2
- package/es/victory-util/common-props.d.ts +1 -0
- package/es/victory-util/data.js +14 -9
- package/es/victory-util/domain.js +15 -15
- package/es/victory-util/events.d.ts +3 -3
- package/es/victory-util/events.js +13 -16
- package/es/victory-util/helpers.js +5 -5
- package/es/victory-util/immutable.js +4 -2
- package/es/victory-util/label-helpers.d.ts +1 -1
- package/es/victory-util/label-helpers.js +11 -12
- package/es/victory-util/selection.js +1 -2
- package/es/victory-util/timer.js +1 -2
- package/es/victory-util/transitions.js +37 -26
- package/es/victory-util/user-props.d.ts +6 -0
- package/es/victory-util/user-props.js +12 -1
- package/es/victory-util/wrapper.js +14 -14
- package/lib/types/callbacks.d.ts +4 -4
- package/lib/victory-animation/util.d.ts +3 -3
- package/lib/victory-animation/util.js +5 -3
- package/lib/victory-animation/victory-animation.js +2 -2
- package/lib/victory-label/victory-label.d.ts +1 -1
- package/lib/victory-label/victory-label.js +7 -11
- package/lib/victory-primitives/arc.d.ts +1 -1
- package/lib/victory-primitives/arc.js +2 -2
- package/lib/victory-primitives/background.d.ts +1 -1
- package/lib/victory-primitives/background.js +2 -2
- package/lib/victory-primitives/border.d.ts +1 -1
- package/lib/victory-primitives/border.js +2 -2
- package/lib/victory-primitives/line-segment.d.ts +1 -1
- package/lib/victory-primitives/line-segment.js +2 -2
- package/lib/victory-primitives/point.d.ts +1 -1
- package/lib/victory-primitives/point.js +2 -2
- package/lib/victory-primitives/whisker.d.ts +1 -1
- package/lib/victory-primitives/whisker.js +16 -17
- package/lib/victory-util/add-events.js +7 -6
- package/lib/victory-util/axis.js +2 -2
- package/lib/victory-util/common-props.d.ts +1 -0
- package/lib/victory-util/data.js +14 -9
- package/lib/victory-util/domain.js +15 -15
- package/lib/victory-util/events.d.ts +3 -3
- package/lib/victory-util/events.js +13 -16
- package/lib/victory-util/helpers.js +5 -5
- package/lib/victory-util/immutable.js +4 -2
- package/lib/victory-util/label-helpers.d.ts +1 -1
- package/lib/victory-util/label-helpers.js +11 -11
- package/lib/victory-util/selection.js +1 -2
- package/lib/victory-util/timer.js +1 -2
- package/lib/victory-util/transitions.js +32 -26
- package/lib/victory-util/user-props.d.ts +6 -0
- package/lib/victory-util/user-props.js +13 -0
- package/lib/victory-util/wrapper.js +16 -14
- package/package.json +2 -2
- package/src/types/callbacks.ts +8 -5
- package/src/victory-animation/util.ts +5 -3
- package/src/victory-animation/victory-animation.tsx +3 -2
- package/src/victory-label/victory-label.tsx +18 -17
- package/src/victory-primitives/arc.tsx +2 -2
- package/src/victory-primitives/background.tsx +2 -2
- package/src/victory-primitives/border.tsx +2 -2
- package/src/victory-primitives/line-segment.tsx +2 -2
- package/src/victory-primitives/point.tsx +2 -2
- package/src/victory-primitives/whisker.tsx +5 -5
- package/src/victory-util/add-events.tsx +10 -9
- package/src/victory-util/axis.tsx +6 -2
- package/src/victory-util/common-props.tsx +1 -0
- package/src/victory-util/data.ts +12 -8
- package/src/victory-util/domain.ts +15 -15
- package/src/victory-util/events.ts +15 -23
- package/src/victory-util/helpers.ts +5 -5
- package/src/victory-util/immutable.ts +3 -2
- package/src/victory-util/label-helpers.ts +6 -10
- package/src/victory-util/selection.ts +3 -2
- package/src/victory-util/timer.ts +1 -2
- package/src/victory-util/transitions.ts +31 -22
- package/src/victory-util/user-props.ts +14 -0
- package/src/victory-util/wrapper.tsx +17 -22
|
@@ -183,22 +183,22 @@ export function createDomainFunction(
|
|
|
183
183
|
getDomainFromDataFunction?,
|
|
184
184
|
formatDomainFunction?,
|
|
185
185
|
) {
|
|
186
|
-
|
|
186
|
+
const getDomainFromDataFn = isFunction(getDomainFromDataFunction)
|
|
187
187
|
? getDomainFromDataFunction
|
|
188
188
|
: getDomainFromData;
|
|
189
|
-
|
|
189
|
+
const formatDomainFn = isFunction(formatDomainFunction)
|
|
190
190
|
? formatDomainFunction
|
|
191
191
|
: formatDomain;
|
|
192
192
|
return (props, axis) => {
|
|
193
193
|
const propsDomain = getDomainFromProps(props, axis);
|
|
194
194
|
if (propsDomain) {
|
|
195
|
-
return
|
|
195
|
+
return formatDomainFn(propsDomain, props, axis);
|
|
196
196
|
}
|
|
197
197
|
const categories = Data.getCategories(props, axis);
|
|
198
198
|
const domain = categories
|
|
199
199
|
? getDomainFromCategories(props, axis, categories)
|
|
200
|
-
:
|
|
201
|
-
return domain ?
|
|
200
|
+
: getDomainFromDataFn(props, axis);
|
|
201
|
+
return domain ? formatDomainFn(domain, props, axis) : undefined;
|
|
202
202
|
};
|
|
203
203
|
}
|
|
204
204
|
|
|
@@ -231,14 +231,14 @@ export function getDomain(props, axis) {
|
|
|
231
231
|
* @returns {Array|undefined} returns a domain from categories or undefined
|
|
232
232
|
*/
|
|
233
233
|
export function getDomainFromCategories(props, axis, categories?) {
|
|
234
|
-
|
|
234
|
+
const categoriesArray = categories || Data.getCategories(props, axis);
|
|
235
235
|
const { polar, startAngle = 0, endAngle = 360 } = props;
|
|
236
|
-
if (!
|
|
236
|
+
if (!categoriesArray) {
|
|
237
237
|
return undefined;
|
|
238
238
|
}
|
|
239
239
|
const minDomain = getMinFromProps(props, axis);
|
|
240
240
|
const maxDomain = getMaxFromProps(props, axis);
|
|
241
|
-
const stringArray = Collection.containsStrings(
|
|
241
|
+
const stringArray = Collection.containsStrings(categoriesArray)
|
|
242
242
|
? Data.getStringsFromCategories(props, axis)
|
|
243
243
|
: [];
|
|
244
244
|
const stringMap =
|
|
@@ -249,8 +249,8 @@ export function getDomainFromCategories(props, axis, categories?) {
|
|
|
249
249
|
return memo;
|
|
250
250
|
}, {});
|
|
251
251
|
const categoryValues = stringMap
|
|
252
|
-
?
|
|
253
|
-
:
|
|
252
|
+
? categoriesArray.map((value) => stringMap[value])
|
|
253
|
+
: categoriesArray;
|
|
254
254
|
const min =
|
|
255
255
|
minDomain !== undefined
|
|
256
256
|
? minDomain
|
|
@@ -273,11 +273,11 @@ export function getDomainFromCategories(props, axis, categories?) {
|
|
|
273
273
|
* @returns {Array} the domain based on data
|
|
274
274
|
*/
|
|
275
275
|
export function getDomainFromData(props, axis, dataset) {
|
|
276
|
-
|
|
276
|
+
const datasetArray = dataset || Data.getData(props);
|
|
277
277
|
const { polar, startAngle = 0, endAngle = 360 } = props;
|
|
278
278
|
const minDomain = getMinFromProps(props, axis);
|
|
279
279
|
const maxDomain = getMaxFromProps(props, axis);
|
|
280
|
-
if (
|
|
280
|
+
if (datasetArray.length < 1) {
|
|
281
281
|
return minDomain !== undefined && maxDomain !== undefined
|
|
282
282
|
? getDomainFromMinMax(minDomain, maxDomain)
|
|
283
283
|
: undefined;
|
|
@@ -285,14 +285,14 @@ export function getDomainFromData(props, axis, dataset) {
|
|
|
285
285
|
const min =
|
|
286
286
|
minDomain !== undefined
|
|
287
287
|
? minDomain
|
|
288
|
-
: getExtremeFromData(
|
|
288
|
+
: getExtremeFromData(datasetArray, axis, "min");
|
|
289
289
|
const max =
|
|
290
290
|
maxDomain !== undefined
|
|
291
291
|
? maxDomain
|
|
292
|
-
: getExtremeFromData(
|
|
292
|
+
: getExtremeFromData(datasetArray, axis, "max");
|
|
293
293
|
const domain = getDomainFromMinMax(min, max);
|
|
294
294
|
return polar && axis === "x" && Math.abs(startAngle - endAngle) === 360
|
|
295
|
-
? getSymmetricDomain(domain, getFlatData(
|
|
295
|
+
? getSymmetricDomain(domain, getFlatData(datasetArray, axis))
|
|
296
296
|
: domain;
|
|
297
297
|
}
|
|
298
298
|
|
|
@@ -48,10 +48,10 @@ interface ComponentWithEvents extends EventMixinCalculatedValues {
|
|
|
48
48
|
export function getEvents(
|
|
49
49
|
this: ComponentWithEvents,
|
|
50
50
|
props,
|
|
51
|
-
target
|
|
52
|
-
eventKey
|
|
51
|
+
target?,
|
|
52
|
+
eventKey?,
|
|
53
53
|
// eslint-disable-next-line no-shadow
|
|
54
|
-
getScopedEvents
|
|
54
|
+
getScopedEvents?,
|
|
55
55
|
) {
|
|
56
56
|
// Returns all events that apply to a particular target element
|
|
57
57
|
const getEventsByTarget = (events: Array<ComponentEvent>) => {
|
|
@@ -137,12 +137,12 @@ export function getScopedEvents(
|
|
|
137
137
|
|
|
138
138
|
// Mandatory usage: `getScopedEvents.bind(this)`
|
|
139
139
|
// eslint-disable-next-line no-invalid-this
|
|
140
|
-
|
|
140
|
+
const newBaseProps = baseProps || this.baseProps;
|
|
141
141
|
// returns the original base props or base state of a given target element
|
|
142
142
|
const getTargetProps = (identifier, type) => {
|
|
143
143
|
const { childName, target, key } = identifier;
|
|
144
144
|
// eslint-disable-next-line no-invalid-this
|
|
145
|
-
const baseType = type === "props" ?
|
|
145
|
+
const baseType = type === "props" ? newBaseProps : this.state || {};
|
|
146
146
|
const base =
|
|
147
147
|
childName === undefined || childName === null || !baseType[childName]
|
|
148
148
|
? baseType
|
|
@@ -249,10 +249,10 @@ export function getScopedEvents(
|
|
|
249
249
|
// Parses an array of event returns into a single state mutation
|
|
250
250
|
const parseEventReturn = (eventReturn, eventKey) => {
|
|
251
251
|
return Array.isArray(eventReturn)
|
|
252
|
-
? eventReturn.reduce(
|
|
253
|
-
memo
|
|
254
|
-
|
|
255
|
-
|
|
252
|
+
? eventReturn.reduce(
|
|
253
|
+
(memo, props) => assign({}, memo, parseEvent(props, eventKey)),
|
|
254
|
+
{},
|
|
255
|
+
)
|
|
256
256
|
: parseEvent(eventReturn, eventKey);
|
|
257
257
|
};
|
|
258
258
|
|
|
@@ -347,13 +347,10 @@ export function getEventState(
|
|
|
347
347
|
// eslint-disable-next-line max-params
|
|
348
348
|
export function getExternalMutationsWithChildren(
|
|
349
349
|
mutations,
|
|
350
|
-
baseProps,
|
|
351
|
-
baseState,
|
|
350
|
+
baseProps = {},
|
|
351
|
+
baseState = {},
|
|
352
352
|
childNames,
|
|
353
353
|
) {
|
|
354
|
-
baseProps = baseProps || {};
|
|
355
|
-
baseState = baseState || {};
|
|
356
|
-
|
|
357
354
|
return childNames.reduce((memo, childName) => {
|
|
358
355
|
const childState = baseState[childName];
|
|
359
356
|
const mutation = getExternalMutations(
|
|
@@ -380,13 +377,10 @@ export function getExternalMutationsWithChildren(
|
|
|
380
377
|
// eslint-disable-next-line max-params
|
|
381
378
|
export function getExternalMutations(
|
|
382
379
|
mutations,
|
|
383
|
-
baseProps,
|
|
384
|
-
baseState,
|
|
380
|
+
baseProps = {},
|
|
381
|
+
baseState = {},
|
|
385
382
|
childName?,
|
|
386
383
|
) {
|
|
387
|
-
baseProps = baseProps || {};
|
|
388
|
-
baseState = baseState || {};
|
|
389
|
-
|
|
390
384
|
const eventKeys = keys(baseProps);
|
|
391
385
|
return eventKeys.reduce((memo, eventKey) => {
|
|
392
386
|
const keyState = baseState[eventKey] || {};
|
|
@@ -452,8 +446,7 @@ export function getExternalMutation(
|
|
|
452
446
|
return false;
|
|
453
447
|
};
|
|
454
448
|
|
|
455
|
-
|
|
456
|
-
let scopedMutations = mutations;
|
|
449
|
+
let scopedMutations = Array.isArray(mutations) ? mutations : [mutations];
|
|
457
450
|
if (identifier.childName) {
|
|
458
451
|
scopedMutations = mutations.filter((m) => filterMutations(m, "childName"));
|
|
459
452
|
}
|
|
@@ -491,10 +484,9 @@ export function getComponentEvents(props, components) {
|
|
|
491
484
|
const componentEvents = isFunction(defaultEvents)
|
|
492
485
|
? defaultEvents(component.props)
|
|
493
486
|
: defaultEvents;
|
|
494
|
-
|
|
487
|
+
return Array.isArray(componentEvents)
|
|
495
488
|
? memo.concat(...componentEvents)
|
|
496
489
|
: memo;
|
|
497
|
-
return memo;
|
|
498
490
|
}, [] as ComponentEvent[]);
|
|
499
491
|
return events && events.length ? events : undefined;
|
|
500
492
|
}
|
|
@@ -258,6 +258,7 @@ export function reduceChildren<
|
|
|
258
258
|
];
|
|
259
259
|
const traverseChildren = (childArray, names, parent?) => {
|
|
260
260
|
return childArray.reduce((memo, child, index) => {
|
|
261
|
+
let newMemo = memo;
|
|
261
262
|
const childRole = child.type && child.type.role;
|
|
262
263
|
const childName = child.props.name || `${childRole}-${names[index]}`;
|
|
263
264
|
if (child.props && child.props.children) {
|
|
@@ -291,14 +292,14 @@ export function reduceChildren<
|
|
|
291
292
|
childNames,
|
|
292
293
|
child,
|
|
293
294
|
);
|
|
294
|
-
|
|
295
|
+
newMemo = combine(newMemo, nestedResults);
|
|
295
296
|
} else {
|
|
296
297
|
const result = iteratee(child, childName, parent);
|
|
297
298
|
if (result) {
|
|
298
|
-
|
|
299
|
+
newMemo = combine(newMemo, result);
|
|
299
300
|
}
|
|
300
301
|
}
|
|
301
|
-
return
|
|
302
|
+
return newMemo;
|
|
302
303
|
}, initialMemo);
|
|
303
304
|
};
|
|
304
305
|
|
|
@@ -320,8 +321,7 @@ export function isHorizontal(props) {
|
|
|
320
321
|
return childArray.reduce((memo, child) => {
|
|
321
322
|
const childProps = child.props || {};
|
|
322
323
|
if (memo || childProps.horizontal || !childProps.children) {
|
|
323
|
-
|
|
324
|
-
return memo;
|
|
324
|
+
return memo || childProps.horizontal;
|
|
325
325
|
}
|
|
326
326
|
return traverseChildren(React.Children.toArray(childProps.children));
|
|
327
327
|
}, false);
|
|
@@ -31,10 +31,11 @@ export function shallowToJS(x, whitelist?: Record<string, boolean | unknown>) {
|
|
|
31
31
|
return isIterable(x)
|
|
32
32
|
? x.reduce(
|
|
33
33
|
(result: any, curr: any, key: any) => {
|
|
34
|
+
let newCurr = curr;
|
|
34
35
|
if (whitelist && whitelist[key]) {
|
|
35
|
-
|
|
36
|
+
newCurr = shallowToJS(curr);
|
|
36
37
|
}
|
|
37
|
-
result[key] =
|
|
38
|
+
result[key] = newCurr;
|
|
38
39
|
return result;
|
|
39
40
|
},
|
|
40
41
|
isList(x) ? [] : {},
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
/* eslint-disable no-use-before-define */
|
|
2
|
+
import { VictoryLabelProps } from "../victory-label/victory-label";
|
|
2
3
|
import * as Helpers from "./helpers";
|
|
3
4
|
import { defaults } from "lodash";
|
|
4
5
|
|
|
5
6
|
// Private Functions
|
|
6
7
|
|
|
7
|
-
function getVerticalAnchor(props, datum) {
|
|
8
|
-
datum = datum || {};
|
|
8
|
+
function getVerticalAnchor(props, datum: VictoryLabelProps["datum"] = {}) {
|
|
9
9
|
const sign = datum._y >= 0 ? 1 : -1;
|
|
10
10
|
const labelStyle = (props.style && props.style.labels) || {};
|
|
11
11
|
if (datum.verticalAnchor || labelStyle.verticalAnchor) {
|
|
@@ -16,8 +16,7 @@ function getVerticalAnchor(props, datum) {
|
|
|
16
16
|
return "middle";
|
|
17
17
|
}
|
|
18
18
|
|
|
19
|
-
function getTextAnchor(props, datum) {
|
|
20
|
-
datum = datum || {};
|
|
19
|
+
function getTextAnchor(props, datum: VictoryLabelProps["datum"] = {}) {
|
|
21
20
|
const { style, horizontal } = props;
|
|
22
21
|
const sign = datum._y >= 0 ? 1 : -1;
|
|
23
22
|
const labelStyle = (style && style.labels) || {};
|
|
@@ -29,14 +28,12 @@ function getTextAnchor(props, datum) {
|
|
|
29
28
|
return sign >= 0 ? "start" : "end";
|
|
30
29
|
}
|
|
31
30
|
|
|
32
|
-
function getAngle(props, datum) {
|
|
33
|
-
datum = datum || {};
|
|
31
|
+
function getAngle(props, datum: VictoryLabelProps["datum"] = {}) {
|
|
34
32
|
const labelStyle = (props.style && props.style.labels) || {};
|
|
35
33
|
return datum.angle === undefined ? labelStyle.angle : datum.angle;
|
|
36
34
|
}
|
|
37
35
|
|
|
38
|
-
function getPadding(props, datum) {
|
|
39
|
-
datum = datum || {};
|
|
36
|
+
function getPadding(props, datum: VictoryLabelProps["datum"] = {}) {
|
|
40
37
|
const { horizontal, style } = props;
|
|
41
38
|
const labelStyle = style.labels || {};
|
|
42
39
|
const defaultPadding = Helpers.evaluateProp(labelStyle.padding, props) || 0;
|
|
@@ -109,8 +106,7 @@ function getPolarOrientation(degrees) {
|
|
|
109
106
|
|
|
110
107
|
// Exported Functions
|
|
111
108
|
|
|
112
|
-
export function getText(props, datum, index) {
|
|
113
|
-
datum = datum || {};
|
|
109
|
+
export function getText(props, datum: VictoryLabelProps["datum"] = {}, index) {
|
|
114
110
|
if (datum.label !== undefined) {
|
|
115
111
|
return datum.label;
|
|
116
112
|
}
|
|
@@ -73,8 +73,9 @@ export function getSVGEventCoordinates(
|
|
|
73
73
|
const location = isReactTouchEvent(evt)
|
|
74
74
|
? evt.changedTouches[0]
|
|
75
75
|
: (evt as React.MouseEvent);
|
|
76
|
-
|
|
77
|
-
|
|
76
|
+
const matrix = getTransformationMatrix(
|
|
77
|
+
(svg as SVGGraphicsElement) || getParentSVG(location),
|
|
78
|
+
);
|
|
78
79
|
return {
|
|
79
80
|
x: transformTarget(location.clientX, matrix, "x"),
|
|
80
81
|
y: transformTarget(location.clientY, matrix, "y"),
|
|
@@ -47,11 +47,10 @@ export default class Timer {
|
|
|
47
47
|
}
|
|
48
48
|
|
|
49
49
|
subscribe(callback: TimerCallback, duration: number) {
|
|
50
|
-
duration = this.shouldAnimate ? duration : 0;
|
|
51
50
|
const subscriptionID = this.subscribers.push({
|
|
52
51
|
startTime: now(),
|
|
53
52
|
callback,
|
|
54
|
-
duration,
|
|
53
|
+
duration: this.shouldAnimate ? duration : 0,
|
|
55
54
|
});
|
|
56
55
|
this.activeSubscriptions++;
|
|
57
56
|
this.start();
|
|
@@ -137,34 +137,39 @@ function getInitialChildProps(animate, data): TransitionProps {
|
|
|
137
137
|
|
|
138
138
|
// eslint-disable-next-line max-params
|
|
139
139
|
function getChildBeforeLoad(animate, child, data, cb): TransitionProps {
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
140
|
+
const newAnimate = assign({}, animate, { onEnd: cb });
|
|
141
|
+
|
|
142
|
+
if (newAnimate && newAnimate.onLoad && !newAnimate.onLoad.duration) {
|
|
143
|
+
return { animate: newAnimate, data };
|
|
143
144
|
}
|
|
144
145
|
const before =
|
|
145
|
-
|
|
146
|
+
newAnimate.onLoad && newAnimate.onLoad.before
|
|
147
|
+
? newAnimate.onLoad.before
|
|
148
|
+
: identity;
|
|
146
149
|
// If nodes need to exit, transform them with the provided onLoad.before function.
|
|
147
|
-
|
|
150
|
+
const newData = data.map((datum, idx) => {
|
|
148
151
|
return assign({}, datum, before(datum, idx, data));
|
|
149
152
|
});
|
|
150
153
|
|
|
151
|
-
return { animate, data, clipWidth: 0 };
|
|
154
|
+
return { animate: newAnimate, data: newData, clipWidth: 0 };
|
|
152
155
|
}
|
|
153
156
|
|
|
154
157
|
// eslint-disable-next-line max-params
|
|
155
158
|
function getChildOnLoad(animate, data, cb): TransitionProps {
|
|
156
|
-
|
|
157
|
-
|
|
159
|
+
const newAnimate = assign({}, animate, { onEnd: cb });
|
|
160
|
+
let newData = data;
|
|
161
|
+
|
|
162
|
+
if (newAnimate && newAnimate.onLoad && !newAnimate.onLoad.duration) {
|
|
158
163
|
return { animate, data };
|
|
159
164
|
}
|
|
160
165
|
const after =
|
|
161
166
|
animate.onLoad && animate.onLoad.after ? animate.onLoad.after : identity;
|
|
162
167
|
// If nodes need to exit, transform them with the provided onLoad.after function.
|
|
163
|
-
|
|
168
|
+
newData = data.map((datum, idx) => {
|
|
164
169
|
return assign({}, datum, after(datum, idx, data));
|
|
165
170
|
});
|
|
166
171
|
|
|
167
|
-
return { animate, data };
|
|
172
|
+
return { animate: newAnimate, data: newData };
|
|
168
173
|
}
|
|
169
174
|
|
|
170
175
|
// eslint-disable-next-line max-params, max-len
|
|
@@ -178,7 +183,8 @@ function getChildPropsOnExit(
|
|
|
178
183
|
// Whether or not _this_ child has exiting nodes, we want the exit-
|
|
179
184
|
// transition for all children to have the same duration, delay, etc.
|
|
180
185
|
const onExit = animate && animate.onExit;
|
|
181
|
-
|
|
186
|
+
const newAnimate = assign({}, animate, onExit);
|
|
187
|
+
let newData = data;
|
|
182
188
|
|
|
183
189
|
if (exitingNodes) {
|
|
184
190
|
// After the exit transition occurs, trigger the animations for
|
|
@@ -189,7 +195,7 @@ function getChildPropsOnExit(
|
|
|
189
195
|
? animate.onExit.before
|
|
190
196
|
: identity;
|
|
191
197
|
// If nodes need to exit, transform them with the provided onExit.before function.
|
|
192
|
-
|
|
198
|
+
newData = data.map((datum, idx) => {
|
|
193
199
|
const key = (datum.key || idx).toString();
|
|
194
200
|
return exitingNodes[key]
|
|
195
201
|
? assign({}, datum, before(datum, idx, data))
|
|
@@ -197,7 +203,7 @@ function getChildPropsOnExit(
|
|
|
197
203
|
});
|
|
198
204
|
}
|
|
199
205
|
|
|
200
|
-
return { animate, data };
|
|
206
|
+
return { animate: newAnimate, data: newData };
|
|
201
207
|
}
|
|
202
208
|
|
|
203
209
|
// eslint-disable-next-line max-params,max-len
|
|
@@ -208,10 +214,12 @@ function getChildPropsBeforeEnter(
|
|
|
208
214
|
enteringNodes,
|
|
209
215
|
cb,
|
|
210
216
|
): TransitionProps {
|
|
217
|
+
let newAnimate = animate;
|
|
218
|
+
let newData = data;
|
|
211
219
|
if (enteringNodes) {
|
|
212
220
|
// Perform a normal animation here, except - when it finishes - trigger
|
|
213
221
|
// the transition for entering nodes.
|
|
214
|
-
|
|
222
|
+
newAnimate = assign({}, animate, { onEnd: cb });
|
|
215
223
|
const before =
|
|
216
224
|
animate.onEnter && animate.onEnter.before
|
|
217
225
|
? animate.onEnter.before
|
|
@@ -219,7 +227,7 @@ function getChildPropsBeforeEnter(
|
|
|
219
227
|
// We want the entering nodes to be included in the transition target
|
|
220
228
|
// domain. However, we may not want these nodes to be displayed initially,
|
|
221
229
|
// so perform the `onEnter.before` transformation on each node.
|
|
222
|
-
|
|
230
|
+
newData = data.map((datum, idx) => {
|
|
223
231
|
const key = (datum.key || idx).toString();
|
|
224
232
|
return enteringNodes[key]
|
|
225
233
|
? assign({}, datum, before(datum, idx, data))
|
|
@@ -227,7 +235,7 @@ function getChildPropsBeforeEnter(
|
|
|
227
235
|
});
|
|
228
236
|
}
|
|
229
237
|
|
|
230
|
-
return { animate, data };
|
|
238
|
+
return { animate: newAnimate, data: newData };
|
|
231
239
|
}
|
|
232
240
|
|
|
233
241
|
// eslint-disable-next-line max-params, max-len
|
|
@@ -240,25 +248,26 @@ function getChildPropsOnEnter(
|
|
|
240
248
|
// Whether or not _this_ child has entering nodes, we want the entering-
|
|
241
249
|
// transition for all children to have the same duration, delay, etc.
|
|
242
250
|
const onEnter = animate && animate.onEnter;
|
|
243
|
-
|
|
251
|
+
const newAnimate = assign({}, animate, onEnter);
|
|
252
|
+
let newData = data;
|
|
244
253
|
|
|
245
254
|
if (enteringNodes) {
|
|
246
255
|
// Old nodes have been transitioned to their new values, and the
|
|
247
256
|
// domain should encompass the nodes that will now enter. So perform
|
|
248
257
|
// the `onEnter.after` transformation on each node.
|
|
249
|
-
|
|
258
|
+
newAnimate.onEnd = cb;
|
|
250
259
|
const after =
|
|
251
|
-
|
|
252
|
-
?
|
|
260
|
+
newAnimate.onEnter && newAnimate.onEnter.after
|
|
261
|
+
? newAnimate.onEnter.after
|
|
253
262
|
: identity;
|
|
254
|
-
|
|
263
|
+
newData = data.map((datum, idx) => {
|
|
255
264
|
const key = getDatumKey(datum, idx);
|
|
256
265
|
return enteringNodes[key]
|
|
257
266
|
? assign({}, datum, after(datum, idx, data))
|
|
258
267
|
: datum;
|
|
259
268
|
});
|
|
260
269
|
}
|
|
261
|
-
return { animate, data };
|
|
270
|
+
return { animate: newAnimate, data: newData };
|
|
262
271
|
}
|
|
263
272
|
|
|
264
273
|
/**
|
|
@@ -55,6 +55,20 @@ const testIfSafeProp = (key: string): key is SafeAttribute => {
|
|
|
55
55
|
return false;
|
|
56
56
|
};
|
|
57
57
|
|
|
58
|
+
/**
|
|
59
|
+
* Asserts that value is not null or undefined, throwing an error if it is.
|
|
60
|
+
* @param value The value to assert
|
|
61
|
+
* @param message The error message to throw
|
|
62
|
+
*/
|
|
63
|
+
export function assert<T>(
|
|
64
|
+
value: T,
|
|
65
|
+
message?: string,
|
|
66
|
+
): asserts value is NonNullable<T> {
|
|
67
|
+
if (value === undefined || value === null) {
|
|
68
|
+
throw new Error(message);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
58
72
|
/**
|
|
59
73
|
* getSafeUserProps - function that takes in a props object and removes any
|
|
60
74
|
* key-value entries that do not match filter strings in the USER_PROPS_SAFELIST
|
|
@@ -102,11 +102,12 @@ export function getDataFromChildren(props, childComponents) {
|
|
|
102
102
|
const iteratee = (child, childName, parent) => {
|
|
103
103
|
const childProps = assign({}, child.props, parentProps);
|
|
104
104
|
let childData;
|
|
105
|
+
let childElement = child;
|
|
105
106
|
if (!Data.isDataComponent(child)) {
|
|
106
107
|
return null;
|
|
107
108
|
} else if (child.type && isFunction(child.type.getData)) {
|
|
108
|
-
|
|
109
|
-
childData =
|
|
109
|
+
childElement = parent ? React.cloneElement(child, parent.props) : child;
|
|
110
|
+
childData = childElement.type.getData(childProps);
|
|
110
111
|
} else {
|
|
111
112
|
childData = Data.getData(childProps);
|
|
112
113
|
}
|
|
@@ -135,8 +136,10 @@ export function getData(props, childComponents) {
|
|
|
135
136
|
if (props.data) {
|
|
136
137
|
return Data.getData(props);
|
|
137
138
|
}
|
|
138
|
-
|
|
139
|
-
|
|
139
|
+
return getDataFromChildren(
|
|
140
|
+
props,
|
|
141
|
+
childComponents || React.Children.toArray(props.children),
|
|
142
|
+
);
|
|
140
143
|
}
|
|
141
144
|
|
|
142
145
|
export function getWidth(props, groupLength?, seriesLength?) {
|
|
@@ -145,12 +148,12 @@ export function getWidth(props, groupLength?, seriesLength?) {
|
|
|
145
148
|
? Helpers.getRange(props, "y")
|
|
146
149
|
: Helpers.getRange(props, "x");
|
|
147
150
|
const extent = Math.abs(range[1] - range[0]);
|
|
148
|
-
|
|
151
|
+
const seriesLengthValue =
|
|
149
152
|
seriesLength !== undefined
|
|
150
153
|
? seriesLength
|
|
151
154
|
: (Array.isArray(datasets[0]) && datasets[0].length) || 1;
|
|
152
|
-
|
|
153
|
-
const bars =
|
|
155
|
+
const groupLengthValue = groupLength || datasets.length;
|
|
156
|
+
const bars = groupLengthValue * seriesLengthValue;
|
|
154
157
|
const barRatio = 0.5;
|
|
155
158
|
return Math.round((barRatio * extent) / bars);
|
|
156
159
|
}
|
|
@@ -241,10 +244,10 @@ export function getDomainFromChildren(props, axis, childComponents) {
|
|
|
241
244
|
}
|
|
242
245
|
|
|
243
246
|
export function getDomain(props, axis, childComponents) {
|
|
244
|
-
|
|
247
|
+
const children = childComponents || React.Children.toArray(props.children);
|
|
245
248
|
|
|
246
249
|
const propsDomain = Domain.getDomainFromProps(props, axis);
|
|
247
|
-
const domainPadding = getDefaultDomainPadding(props, axis,
|
|
250
|
+
const domainPadding = getDefaultDomainPadding(props, axis, children);
|
|
248
251
|
let domain;
|
|
249
252
|
|
|
250
253
|
if (propsDomain) {
|
|
@@ -256,7 +259,7 @@ export function getDomain(props, axis, childComponents) {
|
|
|
256
259
|
const dataDomain = dataset
|
|
257
260
|
? Domain.getDomainFromData(props, axis, dataset)!
|
|
258
261
|
: [];
|
|
259
|
-
const childDomain = getDomainFromChildren(props, axis,
|
|
262
|
+
const childDomain = getDomainFromChildren(props, axis, children);
|
|
260
263
|
const min =
|
|
261
264
|
minDomain || Collection.getMinValue([...dataDomain, ...childDomain]);
|
|
262
265
|
const max =
|
|
@@ -428,20 +431,12 @@ export function getCategoryAndAxisStringsFromChildren(
|
|
|
428
431
|
}
|
|
429
432
|
|
|
430
433
|
export function getStringsFromChildren(props, childComponents) {
|
|
431
|
-
|
|
434
|
+
const children = childComponents || React.Children.toArray(props.children);
|
|
432
435
|
|
|
433
|
-
const xStrings = getCategoryAndAxisStringsFromChildren(
|
|
434
|
-
|
|
435
|
-
"x",
|
|
436
|
-
childComponents,
|
|
437
|
-
);
|
|
438
|
-
const yStrings = getCategoryAndAxisStringsFromChildren(
|
|
439
|
-
props,
|
|
440
|
-
"y",
|
|
441
|
-
childComponents,
|
|
442
|
-
);
|
|
436
|
+
const xStrings = getCategoryAndAxisStringsFromChildren(props, "x", children);
|
|
437
|
+
const yStrings = getCategoryAndAxisStringsFromChildren(props, "y", children);
|
|
443
438
|
|
|
444
|
-
const dataStrings = getStringsFromData(
|
|
439
|
+
const dataStrings = getStringsFromData(children);
|
|
445
440
|
|
|
446
441
|
return {
|
|
447
442
|
x: uniq(flatten([...xStrings, ...dataStrings.x])),
|