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.
Files changed (71) hide show
  1. package/README.md +13 -12
  2. package/dist/victory-core.js +1083 -842
  3. package/dist/victory-core.min.js +1 -1
  4. package/es/victory-animation/victory-animation.js +26 -21
  5. package/es/victory-label/victory-label.js +8 -2
  6. package/es/victory-primitives/path-helpers.js +1 -1
  7. package/es/victory-transition/victory-transition.js +11 -6
  8. package/es/victory-util/add-events.js +66 -38
  9. package/es/victory-util/axis.js +35 -9
  10. package/es/victory-util/data.js +24 -9
  11. package/es/victory-util/domain.js +15 -7
  12. package/es/victory-util/events.js +1 -1
  13. package/es/victory-util/helpers.js +17 -5
  14. package/es/victory-util/label-helpers.js +3 -5
  15. package/es/victory-util/textsize.js +20 -20
  16. package/es/victory-util/transitions.js +16 -16
  17. package/es/victory-util/wrapper.js +56 -19
  18. package/lib/victory-animation/victory-animation.js +27 -21
  19. package/lib/victory-label/victory-label.js +8 -2
  20. package/lib/victory-primitives/path-helpers.js +1 -1
  21. package/lib/victory-transition/victory-transition.js +12 -6
  22. package/lib/victory-util/add-events.js +66 -38
  23. package/lib/victory-util/axis.js +36 -9
  24. package/lib/victory-util/data.js +25 -9
  25. package/lib/victory-util/domain.js +16 -8
  26. package/lib/victory-util/events.js +1 -1
  27. package/lib/victory-util/helpers.js +17 -5
  28. package/lib/victory-util/label-helpers.js +3 -5
  29. package/lib/victory-util/textsize.js +20 -20
  30. package/lib/victory-util/transitions.js +16 -16
  31. package/lib/victory-util/wrapper.js +56 -19
  32. package/package.json +1 -1
  33. package/src/victory-animation/util.js +47 -45
  34. package/src/victory-animation/victory-animation.js +66 -38
  35. package/src/victory-clip-container/victory-clip-container.js +44 -31
  36. package/src/victory-container/victory-container.js +35 -21
  37. package/src/victory-label/victory-label.js +55 -71
  38. package/src/victory-portal/portal.js +1 -1
  39. package/src/victory-portal/victory-portal.js +10 -7
  40. package/src/victory-primitives/arc.js +15 -4
  41. package/src/victory-primitives/border.js +26 -5
  42. package/src/victory-primitives/circle.js +14 -3
  43. package/src/victory-primitives/clip-path.js +2 -7
  44. package/src/victory-primitives/line-segment.js +28 -5
  45. package/src/victory-primitives/line.js +15 -2
  46. package/src/victory-primitives/path-helpers.js +6 -7
  47. package/src/victory-primitives/point.js +30 -11
  48. package/src/victory-primitives/rect.js +19 -3
  49. package/src/victory-primitives/text.js +21 -11
  50. package/src/victory-primitives/tspan.js +6 -4
  51. package/src/victory-primitives/whisker.js +13 -6
  52. package/src/victory-theme/grayscale.js +153 -128
  53. package/src/victory-theme/material.js +178 -149
  54. package/src/victory-transition/victory-transition.js +31 -25
  55. package/src/victory-util/add-events.js +113 -75
  56. package/src/victory-util/axis.js +89 -35
  57. package/src/victory-util/collection.js +3 -8
  58. package/src/victory-util/common-props.js +42 -36
  59. package/src/victory-util/data.js +78 -43
  60. package/src/victory-util/domain.js +68 -46
  61. package/src/victory-util/events.js +129 -112
  62. package/src/victory-util/helpers.js +36 -16
  63. package/src/victory-util/immutable.js +12 -7
  64. package/src/victory-util/label-helpers.js +34 -18
  65. package/src/victory-util/prop-types.js +11 -23
  66. package/src/victory-util/scale.js +2 -3
  67. package/src/victory-util/selection.js +4 -5
  68. package/src/victory-util/style.js +17 -10
  69. package/src/victory-util/textsize.js +35 -31
  70. package/src/victory-util/transitions.js +53 -35
  71. package/src/victory-util/wrapper.js +112 -56
