victory-core 30.6.1 → 31.2.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/README.md +13 -12
- package/dist/victory-core.js +1083 -842
- package/dist/victory-core.min.js +1 -1
- package/es/victory-animation/victory-animation.js +26 -21
- package/es/victory-label/victory-label.js +8 -2
- package/es/victory-primitives/path-helpers.js +1 -1
- package/es/victory-transition/victory-transition.js +11 -6
- package/es/victory-util/add-events.js +66 -38
- package/es/victory-util/axis.js +35 -9
- package/es/victory-util/data.js +24 -9
- package/es/victory-util/domain.js +15 -7
- package/es/victory-util/events.js +1 -1
- package/es/victory-util/helpers.js +17 -5
- package/es/victory-util/label-helpers.js +3 -5
- package/es/victory-util/textsize.js +20 -20
- package/es/victory-util/transitions.js +16 -16
- package/es/victory-util/wrapper.js +56 -19
- package/lib/victory-animation/victory-animation.js +27 -21
- package/lib/victory-label/victory-label.js +8 -2
- package/lib/victory-primitives/path-helpers.js +1 -1
- package/lib/victory-transition/victory-transition.js +12 -6
- package/lib/victory-util/add-events.js +66 -38
- package/lib/victory-util/axis.js +36 -9
- package/lib/victory-util/data.js +25 -9
- package/lib/victory-util/domain.js +16 -8
- package/lib/victory-util/events.js +1 -1
- package/lib/victory-util/helpers.js +17 -5
- package/lib/victory-util/label-helpers.js +3 -5
- package/lib/victory-util/textsize.js +20 -20
- package/lib/victory-util/transitions.js +16 -16
- package/lib/victory-util/wrapper.js +56 -19
- package/package.json +1 -1
- package/src/victory-animation/util.js +47 -45
- package/src/victory-animation/victory-animation.js +66 -38
- package/src/victory-clip-container/victory-clip-container.js +44 -31
- package/src/victory-container/victory-container.js +35 -21
- package/src/victory-label/victory-label.js +55 -71
- package/src/victory-portal/portal.js +1 -1
- package/src/victory-portal/victory-portal.js +10 -7
- package/src/victory-primitives/arc.js +15 -4
- package/src/victory-primitives/border.js +26 -5
- package/src/victory-primitives/circle.js +14 -3
- package/src/victory-primitives/clip-path.js +2 -7
- package/src/victory-primitives/line-segment.js +28 -5
- package/src/victory-primitives/line.js +15 -2
- package/src/victory-primitives/path-helpers.js +6 -7
- package/src/victory-primitives/point.js +30 -11
- package/src/victory-primitives/rect.js +19 -3
- package/src/victory-primitives/text.js +21 -11
- package/src/victory-primitives/tspan.js +6 -4
- package/src/victory-primitives/whisker.js +13 -6
- package/src/victory-theme/grayscale.js +153 -128
- package/src/victory-theme/material.js +178 -149
- package/src/victory-transition/victory-transition.js +31 -25
- package/src/victory-util/add-events.js +113 -75
- package/src/victory-util/axis.js +89 -35
- package/src/victory-util/collection.js +3 -8
- package/src/victory-util/common-props.js +42 -36
- package/src/victory-util/data.js +78 -43
- package/src/victory-util/domain.js +68 -46
- package/src/victory-util/events.js +129 -112
- package/src/victory-util/helpers.js +36 -16
- package/src/victory-util/immutable.js +12 -7
- package/src/victory-util/label-helpers.js +34 -18
- package/src/victory-util/prop-types.js +11 -23
- package/src/victory-util/scale.js +2 -3
- package/src/victory-util/selection.js +4 -5
- package/src/victory-util/style.js +17 -10
- package/src/victory-util/textsize.js +35 -31
- package/src/victory-util/transitions.js +53 -35
- package/src/victory-util/wrapper.js +112 -56
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
assign, isEmpty, isFunction, without, pickBy, uniq, includes
|
|
3
|
-
} from "lodash";
|
|
1
|
+
import { assign, isEmpty, isFunction, without, pickBy, uniq, includes } from "lodash";
|
|
4
2
|
|
|
5
3
|
export default {
|
|
6
4
|
/* Returns all own and shared events that should be attached to a single target element,
|
|
@@ -16,8 +14,9 @@ export default {
|
|
|
16
14
|
const getSelectedEvents = () => {
|
|
17
15
|
const targetEvents = events.reduce((memo, event) => {
|
|
18
16
|
if (event.target !== undefined) {
|
|
19
|
-
const matchesTarget = Array.isArray(event.target)
|
|
20
|
-
includes(event.target, target)
|
|
17
|
+
const matchesTarget = Array.isArray(event.target)
|
|
18
|
+
? includes(event.target, target)
|
|
19
|
+
: `${event.target}` === `${target}`;
|
|
21
20
|
return matchesTarget ? memo.concat(event) : memo;
|
|
22
21
|
}
|
|
23
22
|
return memo.concat(event);
|
|
@@ -26,18 +25,22 @@ export default {
|
|
|
26
25
|
if (eventKey !== undefined && target !== "parent") {
|
|
27
26
|
return targetEvents.filter((obj) => {
|
|
28
27
|
const targetKeys = obj.eventKey;
|
|
29
|
-
const useKey = (key) => key ? `${key}` === `${eventKey}` : true;
|
|
30
|
-
return Array.isArray(targetKeys)
|
|
31
|
-
targetKeys.some((k) => useKey(k))
|
|
28
|
+
const useKey = (key) => (key ? `${key}` === `${eventKey}` : true);
|
|
29
|
+
return Array.isArray(targetKeys)
|
|
30
|
+
? targetKeys.some((k) => useKey(k))
|
|
31
|
+
: useKey(targetKeys);
|
|
32
32
|
});
|
|
33
33
|
}
|
|
34
34
|
return targetEvents;
|
|
35
35
|
};
|
|
36
36
|
|
|
37
37
|
const selectedEvents = getSelectedEvents();
|
|
38
|
-
return
|
|
39
|
-
|
|
40
|
-
|
|
38
|
+
return (
|
|
39
|
+
Array.isArray(selectedEvents) &&
|
|
40
|
+
selectedEvents.reduce((memo, event) => {
|
|
41
|
+
return event ? assign(memo, event.eventHandlers) : memo;
|
|
42
|
+
}, {})
|
|
43
|
+
);
|
|
41
44
|
};
|
|
42
45
|
|
|
43
46
|
/* Returns all events from props and defaultEvents from components. Events handlers
|
|
@@ -46,20 +49,24 @@ export default {
|
|
|
46
49
|
*/
|
|
47
50
|
const getAllEvents = () => {
|
|
48
51
|
if (Array.isArray(this.componentEvents)) {
|
|
49
|
-
return Array.isArray(props.events)
|
|
50
|
-
this.componentEvents.concat(...props.events)
|
|
52
|
+
return Array.isArray(props.events)
|
|
53
|
+
? this.componentEvents.concat(...props.events)
|
|
54
|
+
: this.componentEvents;
|
|
51
55
|
}
|
|
52
56
|
return props.events;
|
|
53
57
|
};
|
|
54
58
|
|
|
55
59
|
const allEvents = getAllEvents();
|
|
56
|
-
const ownEvents =
|
|
57
|
-
|
|
60
|
+
const ownEvents =
|
|
61
|
+
allEvents && isFunction(getScopedEvents)
|
|
62
|
+
? getScopedEvents(getEventsByTarget(allEvents), target)
|
|
63
|
+
: undefined;
|
|
58
64
|
if (!props.sharedEvents) {
|
|
59
65
|
return ownEvents;
|
|
60
66
|
}
|
|
61
67
|
const getSharedEvents = props.sharedEvents.getEvents;
|
|
62
|
-
const sharedEvents =
|
|
68
|
+
const sharedEvents =
|
|
69
|
+
props.sharedEvents.events &&
|
|
63
70
|
getSharedEvents(getEventsByTarget(props.sharedEvents.events), target);
|
|
64
71
|
return assign({}, sharedEvents, ownEvents);
|
|
65
72
|
},
|
|
@@ -80,16 +87,18 @@ export default {
|
|
|
80
87
|
const getTargetProps = (identifier, type) => {
|
|
81
88
|
const { childName, target, key } = identifier;
|
|
82
89
|
const baseType = type === "props" ? baseProps : this.state || {};
|
|
83
|
-
const base =
|
|
84
|
-
|
|
90
|
+
const base =
|
|
91
|
+
childName === undefined || childName === null || !baseType[childName]
|
|
92
|
+
? baseType
|
|
93
|
+
: baseType[childName];
|
|
85
94
|
return key === "parent" ? base.parent : base[key] && base[key][target];
|
|
86
95
|
};
|
|
87
96
|
|
|
88
97
|
// Returns the state object with the mutation caused by a given eventReturn
|
|
89
98
|
// applied to the appropriate property on the state object
|
|
90
99
|
const parseEvent = (eventReturn, eventKey) => {
|
|
91
|
-
const childNames =
|
|
92
|
-
eventReturn.childName : eventReturn.childName || childType;
|
|
100
|
+
const childNames =
|
|
101
|
+
namespace === "parent" ? eventReturn.childName : eventReturn.childName || childType;
|
|
93
102
|
const target = eventReturn.target || namespace;
|
|
94
103
|
|
|
95
104
|
// returns all eventKeys to modify for a targeted childName
|
|
@@ -98,12 +107,11 @@ export default {
|
|
|
98
107
|
return "parent";
|
|
99
108
|
}
|
|
100
109
|
if (eventReturn.eventKey === "all") {
|
|
101
|
-
return baseProps[childName]
|
|
102
|
-
without(Object.keys(baseProps[childName]), "parent")
|
|
103
|
-
without(Object.keys(baseProps), "parent");
|
|
110
|
+
return baseProps[childName]
|
|
111
|
+
? without(Object.keys(baseProps[childName]), "parent")
|
|
112
|
+
: without(Object.keys(baseProps), "parent");
|
|
104
113
|
} else if (eventReturn.eventKey === undefined && eventKey === "parent") {
|
|
105
|
-
return baseProps[childName] ?
|
|
106
|
-
Object.keys(baseProps[childName]) : Object.keys(baseProps);
|
|
114
|
+
return baseProps[childName] ? Object.keys(baseProps[childName]) : Object.keys(baseProps);
|
|
107
115
|
}
|
|
108
116
|
return eventReturn.eventKey !== undefined ? eventReturn.eventKey : eventKey;
|
|
109
117
|
};
|
|
@@ -117,7 +125,8 @@ export default {
|
|
|
117
125
|
const mutationTargetProps = getTargetProps({ childName, key, target }, "props");
|
|
118
126
|
const mutationTargetState = getTargetProps({ childName, key, target }, "state");
|
|
119
127
|
const mutatedProps = eventReturn.mutation(
|
|
120
|
-
assign({}, mutationTargetProps, mutationTargetState),
|
|
128
|
+
assign({}, mutationTargetProps, mutationTargetState),
|
|
129
|
+
baseProps
|
|
121
130
|
);
|
|
122
131
|
const childState = baseState[childName] || {};
|
|
123
132
|
|
|
@@ -132,55 +141,59 @@ export default {
|
|
|
132
141
|
};
|
|
133
142
|
|
|
134
143
|
const extendState = (state) => {
|
|
135
|
-
return target === "parent"
|
|
136
|
-
assign(state, { [key]: assign(state[key], mutatedProps) })
|
|
137
|
-
assign(state, { [key]: assign(state[key], { [target]: mutatedProps }) });
|
|
144
|
+
return target === "parent"
|
|
145
|
+
? assign(state, { [key]: assign(state[key], mutatedProps) })
|
|
146
|
+
: assign(state, { [key]: assign(state[key], { [target]: mutatedProps }) });
|
|
138
147
|
};
|
|
139
148
|
|
|
140
149
|
const updateState = (state) => {
|
|
141
150
|
return mutatedProps ? extendState(state) : filterState(state);
|
|
142
151
|
};
|
|
143
152
|
|
|
144
|
-
return childName !== undefined && childName !== null
|
|
145
|
-
assign(baseState, { [childName]: updateState(childState) })
|
|
146
|
-
updateState(baseState);
|
|
153
|
+
return childName !== undefined && childName !== null
|
|
154
|
+
? assign(baseState, { [childName]: updateState(childState) })
|
|
155
|
+
: updateState(baseState);
|
|
147
156
|
};
|
|
148
157
|
|
|
149
158
|
// returns entire mutated state for a given childName
|
|
150
159
|
const getReturnByChild = (childName) => {
|
|
151
160
|
const mutationKeys = getKeys(childName);
|
|
152
|
-
return Array.isArray(mutationKeys)
|
|
153
|
-
mutationKeys.reduce((memo, key) => {
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
getMutationObject(mutationKeys, childName);
|
|
161
|
+
return Array.isArray(mutationKeys)
|
|
162
|
+
? mutationKeys.reduce((memo, key) => {
|
|
163
|
+
return assign(memo, getMutationObject(key, childName));
|
|
164
|
+
}, {})
|
|
165
|
+
: getMutationObject(mutationKeys, childName);
|
|
157
166
|
};
|
|
158
167
|
|
|
159
168
|
// returns an entire mutated state for all children
|
|
160
|
-
const allChildNames =
|
|
161
|
-
without(Object.keys(baseProps), "parent") : childNames;
|
|
162
|
-
return Array.isArray(allChildNames)
|
|
163
|
-
|
|
164
|
-
|
|
169
|
+
const allChildNames =
|
|
170
|
+
childNames === "all" ? without(Object.keys(baseProps), "parent") : childNames;
|
|
171
|
+
return Array.isArray(allChildNames)
|
|
172
|
+
? allChildNames.reduce((memo, childName) => {
|
|
173
|
+
return assign(memo, getReturnByChild(childName));
|
|
174
|
+
}, {})
|
|
175
|
+
: getReturnByChild(allChildNames);
|
|
165
176
|
};
|
|
166
177
|
|
|
167
178
|
// Parses an array of event returns into a single state mutation
|
|
168
179
|
const parseEventReturn = (eventReturn, eventKey) => {
|
|
169
|
-
return Array.isArray(eventReturn)
|
|
170
|
-
eventReturn.reduce((memo, props) => {
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
parseEvent(eventReturn, eventKey);
|
|
180
|
+
return Array.isArray(eventReturn)
|
|
181
|
+
? eventReturn.reduce((memo, props) => {
|
|
182
|
+
memo = assign({}, memo, parseEvent(props, eventKey));
|
|
183
|
+
return memo;
|
|
184
|
+
}, {})
|
|
185
|
+
: parseEvent(eventReturn, eventKey);
|
|
175
186
|
};
|
|
176
187
|
|
|
177
188
|
const compileCallbacks = (eventReturn) => {
|
|
178
189
|
const getCallback = (obj) => isFunction(obj.callback) && obj.callback;
|
|
179
|
-
const callbacks = Array.isArray(eventReturn)
|
|
180
|
-
eventReturn.map((evtObj) => getCallback(evtObj))
|
|
190
|
+
const callbacks = Array.isArray(eventReturn)
|
|
191
|
+
? eventReturn.map((evtObj) => getCallback(evtObj))
|
|
192
|
+
: [getCallback(eventReturn)];
|
|
181
193
|
const callbackArray = callbacks.filter((callback) => callback !== false);
|
|
182
|
-
return callbackArray.length
|
|
183
|
-
() => callbackArray.forEach((callback) => callback())
|
|
194
|
+
return callbackArray.length
|
|
195
|
+
? () => callbackArray.forEach((callback) => callback())
|
|
196
|
+
: undefined;
|
|
184
197
|
};
|
|
185
198
|
|
|
186
199
|
// A function that calls a particular event handler, parses its return
|
|
@@ -205,13 +218,13 @@ export default {
|
|
|
205
218
|
* This allows event handlers to have access to props controlling each element
|
|
206
219
|
*/
|
|
207
220
|
getPartialEvents(events, eventKey, childProps) {
|
|
208
|
-
return events
|
|
209
|
-
Object.keys(events).reduce((memo, eventName) => {
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
{};
|
|
221
|
+
return events
|
|
222
|
+
? Object.keys(events).reduce((memo, eventName) => {
|
|
223
|
+
const appliedEvent = (evt) => events[eventName](evt, childProps, eventKey, eventName);
|
|
224
|
+
memo[eventName] = appliedEvent;
|
|
225
|
+
return memo;
|
|
226
|
+
}, {})
|
|
227
|
+
: {};
|
|
215
228
|
},
|
|
216
229
|
|
|
217
230
|
/* Returns the property of the state object corresponding to event changes for
|
|
@@ -220,25 +233,23 @@ export default {
|
|
|
220
233
|
getEventState(eventKey, namespace, childType) {
|
|
221
234
|
const state = this.state || {};
|
|
222
235
|
if (!childType) {
|
|
223
|
-
return eventKey === "parent"
|
|
224
|
-
state[eventKey] && state[eventKey][namespace] || state[eventKey]
|
|
225
|
-
state[eventKey] && state[eventKey][namespace];
|
|
236
|
+
return eventKey === "parent"
|
|
237
|
+
? (state[eventKey] && state[eventKey][namespace]) || state[eventKey]
|
|
238
|
+
: state[eventKey] && state[eventKey][namespace];
|
|
226
239
|
}
|
|
227
|
-
return state[childType] &&
|
|
228
|
-
state[childType][eventKey] &&
|
|
229
|
-
state[childType][eventKey][namespace];
|
|
240
|
+
return state[childType] && state[childType][eventKey] && state[childType][eventKey][namespace];
|
|
230
241
|
},
|
|
231
242
|
|
|
232
|
-
/**
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
243
|
+
/**
|
|
244
|
+
* Returns a set of all mutations for shared events
|
|
245
|
+
*
|
|
246
|
+
* @param {Array} mutations an array of mutations objects
|
|
247
|
+
* @param {Object} baseProps an object that describes all props for children of VictorySharedEvents
|
|
248
|
+
* @param {Object} baseState an object that describes state for children of VictorySharedEvents
|
|
249
|
+
* @param {Array} childNames an array of childNames
|
|
250
|
+
*
|
|
251
|
+
* @return {Object} a object describing all mutations for VictorySharedEvents
|
|
252
|
+
*/
|
|
242
253
|
// eslint-disable-next-line max-params
|
|
243
254
|
getExternalMutationsWithChildren(mutations, baseProps, baseState, childNames) {
|
|
244
255
|
baseProps = baseProps || {};
|
|
@@ -247,24 +258,26 @@ export default {
|
|
|
247
258
|
return childNames.reduce((memo, childName) => {
|
|
248
259
|
const childState = baseState[childName];
|
|
249
260
|
const mutation = this.getExternalMutations(
|
|
250
|
-
mutations,
|
|
261
|
+
mutations,
|
|
262
|
+
baseProps[childName],
|
|
263
|
+
baseState[childName],
|
|
264
|
+
childName
|
|
251
265
|
);
|
|
252
266
|
memo[childName] = mutation ? mutation : childState;
|
|
253
267
|
return pickBy(memo, (v) => !isEmpty(v));
|
|
254
268
|
}, {});
|
|
255
|
-
|
|
256
269
|
},
|
|
257
270
|
|
|
258
|
-
/**
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
271
|
+
/**
|
|
272
|
+
* Returns a set of all mutations for a component
|
|
273
|
+
*
|
|
274
|
+
* @param {Array} mutations an array of mutations objects
|
|
275
|
+
* @param {Object} baseProps a props object (scoped to a childName when used by shared events)
|
|
276
|
+
* @param {Object} baseState a state object (scoped to a childName when used by shared events)
|
|
277
|
+
* @param {String} childName an optional childName
|
|
278
|
+
*
|
|
279
|
+
* @return {Object} a object describing mutations for a given component
|
|
280
|
+
*/
|
|
268
281
|
// eslint-disable-next-line max-params
|
|
269
282
|
getExternalMutations(mutations, baseProps, baseState, childName) {
|
|
270
283
|
baseProps = baseProps || {};
|
|
@@ -277,8 +290,7 @@ export default {
|
|
|
277
290
|
if (eventKey === "parent") {
|
|
278
291
|
const identifier = { eventKey, target: "parent" };
|
|
279
292
|
const mutation = this.getExternalMutation(mutations, keyProps, keyState, identifier);
|
|
280
|
-
memo[eventKey] = mutation !== undefined ?
|
|
281
|
-
assign({}, keyState, mutation) : keyState;
|
|
293
|
+
memo[eventKey] = mutation !== undefined ? assign({}, keyState, mutation) : keyState;
|
|
282
294
|
} else {
|
|
283
295
|
// use keys from both state and props so that elements not intially included in baseProps
|
|
284
296
|
// will be used. (i.e. labels)
|
|
@@ -286,10 +298,13 @@ export default {
|
|
|
286
298
|
memo[eventKey] = targets.reduce((m, target) => {
|
|
287
299
|
const identifier = { eventKey, target, childName };
|
|
288
300
|
const mutation = this.getExternalMutation(
|
|
289
|
-
mutations,
|
|
301
|
+
mutations,
|
|
302
|
+
keyProps[target],
|
|
303
|
+
keyState[target],
|
|
304
|
+
identifier
|
|
290
305
|
);
|
|
291
|
-
m[target] =
|
|
292
|
-
assign({}, keyState[target], mutation) : keyState[target];
|
|
306
|
+
m[target] =
|
|
307
|
+
mutation !== undefined ? assign({}, keyState[target], mutation) : keyState[target];
|
|
293
308
|
return pickBy(m, (v) => !isEmpty(v));
|
|
294
309
|
}, {});
|
|
295
310
|
}
|
|
@@ -297,19 +312,18 @@ export default {
|
|
|
297
312
|
}, {});
|
|
298
313
|
},
|
|
299
314
|
|
|
300
|
-
/**
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
315
|
+
/**
|
|
316
|
+
* Returns a set of mutations for a particular element given scoped baseProps and baseState
|
|
317
|
+
*
|
|
318
|
+
* @param {Array} mutations an array of mutations objects
|
|
319
|
+
* @param {Object} baseProps a props object (scoped the element specified by the identifier)
|
|
320
|
+
* @param {Object} baseState a state object (scoped the element specified by the identifier)
|
|
321
|
+
* @param {Object} identifier { eventKey, target, childName }
|
|
322
|
+
*
|
|
323
|
+
* @return {Object | undefined} a object describing mutations for a given element, or undefined
|
|
324
|
+
*/
|
|
310
325
|
// eslint-disable-next-line max-params
|
|
311
326
|
getExternalMutation(mutations, baseProps, baseState, identifier) {
|
|
312
|
-
|
|
313
327
|
const filterMutations = (mutation, type) => {
|
|
314
328
|
if (typeof mutation[type] === "string") {
|
|
315
329
|
return mutation[type] === "all" || mutation[type] === identifier[type];
|
|
@@ -345,16 +359,19 @@ export default {
|
|
|
345
359
|
|
|
346
360
|
/* Returns an array of defaultEvents from sub-components of a given component.
|
|
347
361
|
* i.e. any static `defaultEvents` on `labelComponent` will be returned
|
|
348
|
-
|
|
362
|
+
*/
|
|
349
363
|
getComponentEvents(props, components) {
|
|
350
|
-
const events =
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
defaultEvents
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
364
|
+
const events =
|
|
365
|
+
Array.isArray(components) &&
|
|
366
|
+
components.reduce((memo, componentName) => {
|
|
367
|
+
const component = props[componentName];
|
|
368
|
+
const defaultEvents = component && component.type && component.type.defaultEvents;
|
|
369
|
+
const componentEvents = isFunction(defaultEvents)
|
|
370
|
+
? defaultEvents(component.props)
|
|
371
|
+
: defaultEvents;
|
|
372
|
+
memo = Array.isArray(componentEvents) ? memo.concat(...componentEvents) : memo;
|
|
373
|
+
return memo;
|
|
374
|
+
}, []);
|
|
358
375
|
return events && events.length ? events : undefined;
|
|
359
376
|
}
|
|
360
377
|
};
|
|
@@ -97,9 +97,9 @@ function getStyles(style, defaultStyles) {
|
|
|
97
97
|
return defaults({ parent: { height, width } }, defaultStyles);
|
|
98
98
|
}
|
|
99
99
|
const { data, labels, parent } = style;
|
|
100
|
-
const defaultParent = defaultStyles && defaultStyles.parent || {};
|
|
101
|
-
const defaultLabels = defaultStyles && defaultStyles.labels || {};
|
|
102
|
-
const defaultData = defaultStyles && defaultStyles.data || {};
|
|
100
|
+
const defaultParent = (defaultStyles && defaultStyles.parent) || {};
|
|
101
|
+
const defaultLabels = (defaultStyles && defaultStyles.labels) || {};
|
|
102
|
+
const defaultData = (defaultStyles && defaultStyles.data) || {};
|
|
103
103
|
return {
|
|
104
104
|
parent: defaults({}, parent, defaultParent, { width, height }),
|
|
105
105
|
labels: defaults({}, labels, defaultLabels),
|
|
@@ -122,11 +122,11 @@ function evaluateStyle(style, data, active) {
|
|
|
122
122
|
}
|
|
123
123
|
|
|
124
124
|
function degreesToRadians(degrees) {
|
|
125
|
-
return degrees * (Math.PI / 180);
|
|
125
|
+
return typeof degrees === "number" ? degrees * (Math.PI / 180) : degrees;
|
|
126
126
|
}
|
|
127
127
|
|
|
128
128
|
function radiansToDegrees(radians) {
|
|
129
|
-
return radians / (Math.PI / 180);
|
|
129
|
+
return typeof radians === "number" ? radians / (Math.PI / 180) : radians;
|
|
130
130
|
}
|
|
131
131
|
|
|
132
132
|
function getRadius(props) {
|
|
@@ -190,11 +190,28 @@ function getCurrentAxis(axis, horizontal) {
|
|
|
190
190
|
* @param {Array} children: an array of child components
|
|
191
191
|
* @param {Function} iteratee: a function with arguments "child", "childName", and "parent"
|
|
192
192
|
* @param {Object} parentProps: props from the parent that are applied to children
|
|
193
|
+
* @param {any} initialMemo: The object in which the iteration results are combined.
|
|
194
|
+
* @param {Function} combine: Combines the result of the iteratee with the current memo
|
|
195
|
+
* to the memo for the next iteration step
|
|
193
196
|
* @returns {Array} returns an array of results from calling the iteratee on all nested children
|
|
194
197
|
*/
|
|
195
|
-
|
|
198
|
+
/* eslint-disable max-params */
|
|
199
|
+
function reduceChildren(
|
|
200
|
+
children,
|
|
201
|
+
iteratee,
|
|
202
|
+
parentProps = {},
|
|
203
|
+
initialMemo = [],
|
|
204
|
+
combine = (memo, item) => memo.concat(item)
|
|
205
|
+
) {
|
|
196
206
|
const sharedProps = [
|
|
197
|
-
"data",
|
|
207
|
+
"data",
|
|
208
|
+
"domain",
|
|
209
|
+
"categories",
|
|
210
|
+
"polar",
|
|
211
|
+
"startAngle",
|
|
212
|
+
"endAngle",
|
|
213
|
+
"minDomain",
|
|
214
|
+
"maxDomain"
|
|
198
215
|
];
|
|
199
216
|
const traverseChildren = (childArray, names, parent) => {
|
|
200
217
|
return childArray.reduce((memo, child, index) => {
|
|
@@ -202,21 +219,24 @@ function reduceChildren(children, iteratee, parentProps = {}) {
|
|
|
202
219
|
const childName = child.props.name || `${childRole}-${names[index]}`;
|
|
203
220
|
if (child.props && child.props.children) {
|
|
204
221
|
const childProps = assign({}, child.props, pick(parentProps, sharedProps));
|
|
205
|
-
const nestedChildren =
|
|
206
|
-
child.type.getChildren
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
222
|
+
const nestedChildren =
|
|
223
|
+
child.type && isFunction(child.type.getChildren)
|
|
224
|
+
? child.type.getChildren(childProps)
|
|
225
|
+
: React.Children.toArray(child.props.children).map((c) => {
|
|
226
|
+
const nestedChildProps = assign({}, c.props, pick(childProps, sharedProps));
|
|
227
|
+
return React.cloneElement(c, nestedChildProps);
|
|
228
|
+
});
|
|
211
229
|
const childNames = nestedChildren.map((c, i) => `${childName}-${i}`);
|
|
212
230
|
const nestedResults = traverseChildren(nestedChildren, childNames, child);
|
|
213
|
-
memo = memo
|
|
231
|
+
memo = combine(memo, nestedResults);
|
|
214
232
|
} else {
|
|
215
233
|
const result = iteratee(child, childName, parent);
|
|
216
|
-
|
|
234
|
+
if (result) {
|
|
235
|
+
memo = combine(memo, result);
|
|
236
|
+
}
|
|
217
237
|
}
|
|
218
238
|
return memo;
|
|
219
|
-
},
|
|
239
|
+
}, initialMemo);
|
|
220
240
|
};
|
|
221
241
|
const childNames = children.map((c, i) => i);
|
|
222
242
|
return traverseChildren(children, childNames);
|
|
@@ -25,12 +25,17 @@ export default {
|
|
|
25
25
|
},
|
|
26
26
|
|
|
27
27
|
shallowToJS(x, whitelist) {
|
|
28
|
-
return this.isIterable(x)
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
28
|
+
return this.isIterable(x)
|
|
29
|
+
? x.reduce(
|
|
30
|
+
(prev, curr, key) => {
|
|
31
|
+
if (whitelist && whitelist[key]) {
|
|
32
|
+
curr = this.shallowToJS(curr);
|
|
33
|
+
}
|
|
34
|
+
prev[key] = curr;
|
|
35
|
+
return prev;
|
|
36
|
+
},
|
|
37
|
+
this.isList(x) ? [] : {}
|
|
38
|
+
)
|
|
39
|
+
: x;
|
|
35
40
|
}
|
|
36
41
|
};
|
|
@@ -7,7 +7,7 @@ import Helpers from "./helpers";
|
|
|
7
7
|
function getVerticalAnchor(props, datum) {
|
|
8
8
|
datum = datum || {};
|
|
9
9
|
const sign = datum._y >= 0 ? 1 : -1;
|
|
10
|
-
const labelStyle = props.style && props.style.labels || {};
|
|
10
|
+
const labelStyle = (props.style && props.style.labels) || {};
|
|
11
11
|
if (datum.verticalAnchor || labelStyle.verticalAnchor) {
|
|
12
12
|
return datum.verticalAnchor || labelStyle.verticalAnchor;
|
|
13
13
|
} else if (!props.horizontal) {
|
|
@@ -21,7 +21,7 @@ function getTextAnchor(props, datum) {
|
|
|
21
21
|
datum = datum || {};
|
|
22
22
|
const { style, horizontal } = props;
|
|
23
23
|
const sign = datum._y >= 0 ? 1 : -1;
|
|
24
|
-
const labelStyle = style && style.labels || {};
|
|
24
|
+
const labelStyle = (style && style.labels) || {};
|
|
25
25
|
if (datum.verticalAnchor || labelStyle.verticalAnchor) {
|
|
26
26
|
return datum.verticalAnchor || labelStyle.verticalAnchor;
|
|
27
27
|
} else if (!horizontal) {
|
|
@@ -33,7 +33,7 @@ function getTextAnchor(props, datum) {
|
|
|
33
33
|
|
|
34
34
|
function getAngle(props, datum) {
|
|
35
35
|
datum = datum || {};
|
|
36
|
-
const labelStyle = props.style && props.style.labels || {};
|
|
36
|
+
const labelStyle = (props.style && props.style.labels) || {};
|
|
37
37
|
return datum.angle === undefined ? labelStyle.angle : datum.angle;
|
|
38
38
|
}
|
|
39
39
|
|
|
@@ -74,24 +74,28 @@ function getPolarPadding(props, datum) {
|
|
|
74
74
|
const padding = Helpers.evaluateProp(labelStyle.padding, datum, active) || 0;
|
|
75
75
|
const angle = Helpers.degreesToRadians(degrees);
|
|
76
76
|
return {
|
|
77
|
-
x: padding * Math.cos(angle),
|
|
77
|
+
x: padding * Math.cos(angle),
|
|
78
|
+
y: -padding * Math.sin(angle)
|
|
78
79
|
};
|
|
79
80
|
}
|
|
80
81
|
|
|
81
82
|
function getLabelPlacement(props) {
|
|
82
83
|
const { labelComponent, labelPlacement, polar } = props;
|
|
83
84
|
const defaultLabelPlacement = polar ? "perpendicular" : "vertical";
|
|
84
|
-
return labelPlacement
|
|
85
|
-
labelPlacement
|
|
86
|
-
labelComponent.props && labelComponent.props.labelPlacement || defaultLabelPlacement;
|
|
85
|
+
return labelPlacement
|
|
86
|
+
? labelPlacement
|
|
87
|
+
: (labelComponent.props && labelComponent.props.labelPlacement) || defaultLabelPlacement;
|
|
87
88
|
}
|
|
88
89
|
|
|
89
90
|
function getPolarOrientation(degrees) {
|
|
90
|
-
|
|
91
|
+
// eslint-disable-next-line no-magic-numbers
|
|
92
|
+
if (degrees < 45 || degrees > 315) {
|
|
91
93
|
return "right";
|
|
92
|
-
|
|
94
|
+
// eslint-disable-next-line no-magic-numbers
|
|
95
|
+
} else if (degrees >= 45 && degrees <= 135) {
|
|
93
96
|
return "top";
|
|
94
|
-
|
|
97
|
+
// eslint-disable-next-line no-magic-numbers
|
|
98
|
+
} else if (degrees > 135 && degrees < 225) {
|
|
95
99
|
return "left";
|
|
96
100
|
} else {
|
|
97
101
|
return "bottom";
|
|
@@ -112,7 +116,7 @@ function getPolarTextAnchor(props, degrees) {
|
|
|
112
116
|
const labelPlacement = getLabelPlacement(props);
|
|
113
117
|
if (
|
|
114
118
|
labelPlacement === "perpendicular" ||
|
|
115
|
-
labelPlacement === "vertical" && (degrees === 90 || degrees === 270)
|
|
119
|
+
(labelPlacement === "vertical" && (degrees === 90 || degrees === 270))
|
|
116
120
|
) {
|
|
117
121
|
return "middle";
|
|
118
122
|
}
|
|
@@ -134,7 +138,7 @@ function getPolarAngle(props, baseAngle) {
|
|
|
134
138
|
return 0;
|
|
135
139
|
}
|
|
136
140
|
const degrees = baseAngle !== undefined ? baseAngle : getDegrees(props, datum);
|
|
137
|
-
const sign = (degrees > 90 && degrees < 180 || degrees > 270
|
|
141
|
+
const sign = (degrees > 90 && degrees < 180) || degrees > 270 ? 1 : -1;
|
|
138
142
|
let angle;
|
|
139
143
|
if (degrees === 0 || degrees === 180) {
|
|
140
144
|
angle = 90;
|
|
@@ -156,17 +160,29 @@ function getProps(props, index) {
|
|
|
156
160
|
const { scale, data, style, horizontal, polar } = props;
|
|
157
161
|
const datum = data[index];
|
|
158
162
|
const degrees = getDegrees(props, datum);
|
|
159
|
-
const textAnchor = polar ?
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
+
const textAnchor = polar ? getPolarTextAnchor(props, degrees) : getTextAnchor(props, datum);
|
|
164
|
+
const verticalAnchor = polar
|
|
165
|
+
? getPolarVerticalAnchor(props, degrees)
|
|
166
|
+
: getVerticalAnchor(props, datum);
|
|
163
167
|
const angle = getAngle(props, datum);
|
|
164
168
|
const text = getText(props, datum, index);
|
|
165
169
|
const labelPlacement = getLabelPlacement(props);
|
|
166
170
|
const { x, y } = getPosition(props, datum);
|
|
167
171
|
return {
|
|
168
|
-
angle,
|
|
169
|
-
|
|
172
|
+
angle,
|
|
173
|
+
data,
|
|
174
|
+
datum,
|
|
175
|
+
horizontal,
|
|
176
|
+
index,
|
|
177
|
+
polar,
|
|
178
|
+
scale,
|
|
179
|
+
labelPlacement,
|
|
180
|
+
text,
|
|
181
|
+
textAnchor,
|
|
182
|
+
verticalAnchor,
|
|
183
|
+
x,
|
|
184
|
+
y,
|
|
185
|
+
style: style.labels
|
|
170
186
|
};
|
|
171
187
|
}
|
|
172
188
|
|