victory-core 35.11.3 → 36.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 (31) hide show
  1. package/dist/victory-core.js +10581 -8123
  2. package/dist/victory-core.min.js +1 -1
  3. package/es/index.js +9 -2
  4. package/es/victory-label/victory-label.js +3 -3
  5. package/es/victory-primitives/point.js +1 -1
  6. package/es/victory-util/hooks/index.js +2 -0
  7. package/es/victory-util/hooks/use-animation-state.js +130 -0
  8. package/es/victory-util/hooks/use-previous-props.js +8 -0
  9. package/es/victory-util/line-helpers.js +45 -0
  10. package/es/{victory-primitives/path-helpers.js → victory-util/point-path-helpers.js} +0 -0
  11. package/es/victory-util/wrapper.js +372 -457
  12. package/lib/index.js +20 -8
  13. package/lib/victory-label/victory-label.js +3 -3
  14. package/lib/victory-primitives/point.js +10 -10
  15. package/lib/victory-util/hooks/index.js +21 -0
  16. package/lib/victory-util/hooks/use-animation-state.js +151 -0
  17. package/lib/victory-util/hooks/use-previous-props.js +22 -0
  18. package/lib/victory-util/line-helpers.js +56 -0
  19. package/lib/{victory-primitives/path-helpers.js → victory-util/point-path-helpers.js} +0 -0
  20. package/lib/victory-util/wrapper.js +389 -446
  21. package/package.json +6 -3
  22. package/src/index.js +5 -1
  23. package/src/victory-label/victory-label.js +3 -3
  24. package/src/victory-primitives/point.js +1 -1
  25. package/src/victory-util/hooks/index.js +2 -0
  26. package/src/victory-util/hooks/use-animation-state.js +123 -0
  27. package/src/victory-util/hooks/use-previous-props.js +9 -0
  28. package/src/victory-util/line-helpers.js +54 -0
  29. package/src/{victory-primitives/path-helpers.js → victory-util/point-path-helpers.js} +0 -0
  30. package/src/victory-util/transitions.js +0 -1
  31. package/src/victory-util/wrapper.js +422 -518
@@ -2,17 +2,12 @@ import _isPlainObject from "lodash/isPlainObject";
2
2
  import _values from "lodash/values";
3
3
  import _uniqBy from "lodash/uniqBy";
4
4
  import _groupBy from "lodash/groupBy";
5
- import _some from "lodash/some";
6
5
  import _uniq from "lodash/uniq";
7
6
  import _isFunction from "lodash/isFunction";
8
7
  import _flatten from "lodash/flatten";
9
8
  import _defaults from "lodash/defaults";
10
9
  import _assign from "lodash/assign";
11
10
 
12
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; var ownKeys = Object.keys(source); if (typeof Object.getOwnPropertySymbols === 'function') { ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function (sym) { return Object.getOwnPropertyDescriptor(source, sym).enumerable; })); } ownKeys.forEach(function (key) { _defineProperty(target, key, source[key]); }); } return target; }
13
-
14
- function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
15
-
16
11
  function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _nonIterableSpread(); }
17
12
 
18
13
  function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance"); }
@@ -21,10 +16,13 @@ function _iterableToArray(iter) { if (Symbol.iterator in Object(iter) || Object.
21
16
 
22
17
  function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = new Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } }
23
18
 
19
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; var ownKeys = Object.keys(source); if (typeof Object.getOwnPropertySymbols === 'function') { ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function (sym) { return Object.getOwnPropertyDescriptor(source, sym).enumerable; })); } ownKeys.forEach(function (key) { _defineProperty(target, key, source[key]); }); } return target; }
20
+
21
+ function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
22
+
24
23
  import React from "react";
25
24
  import * as Axis from "./axis";
26
25
  import * as Style from "./style";
27
- import * as Transitions from "./transitions";
28
26
  import * as Data from "./data";
29
27
  import * as Domain from "./domain";
30
28
  import * as Events from "./events";
@@ -32,497 +30,414 @@ import * as Collection from "./collection";
32
30
  import * as Helpers from "./helpers";
33
31
  import * as Scale from "./scale";
34
32
  import * as Log from "./log";