@@ -1,5 +1,13 @@
1
1
  import {
2
- assign, defaults, flatten, isFunction, uniq, some, groupBy, values, isPlainObject
2
+ assign,
3
+ defaults,
4
+ flatten,
5
+ isFunction,
6
+ uniq,
7
+ some,
8
+ groupBy,
9
+ values,
10
+ isPlainObject
3
11
  } from "lodash";
4
12
  import React from "react";
5
13
  import Axis from "./axis";
@@ -24,7 +32,7 @@ export default {
24
32
  const horizontalChildren = childComponents.some((component) => {
25
33
  return component.props && component.props.horizontal;
26
34
  });
27
- const horizontal = props && props.horizontal || horizontalChildren;
35
+ const horizontal = (props && props.horizontal) || horizontalChildren;
28
36
  const groupComponent = childComponents.filter((child) => {
29
37
  return child.type && child.type.role && child.type.role === "group";
30
38
  });
@@ -33,9 +41,9 @@ export default {
33
41
  return undefined;
34
42
  }
35
43
  const { offset, children } = groupComponent[0].props;
36
- const defaultDomainPadding = horizontal ?
37
- { y: (offset * children.length) / 2 } :
38
- { x: (offset * children.length) / 2 };
44
+ const defaultDomainPadding = horizontal
45
+ ? { y: (offset * children.length) / 2 }
46
+ : { x: (offset * children.length) / 2 };
39
47
  return defaultDomainPadding[axis];
40
48
  },
41
49
 