35
- export default {
36
- getData: function (props, childComponents) {
37
- if (props.data) {
38
- return Data.getData(props);
39
- }
40
-
41
- childComponents = childComponents || React.Children.toArray(props.children);
42
- return this.getDataFromChildren(childComponents);
43
- },
44
- getDefaultDomainPadding: function (props, axis, childComponents) {
45
- if (props.polar || axis !== "x") {
46
- return undefined;
47
- }
48
-
49
- var groupComponent = childComponents.filter(function (child) {
50
- return child.type && child.type.role && child.type.role === "group";
51
- });
52
-
53
- if (groupComponent.length < 1) {
54
- return undefined;
55
- }
56
-
57
- var _groupComponent$0$pro = groupComponent[0].props,
58
- offset = _groupComponent$0$pro.offset,
59
- children = _groupComponent$0$pro.children;
60
-
61
- if (!offset) {
62
- return undefined;
63
- }
64
-
65
- var firstChild = Array.isArray(children) && children[0];
66
-
67
- if (!firstChild) {
68
- return undefined;
69
- }
70
-
71
- var barWidth = firstChild.props.barWidth;
72
- var dataLength = firstChild.props.data && firstChild.props.data.length || 1;
33
+ export function addBinsToParentPropsIfHistogram(_ref) {
34
+ var children = _ref.children,
35
+ props = _ref.props,
36
+ childComponents = _ref.childComponents,
37
+ parentProps = _ref.parentProps;
38
+ var someChildrenAreHistograms = children.some(function (child) {
39
+ return child.type && child.type.role === "histogram";
40
+ });
41
+ var allChildrenAreHistograms = someChildrenAreHistograms && children.length && children.every(function (child) {
42
+ return child.type && child.type.role === "histogram";
43
+ });
44
+
45
+ if (someChildrenAreHistograms && !allChildrenAreHistograms) {
46
+ Log.warn("VictoryHistogram only supports being stacked with other VictoryHistogram components. Check to make sure that you are only passing VictoryHistogram components to VictoryStack");
47
+ } // if we are stacking histograms, we need to generate explicit bins
48
+ // or else each histogram may end up having different bins
49
+
50
+
51
+ if (!allChildrenAreHistograms) {
52
+ return parentProps;
53
+ }
73
54
 
74
- if (firstChild && firstChild.type.role === "stack") {
75
- var nestedChild = firstChild.props.children && firstChild.props.children[0];
55
+ var childBins = props.bins || childComponents[0].props.bins; // if we have explicit bins then we don't need to calculate them
76
56
 
77
- if (!nestedChild) {
78
- return undefined;
79
- }
57
+ if (!Array.isArray(childBins)) {
58
+ var combinedData = children.reduce(function (memo, child) {
59
+ var xAccessor = Helpers.createAccessor(child.props.x || "x");
60
+ return memo.concat(child.props.data.map(function (datum) {
61
+ return {
62
+ x: xAccessor(datum)
63
+ };
64
+ }));
65
+ }, []); // use the same function to generate bins as VictoryHistogram but with
66
+ // the combined data from above, then get explicit bins from that
80
67
 
81
- barWidth = nestedChild.props.barWidth;
82
- dataLength = firstChild.props.children.length;
83
- }
68
+ var getFormattedHistogramData = children[0].type.getFormattedData;
69
+ childBins = getFormattedHistogramData({
70
+ data: combinedData,
71
+ bins: childBins
72
+ }).reduce(function (memo, _ref2, index) {
73
+ var x0 = _ref2.x0,
74
+ x1 = _ref2.x1;
75
+ return index === 0 ? memo.concat([x0, x1]) : memo.concat(x1);
76
+ }, []);
77
+ }
84
78
 
85
- var width = barWidth || this.getWidth(props, children.length, dataLength);
86
- return {
87
- x: width * children.length / 2 + (offset - width * ((children.length - 1) / 2))
88
- };
89
- },
90
- getDomain: function (props, axis, childComponents) {
91
- childComponents = childComponents || React.Children.toArray(props.children);
92
- var propsDomain = Domain.getDomainFromProps(props, axis);
93
- var domainPadding = this.getDefaultDomainPadding(props, axis, childComponents);
94
- var domain;
95
-
96
- if (propsDomain) {
97
- domain = propsDomain;
79
+ return _objectSpread({}, parentProps, {
80
+ bins: childBins
81
+ });
82
+ }
83
+ export function getDataFromChildren(props, childComponents) {
84
+ var polar = props.polar,
85
+ startAngle = props.startAngle,
86
+ endAngle = props.endAngle,
87
+ categories = props.categories,
88
+ minDomain = props.minDomain,
89
+ maxDomain = props.maxDomain;
90
+ var parentProps = {
91
+ polar: polar,
92
+ startAngle: startAngle,
93
+ endAngle: endAngle,
94
+ categories: categories,
95
+ minDomain: minDomain,
96
+ maxDomain: maxDomain
97
+ };
98
+ var stack = 0;
99
+ var children = childComponents ? childComponents.slice(0) : React.Children.toArray(props.children);
100
+ parentProps = addBinsToParentPropsIfHistogram({
101
+ children: children,
102
+ props: props,
103
+ childComponents: childComponents,
104
+ parentProps: parentProps
105
+ });
106
+
107
+ var iteratee = function (child, childName, parent) {
108
+ var childProps = _assign({}, child.props, parentProps);
109
+
110
+ var childData;
111
+
112
+ if (!Data.isDataComponent(child)) {
113
+ return null;
114
+ } else if (child.type && _isFunction(child.type.getData)) {
115
+ child = parent ? React.cloneElement(child, parent.props) : child;
116
+ childData = child.type.getData(childProps);
98
117
  } else {
99
- var minDomain = Domain.getMinFromProps(props, axis);
100
- var maxDomain = Domain.getMaxFromProps(props, axis);
101
- var dataset = (props.data || props.y) && Data.getData(props);
102
- var dataDomain = dataset ? Domain.getDomainFromData(props, axis, dataset) : [];
103
- var childDomain = this.getDomainFromChildren(props, axis, childComponents);
104
- var min = minDomain || Collection.getMinValue(_toConsumableArray(dataDomain).concat(_toConsumableArray(childDomain)));
105
- var max = maxDomain || Collection.getMaxValue(_toConsumableArray(dataDomain).concat(_toConsumableArray(childDomain)));
106
- domain = Domain.getDomainFromMinMax(min, max);
107
- }
108
-
109
- return Domain.formatDomain(domain, _assign({
110
- domainPadding: domainPadding
111
- }, props), axis);
112
- },
113
- getScale: function (props, axis, childComponents) {
114
- if (props.data) {
115
- return Scale.getBaseScale(props, axis);
118
+ childData = Data.getData(childProps);
116
119
  }
117
120
 
118
- var children = childComponents ? childComponents.slice(0) : React.Children.toArray(props.children);
119
-
120
- var iteratee = function (child) {
121
- var sharedProps = _assign({}, child.props, {
122
- horizontal: props.horizontal
123
- });
124
-
125
- return Scale.getScaleType(sharedProps, axis);
126
- };
121
+ stack += 1;
122
+ return childData.map(function (datum, index) {
123
+ return _assign({
124
+ _stack: stack,
125
+ _group: index
126
+ }, datum);
127
+ });
128
+ };
129
+
130
+ var stacked = children.filter(function (c) {
131
+ return c.type && c.type.role === "stack";
132
+ }).length;
133
+
134
+ var combine = function (memo, val) {
135
+ return memo.concat(_uniqBy(val, "_group"));
136
+ };
137
+
138
+ var datasets = Helpers.reduceChildren(children, iteratee, props, [], combine);
139
+ var group = stacked ? "_group" : "_stack";
140
+ return _values(_groupBy(datasets, group));
141
+ }
142
+ export function getData(props, childComponents) {
143
+ if (props.data) {
144
+ return Data.getData(props);
145
+ }
127
146
 
128
- var childScale = _uniq(Helpers.reduceChildren(children, iteratee, props)); // default to linear scale if more than one uniq scale type is given by children
147
+ childComponents = childComponents || React.Children.toArray(props.children);
148
+ return getDataFromChildren(childComponents);
149
+ }
150
+ export function getWidth(props, groupLength, seriesLength) {
151
+ var datasets = props.datasets,
152
+ horizontal = props.horizontal;
153
+ var range = horizontal ? Helpers.getRange(props, "y") : Helpers.getRange(props, "x");
154
+ var extent = Math.abs(range[1] - range[0]);
155
+ seriesLength = seriesLength !== undefined ? seriesLength : Array.isArray(datasets[0]) && datasets[0].length || 1;
156
+ groupLength = groupLength || datasets.length;
157
+ var bars = groupLength * seriesLength;
158
+ var barRatio = 0.5;
159
+ return Math.round(barRatio * extent / bars);
160
+ }
161
+ export function getDefaultDomainPadding(props, axis, childComponents) {
162
+ if (props.polar || axis !== "x") {
163
+ return undefined;
164
+ }
129
165
 
166
+ var groupComponent = childComponents.filter(function (child) {
167
+ return child.type && child.type.role && child.type.role === "group";
168
+ });
130
169
 
131
- return childScale.length > 1 ? Scale.getScaleFromName("linear") : Scale.getScaleFromName(childScale[0]);
132
- },
133
- setAnimationState: function (props, nextProps) {
134
- if (!props.animate) {
135
- return;
136
- }
170
+ if (groupComponent.length < 1) {
171
+ return undefined;
172
+ }
137
173
 
138
- if (props.animate.parentState) {
139
- var nodesWillExit = props.animate.parentState.nodesWillExit;
140
- var oldProps = nodesWillExit ? props : null;
141
- this.setState(_defaults({
142
- oldProps: oldProps,
143
- nextProps: nextProps
144
- }, props.animate.parentState));
145
- } else {
146
- var oldChildren = React.Children.toArray(props.children);
147
- var nextChildren = React.Children.toArray(nextProps.children);
174
+ var _groupComponent$0$pro = groupComponent[0].props,
175
+ offset = _groupComponent$0$pro.offset,
176
+ children = _groupComponent$0$pro.children;
148
177
 
149
- var isContinuous = function (child) {
150
- var check = function (c) {
151
- return c.type && c.type.continuous;
152
- };
178
+ if (!offset) {
179
+ return undefined;
180
+ }
153
181
 
154
- return Array.isArray(child) ? _some(child, check) : check(child);
155
- };
182
+ var firstChild = Array.isArray(children) && children[0];
156
183
 
157
- var continuous = !props.polar && _some(oldChildren, function (child) {
158
- return isContinuous(child) || child.props.children && isContinuous(child.props.children);
159
- });
184
+ if (!firstChild) {
185
+ return undefined;
186
+ }
160
187
 
161
- var _Transitions$getIniti = Transitions.getInitialTransitionState(oldChildren, nextChildren),
162
- _nodesWillExit = _Transitions$getIniti.nodesWillExit,
163
- nodesWillEnter = _Transitions$getIniti.nodesWillEnter,
164
- childrenTransitions = _Transitions$getIniti.childrenTransitions,
165
- nodesShouldEnter = _Transitions$getIniti.nodesShouldEnter;
166
-
167
- this.setState({
168
- nodesWillExit: _nodesWillExit,
169
- nodesWillEnter: nodesWillEnter,
170
- nodesShouldEnter: nodesShouldEnter,
171
- childrenTransitions: Collection.isArrayOfArrays(childrenTransitions) ? childrenTransitions[0] : childrenTransitions,
172
- oldProps: _nodesWillExit ? props : null,
173
- nextProps: nextProps,
174
- continuous: continuous
175
- });
176
- }
177
- },
178
- getAllEvents: function (props) {
179
- var components = ["groupComponent", "containerComponent", "labelComponent"];
180
- this.componentEvents = Events.getComponentEvents(props, components);
181
- var events = props.events;
188
+ var barWidth = firstChild.props.barWidth;
189
+ var dataLength = firstChild.props.data && firstChild.props.data.length || 1;
182
190
 
183
- if (Array.isArray(this.componentEvents)) {
184
- var _componentEvents;
191
+ if (firstChild && firstChild.type.role === "stack") {
192
+ var nestedChild = firstChild.props.children && firstChild.props.children[0];
185
193
 
186
- events = Array.isArray(props.events) ? (_componentEvents = this.componentEvents).concat.apply(_componentEvents, _toConsumableArray(props.events)) : this.componentEvents;
194
+ if (!nestedChild) {
195
+ return undefined;
187
196
  }
188
197
 
189
- return events || [];
190
- },
191
- getAnimationProps: function (props, child, index) {
192
- var _this = this;
198
+ barWidth = nestedChild.props.barWidth;
199
+ dataLength = firstChild.props.children.length;
200
+ }
193
201
 
194
- if (!props.animate) {
195
- return child.props.animate;
202
+ var width = barWidth || getWidth(props, children.length, dataLength);
203
+ return {
204
+ x: width * children.length / 2 + (offset - width * ((children.length - 1) / 2))
205
+ };
206
+ }
207
+ export function getDomainFromChildren(props, axis, childComponents) {
208
+ // eslint-disable-line max-statements, complexity, max-len
209
+ var children = childComponents ? childComponents.slice(0) : React.Children.toArray(props.children);
210
+ var parentData = props.data ? Data.getData(props, axis) : undefined;
211
+ var polar = props.polar,
212
+ startAngle = props.startAngle,
213
+ endAngle = props.endAngle,
214
+ categories = props.categories,
215
+ minDomain = props.minDomain,
216
+ maxDomain = props.maxDomain,
217
+ horizontal = props.horizontal;
218
+ var baseParentProps = {
219
+ horizontal: horizontal,
220
+ polar: polar,
221
+ startAngle: startAngle,
222
+ endAngle: endAngle,
223
+ minDomain: minDomain,
224
+ maxDomain: maxDomain,
225
+ categories: categories
226
+ };
227
+ var parentProps = parentData ? _assign(baseParentProps, {
228
+ data: parentData
229
+ }) : baseParentProps;
230
+
231
+ var iteratee = function (child) {
232
+ var sharedProps = _assign({}, child.props, parentProps);
233
+
234
+ if (!Domain.isDomainComponent(child)) {
235
+ return null;
236
+ } else if (child.type && _isFunction(child.type.getDomain)) {
237
+ return child.props && child.type.getDomain(sharedProps, axis);
238
+ } else {
239
+ return Domain.getDomain(sharedProps, axis);
196
240
  }
241
+ };
242
+
243
+ var childDomains = Helpers.reduceChildren(children, iteratee, props);
244
+ var min = childDomains.length === 0 ? 0 : Collection.getMinValue(childDomains);
245
+ var max = childDomains.length === 0 ? 1 : Collection.getMaxValue(childDomains);
246
+ return [min, max];
247
+ }
248
+ export function getDomain(props, axis, childComponents) {
249
+ childComponents = childComponents || React.Children.toArray(props.children);
250
+ var propsDomain = Domain.getDomainFromProps(props, axis);
251
+ var domainPadding = getDefaultDomainPadding(props, axis, childComponents);
252
+ var domain;
253
+
254
+ if (propsDomain) {
255
+ domain = propsDomain;
256
+ } else {
257
+ var minDomain = Domain.getMinFromProps(props, axis);
258
+ var maxDomain = Domain.getMaxFromProps(props, axis);
259
+ var dataset = (props.data || props.y) && Data.getData(props);
260
+ var dataDomain = dataset ? Domain.getDomainFromData(props, axis, dataset) : [];
261
+ var childDomain = getDomainFromChildren(props, axis, childComponents);
262
+ var min = minDomain || Collection.getMinValue(_toConsumableArray(dataDomain).concat(_toConsumableArray(childDomain)));
263
+ var max = maxDomain || Collection.getMaxValue(_toConsumableArray(dataDomain).concat(_toConsumableArray(childDomain)));
264
+ domain = Domain.getDomainFromMinMax(min, max);
265
+ }
197
266
 
198
- var getFilteredState = function () {
199
- var childrenTransitions = _this.state && _this.state.childrenTransitions;
200
- childrenTransitions = Collection.isArrayOfArrays(childrenTransitions) ? childrenTransitions[index] : childrenTransitions;
201
- return _defaults({
202
- childrenTransitions: childrenTransitions
203
- }, _this.state);
204
- };
205
-
206
- var getTransitions = props.animate && props.animate.getTransitions;
207
- var state = getFilteredState();
208
- var parentState = props.animate && props.animate.parentState || state;
209
-
210
- if (!getTransitions) {
211
- var getTransitionProps = Transitions.getTransitionPropsFactory(props, state, function (newState) {
212
- return _this.setState(newState);
213
- });
214
-
215
- getTransitions = function (childComponent) {
216
- return getTransitionProps(childComponent, index);
217
- };
218
- }
267
+ return Domain.formatDomain(domain, _assign({
268
+ domainPadding: domainPadding
269
+ }, props), axis);
270
+ }
271
+ export function getScale(props, axis, childComponents) {
272
+ if (props.data) {
273
+ return Scale.getBaseScale(props, axis);
274
+ }
219
275
 
220
- return _defaults({
221
- getTransitions: getTransitions,
222
- parentState: parentState
223
- }, props.animate, child.props.animate);
224
- },
225
- getDomainFromChildren: function (props, axis, childComponents) {
226
- // eslint-disable-line max-statements, complexity, max-len
227
- var children = childComponents ? childComponents.slice(0) : React.Children.toArray(props.children);
228
- var parentData = props.data ? Data.getData(props, axis) : undefined;
229
- var polar = props.polar,
230
- startAngle = props.startAngle,
231
- endAngle = props.endAngle,
232
- categories = props.categories,
233
- minDomain = props.minDomain,
234
- maxDomain = props.maxDomain,
235
- horizontal = props.horizontal;
236
- var baseParentProps = {
237
- horizontal: horizontal,
238
- polar: polar,
239
- startAngle: startAngle,
240
- endAngle: endAngle,
241
- minDomain: minDomain,
242
- maxDomain: maxDomain,
243
- categories: categories
244
- };
245
- var parentProps = parentData ? _assign(baseParentProps, {
246
- data: parentData
247
- }) : baseParentProps;
248
-
249
- var iteratee = function (child) {
250
- var sharedProps = _assign({}, child.props, parentProps);
251
-
252
- if (!Domain.isDomainComponent(child)) {
253
- return null;
254
- } else if (child.type && _isFunction(child.type.getDomain)) {
255
- return child.props && child.type.getDomain(sharedProps, axis);
256
- } else {
257
- return Domain.getDomain(sharedProps, axis);
258
- }
259
- };
276
+ var children = childComponents ? childComponents.slice(0) : React.Children.toArray(props.children);
260
277
 
261
- var childDomains = Helpers.reduceChildren(children, iteratee, props);
262
- var min = childDomains.length === 0 ? 0 : Collection.getMinValue(childDomains);
263
- var max = childDomains.length === 0 ? 1 : Collection.getMaxValue(childDomains);
264
- return [min, max];
265
- },
266
- addBinsToParentPropsIfHistogram: function (_ref) {
267
- var children = _ref.children,
268
- props = _ref.props,
269
- childComponents = _ref.childComponents,
270
- parentProps = _ref.parentProps;
271
- var someChildrenAreHistograms = children.some(function (child) {
272
- return child.type && child.type.role === "histogram";
273
- });
274
- var allChildrenAreHistograms = someChildrenAreHistograms && children.length && children.every(function (child) {
275
- return child.type && child.type.role === "histogram";
278
+ var iteratee = function (child) {
279
+ var sharedProps = _assign({}, child.props, {
280
+ horizontal: props.horizontal
276
281
  });
277
282
 
278
- if (someChildrenAreHistograms && !allChildrenAreHistograms) {
279
- Log.warn("VictoryHistogram only supports being stacked with other VictoryHistogram components. Check to make sure that you are only passing VictoryHistogram components to VictoryStack");
280
- } // if we are stacking histograms, we need to generate explicit bins
281
- // or else each histogram may end up having different bins
283
+ return Scale.getScaleType(sharedProps, axis);
284
+ };
282
285
 
286
+ var childScale = _uniq(Helpers.reduceChildren(children, iteratee, props)); // default to linear scale if more than one uniq scale type is given by children
283
287
 
284
- if (!allChildrenAreHistograms) {
285
- return parentProps;
286
- }
287
288
 
288
- var childBins = props.bins || childComponents[0].props.bins; // if we have explicit bins then we don't need to calculate them
289
-
290
- if (!Array.isArray(childBins)) {
291
- var combinedData = children.reduce(function (memo, child) {
292
- var xAccessor = Helpers.createAccessor(child.props.x || "x");
293
- return memo.concat(child.props.data.map(function (datum) {
294
- return {
295
- x: xAccessor(datum)
296
- };
297
- }));
298
- }, []); // use the same function to generate bins as VictoryHistogram but with
299
- // the combined data from above, then get explicit bins from that
300
-
301
- var getFormattedHistogramData = children[0].type.getFormattedData;
302
- childBins = getFormattedHistogramData({
303
- data: combinedData,
304
- bins: childBins
305
- }).reduce(function (memo, _ref2, index) {
306
- var x0 = _ref2.x0,
307
- x1 = _ref2.x1;
308
- return index === 0 ? memo.concat([x0, x1]) : memo.concat(x1);
309
- }, []);
310
- }
289
+ return childScale.length > 1 ? Scale.getScaleFromName("linear") : Scale.getScaleFromName(childScale[0]);
290
+ }
291
+ export function getAllEvents(props) {
292
+ var components = ["groupComponent", "containerComponent", "labelComponent"];
293
+ var componentEvents = Events.getComponentEvents(props, components);
294
+ var events = props.events;
311
295
 
312
- return _objectSpread({}, parentProps, {
313
- bins: childBins
314
- });
315
- },
316
- getDataFromChildren: function (props, childComponents) {
317
- var polar = props.polar,
318
- startAngle = props.startAngle,
319
- endAngle = props.endAngle,
320
- categories = props.categories,
321
- minDomain = props.minDomain,
322
- maxDomain = props.maxDomain;
323
- var parentProps = {
324
- polar: polar,
325
- startAngle: startAngle,
326
- endAngle: endAngle,
327
- categories: categories,
328
- minDomain: minDomain,
329
- maxDomain: maxDomain
330
- };
331
- var stack = 0;
332
- var children = childComponents ? childComponents.slice(0) : React.Children.toArray(props.children);
333
- parentProps = this.addBinsToParentPropsIfHistogram({
334
- children: children,
335
- props: props,
336
- childComponents: childComponents,
337
- parentProps: parentProps
338
- });
296
+ if (Array.isArray(componentEvents)) {
297
+ events = Array.isArray(props.events) ? componentEvents.concat.apply(componentEvents, _toConsumableArray(props.events)) : componentEvents;
298
+ }
339
299
 
340
- var iteratee = function (child, childName, parent) {
341
- var childProps = _assign({}, child.props, parentProps);
342
-
343
- var childData;
344
-
345
- if (!Data.isDataComponent(child)) {
346
- return null;
347
- } else if (child.type && _isFunction(child.type.getData)) {
348
- child = parent ? React.cloneElement(child, parent.props) : child;
349
- childData = child.type.getData(childProps);
350
- } else {
351
- childData = Data.getData(childProps);
352
- }
353
-
354
- stack += 1;
355
- return childData.map(function (datum, index) {
356
- return _assign({
357
- _stack: stack,
358
- _group: index
359
- }, datum);
360
- });
361
- };
300
+ return events || [];
301
+ }
302
+ export function getColor(calculatedProps, child, index) {
303
+ // check for styles first
304
+ var style = calculatedProps.style;
305
+ var colorScale = calculatedProps.colorScale,
306
+ color = calculatedProps.color;
362
307
 
363
- var stacked = children.filter(function (c) {
364
- return c.type && c.type.role === "stack";
365
- }).length;
308
+ if (style && style.data && style.data.fill) {
309
+ return style.data.fill;
310
+ }
366
311
 
367
- var combine = function (memo, val) {
368
- return memo.concat(_uniqBy(val, "_group"));
369
- };
312
+ colorScale = child.props && child.props.colorScale ? child.props.colorScale : colorScale;
313
+ color = child.props && child.props.color ? child.props.color : color;
370
314
 
371
- var datasets = Helpers.reduceChildren(children, iteratee, props, [], combine);
372
- var group = stacked ? "_group" : "_stack";
373
- return _values(_groupBy(datasets, group));
374
- },
375
- getColor: function (calculatedProps, child, index) {
376
- // check for styles first
377
- var style = calculatedProps.style;
378
- var colorScale = calculatedProps.colorScale,
379
- color = calculatedProps.color;
380
-
381
- if (style && style.data && style.data.fill) {
382
- return style.data.fill;
383
- }
315
+ if (!colorScale && !color) {
316
+ return undefined;
317
+ }
384
318
 
385
- colorScale = child.props && child.props.colorScale ? child.props.colorScale : colorScale;
386
- color = child.props && child.props.color ? child.props.color : color;
319
+ var colors = Array.isArray(colorScale) ? colorScale : Style.getColorScale(colorScale);
320
+ return color || colors[index % colors.length];
321
+ }
322
+ export function getStyle(theme, style, role) {
323
+ var defaultStyle = theme && theme[role] && theme[role].style ? theme[role].style : {};
324
+ return Helpers.getStyles(style, defaultStyle);
325
+ }
326
+ export function getChildStyle(child, index, calculatedProps) {
327
+ var style = calculatedProps.style,
328
+ role = calculatedProps.role;
329
+ var childStyle = child.props.style || {};
330
+
331
+ if (Array.isArray(childStyle)) {
332
+ return childStyle;
333
+ }
387
334
 
388
- if (!colorScale && !color) {
389
- return undefined;
335
+ var childRole = child.type && child.type.role;
336
+ var defaultFill = childRole === "stack" ? undefined : getColor(calculatedProps, child, index);
337
+ var defaultColor = childRole === "line" ? {
338
+ fill: "none",
339
+ stroke: defaultFill
340
+ } : {
341
+ fill: defaultFill
342
+ };
343
+ var dataWidth = role === "stack" ? {} : {
344
+ width: getWidth(calculatedProps)
345
+ };
346
+
347
+ var dataStyle = _defaults({}, childStyle.data, _assign({}, dataWidth, style.data, defaultColor));
348
+
349
+ var labelsStyle = _defaults({}, childStyle.labels, style.labels);
350
+
351
+ return {
352
+ parent: style.parent,
353
+ data: dataStyle,
354
+ labels: labelsStyle
355
+ };
356
+ }
357
+ export function getStringsFromCategories(childComponents, axis) {
358
+ var iteratee = function (child) {
359
+ var childProps = child.props || {};
360
+
361
+ if (!Domain.isDomainComponent(child) || !childProps.categories) {
362
+ return null;
363
+ } else {
364
+ var categories = childProps.categories && !Array.isArray(childProps.categories) ? childProps.categories[axis] : childProps.props.categories;
365
+ var categoryStrings = categories && categories.filter(function (val) {
366
+ return typeof val === "string";
367
+ });
368
+ return categoryStrings ? Collection.removeUndefined(categoryStrings) : [];
390
369
  }
391
-
392
- var colors = Array.isArray(colorScale) ? colorScale : Style.getColorScale(colorScale);
393
- return color || colors[index % colors.length];
394
- },
395
- getWidth: function (props, groupLength, seriesLength) {
396
- var datasets = props.datasets,
397
- horizontal = props.horizontal;
398
- var range = horizontal ? Helpers.getRange(props, "y") : Helpers.getRange(props, "x");
399
- var extent = Math.abs(range[1] - range[0]);
400
- seriesLength = seriesLength !== undefined ? seriesLength : Array.isArray(datasets[0]) && datasets[0].length || 1;
401
- groupLength = groupLength || datasets.length;
402
- var bars = groupLength * seriesLength;
403
- var barRatio = 0.5;
404
- return Math.round(barRatio * extent / bars);
405
- },
406
- getStyle: function (theme, style, role) {
407
- var defaultStyle = theme && theme[role] && theme[role].style ? theme[role].style : {};
408
- return Helpers.getStyles(style, defaultStyle);
409
- },
410
- getChildStyle: function (child, index, calculatedProps) {
411
- var style = calculatedProps.style,
412
- role = calculatedProps.role;
413
- var childStyle = child.props.style || {};
414
-
415
- if (Array.isArray(childStyle)) {
416
- return childStyle;
370
+ };
371
+
372
+ return Helpers.reduceChildren(childComponents.slice(0), iteratee);
373
+ }
374
+ export function getStringsFromData(childComponents) {
375
+ var iteratee = function (child) {
376
+ var childProps = child.props || {};
377
+ var data;
378
+
379
+ if (!Data.isDataComponent(child)) {
380
+ return null;
381
+ } else if (child.type && _isFunction(child.type.getData)) {
382
+ data = child.type.getData(childProps);
383
+ } else {
384
+ data = Data.getData(childProps);
417
385
  }
418
386
 
419
- var childRole = child.type && child.type.role;
420
- var defaultFill = childRole === "stack" ? undefined : this.getColor(calculatedProps, child, index);
421
- var defaultColor = childRole === "line" ? {
422
- fill: "none",
423
- stroke: defaultFill
424
- } : {
425
- fill: defaultFill
426
- };
427
- var dataWidth = role === "stack" ? {} : {
428
- width: this.getWidth(calculatedProps)
429
- };
430
-
431
- var dataStyle = _defaults({}, childStyle.data, _assign({}, dataWidth, style.data, defaultColor));
432
-
433
- var labelsStyle = _defaults({}, childStyle.labels, style.labels);
434
-
435
- return {
436
- parent: style.parent,
437
- data: dataStyle,
438
- labels: labelsStyle
439
- };
440
- },
441
- getStringsFromCategories: function (childComponents, axis) {
442
- var iteratee = function (child) {
443
- var childProps = child.props || {};
444
-
445
- if (!Domain.isDomainComponent(child) || !childProps.categories) {
446
- return null;
447
- } else {
448
- var categories = childProps.categories && !Array.isArray(childProps.categories) ? childProps.categories[axis] : childProps.props.categories;
449
- var categoryStrings = categories && categories.filter(function (val) {
450
- return typeof val === "string";
451
- });
452
- return categoryStrings ? Collection.removeUndefined(categoryStrings) : [];
453
- }
454
- };
455
-
456
- return Helpers.reduceChildren(childComponents.slice(0), iteratee);
457
- },
458
- getStringsFromData: function (childComponents) {
459
- var iteratee = function (child) {
460
- var childProps = child.props || {};
461
- var data;
462
-
463
- if (!Data.isDataComponent(child)) {
464
- return null;
465
- } else if (child.type && _isFunction(child.type.getData)) {
466
- data = child.type.getData(childProps);
467
- } else {
468
- data = Data.getData(childProps);
469
- }
470
-
471
- return data.map(function (d) {
472
- return {
473
- x: d.xName,
474
- y: d.yName
475
- };
476
- });
477
- };
478
-
479
- var initialMemo = {
480
- x: [],
481
- y: []
482
- };
483
-
484
- var combine = function (memo, datum) {
485
- var x = Array.isArray(datum) ? datum.map(function (d) {
486
- return d.x;
487
- }).filter(Boolean) : datum.x;
488
- var y = Array.isArray(datum) ? datum.map(function (d) {
489
- return d.y;
490
- }).filter(Boolean) : datum.y;
387
+ return data.map(function (d) {
491
388
  return {
492
- x: x !== undefined ? memo.x.concat(x) : memo.x,
493
- y: y !== undefined ? memo.y.concat(y) : memo.y
389
+ x: d.xName,
390
+ y: d.yName
494
391
  };
495
- };
496
-
497
- return Helpers.reduceChildren(childComponents.slice(0), iteratee, {}, initialMemo, combine);
498
- },
499
- getCategoryAndAxisStringsFromChildren: function (props, axis, childComponents) {
500
- var categories = _isPlainObject(props.categories) ? props.categories[axis] : props.categories;
501
- var axisComponent = Axis.getAxisComponent(childComponents, axis);
502
- var axisStrings = axisComponent ? Data.getStringsFromAxes(axisComponent.props, axis) : [];
503
- var categoryStrings = categories || this.getStringsFromCategories(childComponents, axis);
504
- return _uniq(_flatten(_toConsumableArray(categoryStrings).concat(_toConsumableArray(axisStrings))));
505
- },
506
- getStringsFromChildren: function (props, childComponents) {
507
- childComponents = childComponents || React.Children.toArray(props.children);
508
- var xStrings = this.getCategoryAndAxisStringsFromChildren(props, "x", childComponents);
509
- var yStrings = this.getCategoryAndAxisStringsFromChildren(props, "y", childComponents);
510
- var dataStrings = this.getStringsFromData(childComponents);
511
- return {
512
- x: _uniq(_flatten(_toConsumableArray(xStrings).concat(_toConsumableArray(dataStrings.x)))),
513
- y: _uniq(_flatten(_toConsumableArray(yStrings).concat(_toConsumableArray(dataStrings.y))))
514
- };
515
- },
516
- getCategories: function (props, childComponents, allStrings) {
517
- var xPropCategories = props.categories && !Array.isArray(props.categories) ? props.categories.x : props.categories;
518
- var yPropCategories = props.categories && !Array.isArray(props.categories) ? props.categories.y : props.categories;
519
- var fallbackRequired = !xPropCategories || !yPropCategories;
520
- var fallbackProps = fallbackRequired ? allStrings || this.getStringsFromChildren(props, childComponents) : {};
521
- var xCategories = xPropCategories || fallbackProps.x;
522
- var yCategories = yPropCategories || fallbackProps.y;
392
+ });
393
+ };
394
+
395
+ var initialMemo = {
396
+ x: [],
397
+ y: []
398
+ };
399
+
400
+ var combine = function (memo, datum) {
401
+ var x = Array.isArray(datum) ? datum.map(function (d) {
402
+ return d.x;
403
+ }).filter(Boolean) : datum.x;
404
+ var y = Array.isArray(datum) ? datum.map(function (d) {
405
+ return d.y;
406
+ }).filter(Boolean) : datum.y;
523
407
  return {
524
- x: xCategories.length > 0 ? xCategories : undefined,
525
- y: yCategories.length > 0 ? yCategories : undefined
408
+ x: x !== undefined ? memo.x.concat(x) : memo.x,
409
+ y: y !== undefined ? memo.y.concat(y) : memo.y
526
410
  };
527
- }
528
- };
411
+ };
412
+
413
+ return Helpers.reduceChildren(childComponents.slice(0), iteratee, {}, initialMemo, combine);
414
+ }
415
+ export function getCategoryAndAxisStringsFromChildren(props, axis, childComponents) {
416
+ var categories = _isPlainObject(props.categories) ? props.categories[axis] : props.categories;
417
+ var axisComponent = Axis.getAxisComponent(childComponents, axis);
418
+ var axisStrings = axisComponent ? Data.getStringsFromAxes(axisComponent.props, axis) : [];
419
+ var categoryStrings = categories || getStringsFromCategories(childComponents, axis);
420
+ return _uniq(_flatten(_toConsumableArray(categoryStrings).concat(_toConsumableArray(axisStrings))));
421
+ }
422
+ export function getStringsFromChildren(props, childComponents) {
423
+ childComponents = childComponents || React.Children.toArray(props.children);
424
+ var xStrings = getCategoryAndAxisStringsFromChildren(props, "x", childComponents);
425
+ var yStrings = getCategoryAndAxisStringsFromChildren(props, "y", childComponents);
426
+ var dataStrings = getStringsFromData(childComponents);
427
+ return {
428
+ x: _uniq(_flatten(_toConsumableArray(xStrings).concat(_toConsumableArray(dataStrings.x)))),
429
+ y: _uniq(_flatten(_toConsumableArray(yStrings).concat(_toConsumableArray(dataStrings.y))))
430
+ };
431
+ }
432
+ export function getCategories(props, childComponents, allStrings) {
433
+ var xPropCategories = props.categories && !Array.isArray(props.categories) ? props.categories.x : props.categories;
434
+ var yPropCategories = props.categories && !Array.isArray(props.categories) ? props.categories.y : props.categories;
435
+ var fallbackRequired = !xPropCategories || !yPropCategories;
436
+ var fallbackProps = fallbackRequired ? allStrings || getStringsFromChildren(props, childComponents) : {};
437
+ var xCategories = xPropCategories || fallbackProps.x;
438
+ var yCategories = yPropCategories || fallbackProps.y;
439
+ return {
440
+ x: xCategories.length > 0 ? xCategories : undefined,
441
+ y: yCategories.length > 0 ? yCategories : undefined
442
+ };
443
+ }