@@ -44,8 +52,9 @@ export default {
44
52
  const propsDomain = Domain.getDomainFromProps(props, axis);
45
53
  const minDomain = Domain.getMinFromProps(props, axis);
46
54
  const maxDomain = Domain.getMaxFromProps(props, axis);
47
- const domainPadding = props.polar ?
48
- 0 : this.getDefaultDomainPadding(props, axis, childComponents);
55
+ const domainPadding = props.polar
56
+ ? 0
57
+ : this.getDefaultDomainPadding(props, axis, childComponents);
49
58
  let domain;
50
59
  if (propsDomain) {
51
60
  domain = propsDomain;
@@ -76,9 +85,13 @@ export default {
76
85
  return Array.isArray(child) ? some(child, check) : check(child);
77
86
  };
78
87
 
79
- const continuous = !props.polar && some(oldChildren, (child) => {
80
- return isContinuous(child) || child.props.children && isContinuous(child.props.children);
81
- });
88
+ const continuous =
89
+ !props.polar &&
90
+ some(oldChildren, (child) => {
91
+ return (
92
+ isContinuous(child) || (child.props.children && isContinuous(child.props.children))
93
+ );
94
+ });
82
95
  const {
83
96
  nodesWillExit,
84
97
  nodesWillEnter,
@@ -90,8 +103,9 @@ export default {
90
103
  nodesWillExit,
91
104
  nodesWillEnter,
92
105
  nodesShouldEnter,
93
- childrenTransitions: Collection.isArrayOfArrays(childrenTransitions) ?
94
- childrenTransitions[0] : childrenTransitions,
106
+ childrenTransitions: Collection.isArrayOfArrays(childrenTransitions)
107
+ ? childrenTransitions[0]
108
+ : childrenTransitions,
95
109
  oldProps: nodesWillExit ? props : null,
96
110
  nextProps,
97
111
  continuous
@@ -102,11 +116,13 @@ export default {
102
116
  getAllEvents(props) {
103
117
  const components = ["groupComponent", "containerComponent", "labelComponent"];
104
118
  this.componentEvents = Events.getComponentEvents(props, components);
119
+ let events = props.events;
105
120
  if (Array.isArray(this.componentEvents)) {
106
- return Array.isArray(props.events) ?
107
- this.componentEvents.concat(...props.events) : this.componentEvents;
121
+ events = Array.isArray(props.events)
122
+ ? this.componentEvents.concat(...props.events)
123
+ : this.componentEvents;
108
124
  }
109
- return props.events;
125
+ return events || [];
110
126
  },
111
127
 
112
128
  getAnimationProps(props, child, index) {
@@ -115,38 +131,40 @@ export default {
115
131
  }
116
132
  const getFilteredState = () => {
117
133
  let childrenTransitions = this.state && this.state.childrenTransitions;
118
- childrenTransitions = Collection.isArrayOfArrays(childrenTransitions) ?
119
- childrenTransitions[index] : childrenTransitions;
134
+ childrenTransitions = Collection.isArrayOfArrays(childrenTransitions)
135
+ ? childrenTransitions[index]
136
+ : childrenTransitions;
120
137
  return defaults({ childrenTransitions }, this.state);
121
138
  };
122
139
 
123
140
  let getTransitions = props.animate && props.animate.getTransitions;
124
141
  const state = getFilteredState();
125
- const parentState = props.animate && props.animate.parentState || state;
142
+ const parentState = (props.animate && props.animate.parentState) || state;
126
143
  if (!getTransitions) {
127
- const getTransitionProps = Transitions.getTransitionPropsFactory(
128
- props,
129
- state,
130
- (newState) => this.setState(newState)
144
+ const getTransitionProps = Transitions.getTransitionPropsFactory(props, state, (newState) =>
145
+ this.setState(newState)
131
146
  );
132
147
  getTransitions = (childComponent) => getTransitionProps(childComponent, index);
133
148
  }
134
149
  return defaults({ getTransitions, parentState }, props.animate, child.props.animate);
135
150
  },
136
151
 
137
- getDomainFromChildren(props, axis, childComponents) { // eslint-disable-line max-statements, complexity, max-len
138
- const children = childComponents ?
139
- childComponents.slice(0) : React.Children.toArray(props.children);
152
+ getDomainFromChildren(props, axis, childComponents) {
153
+ // eslint-disable-line max-statements, complexity, max-len
154
+ const children = childComponents
155
+ ? childComponents.slice(0)
156
+ : React.Children.toArray(props.children);
140
157
  const horizontalChildren = childComponents.some((component) => {
141
158
  return component.props && component.props.horizontal;
142
159
  });
143
- const horizontal = props && props.horizontal || horizontalChildren.length > 0;
160
+ const horizontal = (props && props.horizontal) || horizontalChildren.length > 0;
144
161
  const currentAxis = Axis.getCurrentAxis(axis, horizontal);
145
162
  const parentData = props.data ? Data.getData(props, axis) : undefined;
146
163
  const { polar, startAngle, endAngle, categories, minDomain, maxDomain } = props;
147
164
  const baseParentProps = { polar, startAngle, endAngle, categories, minDomain, maxDomain };
148
- const parentProps = parentData ?
149
- assign(baseParentProps, { data: parentData }) : baseParentProps;
165
+ const parentProps = parentData
166
+ ? assign(baseParentProps, { data: parentData })
167
+ : baseParentProps;
150
168
 
151
169
  const iteratee = (child) => {
152
170
  const sharedProps = assign({}, child.props, parentProps);
@@ -182,13 +200,14 @@ export default {
182
200
  childData = Data.getData(childProps);
183
201
  }
184
202
  stack += 1;
185
- return childData.map((datum) => assign({ stack }, datum));
203
+ return childData.map((datum, index) => assign({ stack, group: index }, datum));
186
204
  };
187
- const children = childComponents ?
188
- childComponents.slice(0) : React.Children.toArray(props.children);
205
+ const children = childComponents
206
+ ? childComponents.slice(0)
207
+ : React.Children.toArray(props.children);
189
208
  const stacked = children.filter((c) => c.type && c.type.role === "stack").length;
190
209
  const datasets = Helpers.reduceChildren(children, iteratee, props);
191
- const group = stacked ? "eventKey" : "stack";
210
+ const group = stacked ? "group" : "stack";
192
211
  return values(groupBy(datasets, group));
193
212
  },
194
213
 
@@ -204,8 +223,7 @@ export default {
204
223
  if (!colorScale && !color) {
205
224
  return undefined;
206
225
  }
207
- const colors = Array.isArray(colorScale) ?
208
- colorScale : Style.getColorScale(colorScale);
226
+ const colors = Array.isArray(colorScale) ? colorScale : Style.getColorScale(colorScale);
209
227
  return color || colors[index % colors.length];
210
228
  },
211
229
 
@@ -214,9 +232,9 @@ export default {
214
232
  const range = horizontal ? scale.y.range() : scale.x.range();
215
233
  const extent = Math.abs(range[1] - range[0]);
216
234
  const seriesLength = Array.isArray(datasets[0]) ? datasets[0].length : 1;
217
- const bars = datasets.length * (seriesLength) + 2;
235
+ const bars = datasets.length * seriesLength + 2;
218
236
  const barRatio = 0.5;
219
- return { width: Math.round(barRatio * extent / bars) };
237
+ return { width: Math.round((barRatio * extent) / bars) };
220
238
  },
221
239
 
222
240
  getStyle(theme, style, role) {
@@ -231,13 +249,15 @@ export default {
231
249
  return childStyle;
232
250
  }
233
251
  const childRole = child.type && child.type.role;
234
- const defaultFill = childRole === "stack" ?
235
- undefined : this.getColor(calculatedProps, child, index);
236
- const defaultColor = childRole === "line" ?
237
- { fill: "none", stroke: defaultFill } : { fill: defaultFill };
252
+ const defaultFill =
253
+ childRole === "stack" ? undefined : this.getColor(calculatedProps, child, index);
254
+ const defaultColor =
255
+ childRole === "line" ? { fill: "none", stroke: defaultFill } : { fill: defaultFill };
238
256
  const dataWidth = role === "stack" ? {} : this.getWidth(calculatedProps);
239
257
  const dataStyle = defaults(
240
- {}, childStyle.data, assign({}, dataWidth, style.data, defaultColor)
258
+ {},
259
+ childStyle.data,
260
+ assign({}, dataWidth, style.data, defaultColor)
241
261
  );
242
262
  const labelsStyle = defaults({}, childStyle.labels, style.labels);
243
263
  return {
@@ -253,8 +273,10 @@ export default {
253
273
  if (!Domain.isDomainComponent(child) || !childProps.categories) {
254
274
  return null;
255
275
  } else {
256
- const categories = childProps.categories && !Array.isArray(childProps.categories) ?
257
- childProps.categories[axis] : childProps.rops.categories;
276
+ const categories =
277
+ childProps.categories && !Array.isArray(childProps.categories)
278
+ ? childProps.categories[axis]
279
+ : childProps.props.categories;
258
280
  const categoryStrings = categories && categories.filter((val) => typeof val === "string");
259
281
  return categoryStrings ? Collection.removeUndefined(categoryStrings) : [];
260
282
  }
@@ -262,7 +284,7 @@ export default {
262
284
  return Helpers.reduceChildren(childComponents.slice(0), iteratee);
263
285
  },
264
286
 
265
- getStringsFromData(childComponents, axis) {
287
+ getStringsFromData(childComponents) {
266
288
  const iteratee = (child) => {
267
289
  const childProps = child.props || {};
268
290
  let data;
@@ -273,27 +295,61 @@ export default {
273
295
  } else {
274
296
  data = Data.getData(childProps);
275
297
  }
276
- const attr = axis === "x" ? "xName" : "yName";
277
- return data.map((d) => d[attr]).filter(Boolean);
298
+ return data.map((d) => ({ x: d.xName, y: d.yName }));
278
299
  };
279
- return Helpers.reduceChildren(childComponents.slice(0), iteratee);
300
+
301
+ const initialMemo = { x: [], y: [] };
302
+ const combine = (memo, datum) => {
303
+ const x = Array.isArray(datum) ? datum.map((d) => d.x).filter(Boolean) : datum.x;
304
+ const y = Array.isArray(datum) ? datum.map((d) => d.y).filter(Boolean) : datum.y;
305
+ return {
306
+ x: x !== undefined ? memo.x.concat(x) : memo.x,
307
+ y: y !== undefined ? memo.y.concat(y) : memo.y
308
+ };
309
+ };
310
+ return Helpers.reduceChildren(childComponents.slice(0), iteratee, {}, initialMemo, combine);
280
311
  },
281
312
 
282
- getStringsFromChildren(props, axis, childComponents) {
313
+ getCategoryAndAxisStringsFromChildren(props, axis, childComponents) {
283
314
  const currentAxis = Helpers.getCurrentAxis(axis, props.horizontal);
284
- childComponents = childComponents || React.Children.toArray(props.children);
285
315
  const categories = isPlainObject(props.categories) ? props.categories[axis] : props.categories;
286
316
  const axisComponent = Axis.getAxisComponent(childComponents, currentAxis);
287
317
  const axisStrings = axisComponent ? Data.getStringsFromAxes(axisComponent.props, axis) : [];
288
318
  const categoryStrings = categories || this.getStringsFromCategories(childComponents, axis);
289
- const dataStrings = this.getStringsFromData(childComponents, axis);
290
- return uniq(flatten([...categoryStrings, ...dataStrings, ...axisStrings]));
319
+ return uniq(flatten([...categoryStrings, ...axisStrings]));
291
320
  },
292
321
 
293
- getCategories(props, axis) {
294
- const propCategories = props.categories && !Array.isArray(props.categories) ?
295
- props.categories[axis] : props.categories;
296
- const categories = propCategories || this.getStringsFromChildren(props, axis);
297
- return categories.length > 0 ? categories : undefined;
322
+ getStringsFromChildren(props, childComponents) {
323
+ childComponents = childComponents || React.Children.toArray(props.children);
324
+
325
+ const xStrings = this.getCategoryAndAxisStringsFromChildren(props, "x", childComponents);
326
+ const yStrings = this.getCategoryAndAxisStringsFromChildren(props, "y", childComponents);
327
+
328
+ const dataStrings = this.getStringsFromData(childComponents);
329
+
330
+ return {
331
+ x: uniq(flatten([...xStrings, ...dataStrings.x])),
332
+ y: uniq(flatten([...yStrings, ...dataStrings.y]))
333
+ };
334
+ },
335
+
336
+ getCategories(props) {
337
+ const xPropCategories =
338
+ props.categories && !Array.isArray(props.categories) ? props.categories.x : props.categories;
339
+
340
+ const yPropCategories =
341
+ props.categories && !Array.isArray(props.categories) ? props.categories.y : props.categories;
342
+
343
+ const fallbackRequired = !xPropCategories || !yPropCategories;
344
+
345
+ const fallbackProps = fallbackRequired ? this.getStringsFromChildren(props) : {};
346
+
347
+ const xCategories = xPropCategories || fallbackProps.x;
348
+ const yCategories = yPropCategories || fallbackProps.y;
349
+
350
+ return {
351
+ x: xCategories.length > 0 ? xCategories : undefined,
352
+ y: yCategories.length > 0 ? yCategories : undefined
353
+ };
298
354
  }
299
355
  };