victory-core 36.9.2 → 37.0.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/CHANGELOG.md +6 -0
- package/dist/victory-core.js +4371 -5749
- package/dist/victory-core.min.js +1 -1
- package/es/victory-accessible-group/victory-accessible-group.js +9 -15
- package/es/victory-animation/util.js +28 -47
- package/es/victory-animation/victory-animation.js +51 -67
- package/es/victory-clip-container/victory-clip-container.js +153 -229
- package/es/victory-container/victory-container.js +157 -216
- package/es/victory-label/victory-label.js +246 -323
- package/es/victory-portal/portal-context.js +1 -2
- package/es/victory-portal/portal.js +30 -76
- package/es/victory-portal/victory-portal.js +47 -104
- package/es/victory-primitives/arc.js +44 -47
- package/es/victory-primitives/background.js +14 -17
- package/es/victory-primitives/border.js +20 -24
- package/es/victory-primitives/circle.js +13 -27
- package/es/victory-primitives/clip-path.js +3 -7
- package/es/victory-primitives/line-segment.js +20 -24
- package/es/victory-primitives/line.js +13 -27
- package/es/victory-primitives/path.js +13 -27
- package/es/victory-primitives/point.js +36 -40
- package/es/victory-primitives/rect.js +13 -27
- package/es/victory-primitives/text.js +15 -28
- package/es/victory-primitives/tspan.js +13 -26
- package/es/victory-primitives/whisker.js +43 -47
- package/es/victory-theme/grayscale.js +22 -22
- package/es/victory-theme/material.js +46 -46
- package/es/victory-theme/victory-theme.js +3 -3
- package/es/victory-transition/victory-transition.js +126 -206
- package/es/victory-util/add-events.js +263 -374
- package/es/victory-util/axis.js +126 -222
- package/es/victory-util/collection.js +13 -41
- package/es/victory-util/data.js +159 -214
- package/es/victory-util/default-transitions.js +33 -51
- package/es/victory-util/domain.js +122 -171
- package/es/victory-util/events.js +168 -258
- package/es/victory-util/helpers.js +153 -178
- package/es/victory-util/hooks/use-animation-state.js +61 -99
- package/es/victory-util/hooks/use-previous-props.js +2 -2
- package/es/victory-util/immutable.js +6 -8
- package/es/victory-util/label-helpers.js +128 -130
- package/es/victory-util/line-helpers.js +29 -41
- package/es/victory-util/log.js +1 -1
- package/es/victory-util/point-path-helpers.js +89 -49
- package/es/victory-util/scale.js +24 -42
- package/es/victory-util/selection.js +39 -40
- package/es/victory-util/style.js +8 -13
- package/es/victory-util/textsize.js +80 -154
- package/es/victory-util/timer-context.js +2 -2
- package/es/victory-util/timer.js +40 -76
- package/es/victory-util/transitions.js +110 -150
- package/es/victory-util/type-helpers.js +2 -3
- package/es/victory-util/user-props.js +24 -49
- package/es/victory-util/wrapper.js +184 -247
- package/lib/index.js +0 -30
- package/lib/victory-accessible-group/victory-accessible-group.js +9 -19
- package/lib/victory-animation/util.js +28 -63
- package/lib/victory-animation/victory-animation.js +54 -83
- package/lib/victory-clip-container/victory-clip-container.js +156 -243
- package/lib/victory-container/victory-container.js +160 -232
- package/lib/victory-label/victory-label.js +248 -344
- package/lib/victory-portal/portal-context.js +1 -6
- package/lib/victory-portal/portal.js +31 -81
- package/lib/victory-portal/victory-portal.js +50 -116
- package/lib/victory-primitives/arc.js +48 -57
- package/lib/victory-primitives/background.js +16 -28
- package/lib/victory-primitives/border.js +22 -34
- package/lib/victory-primitives/circle.js +16 -36
- package/lib/victory-primitives/clip-path.js +3 -11
- package/lib/victory-primitives/index.js +0 -28
- package/lib/victory-primitives/line-segment.js +22 -34
- package/lib/victory-primitives/line.js +16 -36
- package/lib/victory-primitives/path.js +16 -36
- package/lib/victory-primitives/point.js +38 -52
- package/lib/victory-primitives/rect.js +16 -36
- package/lib/victory-primitives/text.js +15 -33
- package/lib/victory-primitives/tspan.js +13 -31
- package/lib/victory-primitives/whisker.js +45 -57
- package/lib/victory-theme/grayscale.js +23 -24
- package/lib/victory-theme/material.js +47 -48
- package/lib/victory-theme/victory-theme.js +2 -7
- package/lib/victory-transition/victory-transition.js +129 -224
- package/lib/victory-util/add-events.js +263 -380
- package/lib/victory-util/axis.js +128 -241
- package/lib/victory-util/collection.js +13 -50
- package/lib/victory-util/data.js +160 -239
- package/lib/victory-util/default-transitions.js +33 -54
- package/lib/victory-util/domain.js +123 -193
- package/lib/victory-util/events.js +167 -274
- package/lib/victory-util/helpers.js +156 -207
- package/lib/victory-util/hooks/index.js +0 -2
- package/lib/victory-util/hooks/use-animation-state.js +63 -113
- package/lib/victory-util/hooks/use-previous-props.js +2 -7
- package/lib/victory-util/immutable.js +6 -18
- package/lib/victory-util/index.js +2 -51
- package/lib/victory-util/label-helpers.js +130 -141
- package/lib/victory-util/line-helpers.js +31 -49
- package/lib/victory-util/log.js +1 -2
- package/lib/victory-util/point-path-helpers.js +91 -63
- package/lib/victory-util/scale.js +26 -57
- package/lib/victory-util/selection.js +41 -49
- package/lib/victory-util/style.js +8 -16
- package/lib/victory-util/textsize.js +80 -157
- package/lib/victory-util/timer-context.js +2 -8
- package/lib/victory-util/timer.js +40 -76
- package/lib/victory-util/transitions.js +110 -152
- package/lib/victory-util/type-helpers.js +2 -9
- package/lib/victory-util/user-props.js +25 -59
- package/lib/victory-util/wrapper.js +186 -281
- package/package.json +2 -2
|
@@ -3,25 +3,6 @@ import _uniqBy from "lodash/uniqBy";
|
|
|
3
3
|
import _groupBy from "lodash/groupBy";
|
|
4
4
|
import _uniq from "lodash/uniq";
|
|
5
5
|
import _defaults from "lodash/defaults";
|
|
6
|
-
|
|
7
|
-
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
|
8
|
-
|
|
9
|
-
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
10
|
-
|
|
11
|
-
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
12
|
-
|
|
13
|
-
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
|
|
14
|
-
|
|
15
|
-
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
|
|
16
|
-
|
|
17
|
-
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
|
|
18
|
-
|
|
19
|
-
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
20
|
-
|
|
21
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
22
|
-
|
|
23
|
-
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; }
|
|
24
|
-
|
|
25
6
|
import React from "react";
|
|
26
7
|
import * as Axis from "./axis";
|
|
27
8
|
import * as Style from "./style";
|
|
@@ -33,84 +14,86 @@ import * as Helpers from "./helpers";
|
|
|
33
14
|
import * as Scale from "./scale";
|
|
34
15
|
import * as Log from "./log";
|
|
35
16
|
export function addBinsToParentPropsIfHistogram(_ref) {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
17
|
+
let {
|
|
18
|
+
children,
|
|
19
|
+
props,
|
|
20
|
+
childComponents,
|
|
21
|
+
parentProps
|
|
22
|
+
} = _ref;
|
|
23
|
+
const someChildrenAreHistograms = children.some(child => {
|
|
41
24
|
return child.type && child.type.role === "histogram";
|
|
42
25
|
});
|
|
43
|
-
|
|
26
|
+
const allChildrenAreHistograms = someChildrenAreHistograms && children.length && children.every(child => {
|
|
44
27
|
return child.type && child.type.role === "histogram";
|
|
45
28
|
});
|
|
46
|
-
|
|
47
29
|
if (someChildrenAreHistograms && !allChildrenAreHistograms) {
|
|
48
30
|
Log.warn("VictoryHistogram only supports being stacked with other VictoryHistogram components. Check to make sure that you are only passing VictoryHistogram components to VictoryStack");
|
|
49
|
-
}
|
|
50
|
-
// or else each histogram may end up having different bins
|
|
51
|
-
|
|
31
|
+
}
|
|
52
32
|
|
|
33
|
+
// if we are stacking histograms, we need to generate explicit bins
|
|
34
|
+
// or else each histogram may end up having different bins
|
|
53
35
|
if (!allChildrenAreHistograms) {
|
|
54
36
|
return parentProps;
|
|
55
37
|
}
|
|
38
|
+
let childBins = props.bins || childComponents[0].props.bins;
|
|
56
39
|
|
|
57
|
-
|
|
58
|
-
|
|
40
|
+
// if we have explicit bins then we don't need to calculate them
|
|
59
41
|
if (!Array.isArray(childBins)) {
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
return memo.concat(child.props.data.map(
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
}));
|
|
67
|
-
}, []); // use the same function to generate bins as VictoryHistogram but with
|
|
68
|
-
// the combined data from above, then get explicit bins from that
|
|
42
|
+
const combinedData = children.reduce((memo, child) => {
|
|
43
|
+
const xAccessor = Helpers.createAccessor(child.props.x || "x");
|
|
44
|
+
return memo.concat(child.props.data.map(datum => ({
|
|
45
|
+
x: xAccessor(datum)
|
|
46
|
+
})));
|
|
47
|
+
}, []);
|
|
69
48
|
|
|
70
|
-
|
|
49
|
+
// use the same function to generate bins as VictoryHistogram but with
|
|
50
|
+
// the combined data from above, then get explicit bins from that
|
|
51
|
+
const getFormattedHistogramData = children[0].type.getFormattedData;
|
|
71
52
|
childBins = getFormattedHistogramData({
|
|
72
53
|
data: combinedData,
|
|
73
54
|
bins: childBins
|
|
74
|
-
}).reduce(
|
|
75
|
-
|
|
76
|
-
|
|
55
|
+
}).reduce((memo, _ref2, index) => {
|
|
56
|
+
let {
|
|
57
|
+
x0,
|
|
58
|
+
x1
|
|
59
|
+
} = _ref2;
|
|
77
60
|
return index === 0 ? memo.concat([x0, x1]) : memo.concat(x1);
|
|
78
61
|
}, []);
|
|
79
62
|
}
|
|
80
|
-
|
|
81
|
-
|
|
63
|
+
return {
|
|
64
|
+
...parentProps,
|
|
82
65
|
bins: childBins
|
|
83
|
-
}
|
|
66
|
+
};
|
|
84
67
|
}
|
|
85
68
|
export function getDataFromChildren(props, childComponents) {
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
69
|
+
const {
|
|
70
|
+
polar,
|
|
71
|
+
startAngle,
|
|
72
|
+
endAngle,
|
|
73
|
+
categories,
|
|
74
|
+
minDomain,
|
|
75
|
+
maxDomain
|
|
76
|
+
} = props;
|
|
77
|
+
let parentProps = {
|
|
78
|
+
polar,
|
|
79
|
+
startAngle,
|
|
80
|
+
endAngle,
|
|
81
|
+
categories,
|
|
82
|
+
minDomain,
|
|
83
|
+
maxDomain
|
|
99
84
|
};
|
|
100
|
-
|
|
101
|
-
|
|
85
|
+
let stack = 0;
|
|
86
|
+
const children = childComponents ? childComponents.slice(0) : React.Children.toArray(props.children);
|
|
102
87
|
parentProps = addBinsToParentPropsIfHistogram({
|
|
103
|
-
children
|
|
104
|
-
props
|
|
105
|
-
childComponents
|
|
106
|
-
parentProps
|
|
88
|
+
children,
|
|
89
|
+
props,
|
|
90
|
+
childComponents,
|
|
91
|
+
parentProps
|
|
107
92
|
});
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
var childElement = child;
|
|
113
|
-
|
|
93
|
+
const iteratee = (child, childName, parent) => {
|
|
94
|
+
const childProps = Object.assign({}, child.props, parentProps);
|
|
95
|
+
let childData;
|
|
96
|
+
let childElement = child;
|
|
114
97
|
if (!Data.isDataComponent(child)) {
|
|
115
98
|
return null;
|
|
116
99
|
} else if (child.type && Helpers.isFunction(child.type.getData)) {
|
|
@@ -119,263 +102,227 @@ export function getDataFromChildren(props, childComponents) {
|
|
|
119
102
|
} else {
|
|
120
103
|
childData = Data.getData(childProps);
|
|
121
104
|
}
|
|
122
|
-
|
|
123
105
|
stack += 1;
|
|
124
|
-
return childData.map(
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
}, datum);
|
|
129
|
-
});
|
|
130
|
-
};
|
|
131
|
-
|
|
132
|
-
var stacked = children.filter(function (c) {
|
|
133
|
-
return c.type && c.type.role === "stack";
|
|
134
|
-
}).length;
|
|
135
|
-
|
|
136
|
-
var combine = function (memo, val) {
|
|
137
|
-
return memo.concat(_uniqBy(val, "_group"));
|
|
106
|
+
return childData.map((datum, index) => Object.assign({
|
|
107
|
+
_stack: stack,
|
|
108
|
+
_group: index
|
|
109
|
+
}, datum));
|
|
138
110
|
};
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
111
|
+
const stacked = children.filter(c => c.type && c.type.role === "stack").length;
|
|
112
|
+
const combine = (memo, val) => memo.concat(_uniqBy(val, "_group"));
|
|
113
|
+
const datasets = Helpers.reduceChildren(children, iteratee, props, [], combine);
|
|
114
|
+
const group = stacked ? "_group" : "_stack";
|
|
142
115
|
return Object.values(_groupBy(datasets, group));
|
|
143
116
|
}
|
|
144
117
|
export function getData(props, childComponents) {
|
|
145
118
|
if (props.data) {
|
|
146
119
|
return Data.getData(props);
|
|
147
120
|
}
|
|
148
|
-
|
|
149
121
|
return getDataFromChildren(props, childComponents || React.Children.toArray(props.children));
|
|
150
122
|
}
|
|
151
123
|
export function getWidth(props, groupLength, seriesLength) {
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
124
|
+
const {
|
|
125
|
+
datasets,
|
|
126
|
+
horizontal
|
|
127
|
+
} = props;
|
|
128
|
+
const range = horizontal ? Helpers.getRange(props, "y") : Helpers.getRange(props, "x");
|
|
129
|
+
const extent = Math.abs(range[1] - range[0]);
|
|
130
|
+
const seriesLengthValue = seriesLength !== undefined ? seriesLength : Array.isArray(datasets[0]) && datasets[0].length || 1;
|
|
131
|
+
const groupLengthValue = groupLength || datasets.length;
|
|
132
|
+
const bars = groupLengthValue * seriesLengthValue;
|
|
133
|
+
const barRatio = 0.5;
|
|
160
134
|
return Math.round(barRatio * extent / bars);
|
|
161
135
|
}
|
|
162
136
|
export function getDefaultDomainPadding(props, axis, childComponents) {
|
|
163
137
|
if (props.polar || axis !== "x") {
|
|
164
138
|
return undefined;
|
|
165
139
|
}
|
|
166
|
-
|
|
167
|
-
var groupComponent = childComponents.filter(function (child) {
|
|
140
|
+
const groupComponent = childComponents.filter(child => {
|
|
168
141
|
return child.type && child.type.role && child.type.role === "group";
|
|
169
142
|
});
|
|
170
|
-
|
|
171
143
|
if (groupComponent.length < 1) {
|
|
172
144
|
return undefined;
|
|
173
145
|
}
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
146
|
+
const {
|
|
147
|
+
offset,
|
|
148
|
+
children
|
|
149
|
+
} = groupComponent[0].props;
|
|
179
150
|
if (!offset) {
|
|
180
151
|
return undefined;
|
|
181
152
|
}
|
|
182
|
-
|
|
183
|
-
var firstChild = Array.isArray(children) && children[0];
|
|
184
|
-
|
|
153
|
+
const firstChild = Array.isArray(children) && children[0];
|
|
185
154
|
if (!firstChild) {
|
|
186
155
|
return undefined;
|
|
187
156
|
}
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
var dataLength = firstChild.props.data && firstChild.props.data.length || 1;
|
|
191
|
-
|
|
157
|
+
let barWidth = firstChild.props.barWidth;
|
|
158
|
+
let dataLength = firstChild.props.data && firstChild.props.data.length || 1;
|
|
192
159
|
if (firstChild && firstChild.type.role === "stack") {
|
|
193
|
-
|
|
194
|
-
|
|
160
|
+
const nestedChild = firstChild.props.children && firstChild.props.children[0];
|
|
195
161
|
if (!nestedChild) {
|
|
196
162
|
return undefined;
|
|
197
163
|
}
|
|
198
|
-
|
|
199
164
|
barWidth = nestedChild.props.barWidth;
|
|
200
165
|
dataLength = firstChild.props.children.length;
|
|
201
166
|
}
|
|
202
|
-
|
|
203
|
-
var width = barWidth || getWidth(props, children.length, dataLength);
|
|
167
|
+
const width = barWidth || getWidth(props, children.length, dataLength);
|
|
204
168
|
return {
|
|
205
169
|
x: width * children.length / 2 + (offset - width * ((children.length - 1) / 2))
|
|
206
170
|
};
|
|
207
171
|
}
|
|
208
172
|
export function getDomainFromChildren(props, axis, childComponents) {
|
|
209
173
|
// eslint-disable-line max-statements, complexity, max-len
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
174
|
+
const children = childComponents ? childComponents.slice(0) : React.Children.toArray(props.children);
|
|
175
|
+
const parentData = props.data ? Data.getData(props) : undefined;
|
|
176
|
+
const {
|
|
177
|
+
polar,
|
|
178
|
+
startAngle,
|
|
179
|
+
endAngle,
|
|
180
|
+
categories,
|
|
181
|
+
minDomain,
|
|
182
|
+
maxDomain,
|
|
183
|
+
horizontal
|
|
184
|
+
} = props;
|
|
185
|
+
const baseParentProps = {
|
|
186
|
+
horizontal,
|
|
187
|
+
polar,
|
|
188
|
+
startAngle,
|
|
189
|
+
endAngle,
|
|
190
|
+
minDomain,
|
|
191
|
+
maxDomain,
|
|
192
|
+
categories
|
|
227
193
|
};
|
|
228
|
-
|
|
194
|
+
const parentProps = parentData ? Object.assign(baseParentProps, {
|
|
229
195
|
data: parentData
|
|
230
196
|
}) : baseParentProps;
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
var sharedProps = Object.assign({}, child.props, parentProps);
|
|
234
|
-
|
|
197
|
+
const iteratee = child => {
|
|
198
|
+
const sharedProps = Object.assign({}, child.props, parentProps);
|
|
235
199
|
if (!Domain.isDomainComponent(child)) {
|
|
236
200
|
return null;
|
|
237
201
|
} else if (child.type && Helpers.isFunction(child.type.getDomain)) {
|
|
238
202
|
return child.props && child.type.getDomain(sharedProps, axis);
|
|
239
203
|
}
|
|
240
|
-
|
|
241
204
|
return Domain.getDomain(sharedProps, axis);
|
|
242
205
|
};
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
var max = childDomains.length === 0 ? 1 : Collection.getMaxValue(childDomains);
|
|
206
|
+
const childDomains = Helpers.reduceChildren(children, iteratee, props);
|
|
207
|
+
const min = childDomains.length === 0 ? 0 : Collection.getMinValue(childDomains);
|
|
208
|
+
const max = childDomains.length === 0 ? 1 : Collection.getMaxValue(childDomains);
|
|
247
209
|
return [min, max];
|
|
248
210
|
}
|
|
249
211
|
export function getDomain(props, axis, childComponents) {
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
212
|
+
const children = childComponents || React.Children.toArray(props.children);
|
|
213
|
+
const propsDomain = Domain.getDomainFromProps(props, axis);
|
|
214
|
+
const domainPadding = getDefaultDomainPadding(props, axis, children);
|
|
215
|
+
let domain;
|
|
255
216
|
if (propsDomain) {
|
|
256
217
|
domain = propsDomain;
|
|
257
218
|
} else {
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
219
|
+
const minDomain = Domain.getMinFromProps(props, axis);
|
|
220
|
+
const maxDomain = Domain.getMaxFromProps(props, axis);
|
|
221
|
+
const dataset = (props.data || props.y) && Data.getData(props);
|
|
222
|
+
const dataDomain = dataset ? Domain.getDomainFromData(props, axis, dataset) : [];
|
|
223
|
+
const childDomain = getDomainFromChildren(props, axis, children);
|
|
224
|
+
const min = minDomain || Collection.getMinValue([...dataDomain, ...childDomain]);
|
|
225
|
+
const max = maxDomain || Collection.getMaxValue([...dataDomain, ...childDomain]);
|
|
265
226
|
domain = Domain.getDomainFromMinMax(min, max);
|
|
266
227
|
}
|
|
267
|
-
|
|
268
228
|
return Domain.formatDomain(domain, Object.assign({
|
|
269
|
-
domainPadding
|
|
229
|
+
domainPadding
|
|
270
230
|
}, props), axis);
|
|
271
231
|
}
|
|
272
232
|
export function getScale(props, axis, childComponents) {
|
|
273
233
|
if (props.data) {
|
|
274
234
|
return Scale.getBaseScale(props, axis);
|
|
275
235
|
}
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
var iteratee = function (child) {
|
|
280
|
-
var sharedProps = Object.assign({}, child.props, {
|
|
236
|
+
const children = childComponents ? childComponents.slice(0) : React.Children.toArray(props.children);
|
|
237
|
+
const iteratee = child => {
|
|
238
|
+
const sharedProps = Object.assign({}, child.props, {
|
|
281
239
|
horizontal: props.horizontal
|
|
282
240
|
});
|
|
283
241
|
return Scale.getScaleType(sharedProps, axis);
|
|
284
242
|
};
|
|
243
|
+
const childScale = _uniq(Helpers.reduceChildren(children, iteratee, props));
|
|
285
244
|
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
245
|
+
// default to linear scale if more than one uniq scale type is given by children
|
|
289
246
|
return childScale.length > 1 ? Scale.getScaleFromName("linear") : Scale.getScaleFromName(childScale[0]);
|
|
290
247
|
}
|
|
291
248
|
export function getAllEvents(props) {
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
249
|
+
const components = ["groupComponent", "containerComponent", "labelComponent"];
|
|
250
|
+
const componentEvents = Events.getComponentEvents(props, components);
|
|
251
|
+
let events = props.events;
|
|
296
252
|
if (Array.isArray(componentEvents)) {
|
|
297
|
-
events = Array.isArray(props.events) ? componentEvents.concat
|
|
253
|
+
events = Array.isArray(props.events) ? componentEvents.concat(...props.events) : componentEvents;
|
|
298
254
|
}
|
|
299
|
-
|
|
300
255
|
return events || [];
|
|
301
256
|
}
|
|
302
257
|
export function getColor(calculatedProps, child, index) {
|
|
303
258
|
// check for styles first
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
259
|
+
const {
|
|
260
|
+
style
|
|
261
|
+
} = calculatedProps;
|
|
262
|
+
let {
|
|
263
|
+
colorScale,
|
|
264
|
+
color
|
|
265
|
+
} = calculatedProps;
|
|
308
266
|
if (style && style.data && style.data.fill) {
|
|
309
267
|
return style.data.fill;
|
|
310
268
|
}
|
|
311
|
-
|
|
312
269
|
colorScale = child.props && child.props.colorScale ? child.props.colorScale : colorScale;
|
|
313
270
|
color = child.props && child.props.color ? child.props.color : color;
|
|
314
|
-
|
|
315
271
|
if (!colorScale && !color) {
|
|
316
272
|
return undefined;
|
|
317
273
|
}
|
|
318
|
-
|
|
319
|
-
var colors = Array.isArray(colorScale) ? colorScale : Style.getColorScale(colorScale);
|
|
274
|
+
const colors = Array.isArray(colorScale) ? colorScale : Style.getColorScale(colorScale);
|
|
320
275
|
return color || colors[index % colors.length];
|
|
321
276
|
}
|
|
322
277
|
export function getStyle(theme, style, role) {
|
|
323
|
-
|
|
278
|
+
const defaultStyle = theme && theme[role] && theme[role].style ? theme[role].style : {};
|
|
324
279
|
return Helpers.getStyles(style, defaultStyle);
|
|
325
280
|
}
|
|
326
281
|
export function getChildStyle(child, index, calculatedProps) {
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
282
|
+
const {
|
|
283
|
+
style,
|
|
284
|
+
role
|
|
285
|
+
} = calculatedProps;
|
|
286
|
+
const childStyle = child.props.style || {};
|
|
331
287
|
if (Array.isArray(childStyle)) {
|
|
332
288
|
return childStyle;
|
|
333
289
|
}
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
var defaultColor = childRole === "line" ? {
|
|
290
|
+
const childRole = child.type && child.type.role;
|
|
291
|
+
const defaultFill = childRole === "stack" ? undefined : getColor(calculatedProps, child, index);
|
|
292
|
+
const defaultColor = childRole === "line" ? {
|
|
338
293
|
fill: "none",
|
|
339
294
|
stroke: defaultFill
|
|
340
295
|
} : {
|
|
341
296
|
fill: defaultFill
|
|
342
297
|
};
|
|
343
|
-
|
|
298
|
+
const dataWidth = role === "stack" ? {} : {
|
|
344
299
|
width: getWidth(calculatedProps)
|
|
345
300
|
};
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
return _objectSpread(_objectSpread({}, childStyle), {}, {
|
|
301
|
+
const dataStyle = _defaults({}, childStyle.data, Object.assign({}, dataWidth, style.data, defaultColor));
|
|
302
|
+
const labelsStyle = _defaults({}, childStyle.labels, style.labels);
|
|
303
|
+
return {
|
|
304
|
+
...childStyle,
|
|
352
305
|
parent: style.parent,
|
|
353
306
|
data: dataStyle,
|
|
354
307
|
labels: labelsStyle
|
|
355
|
-
}
|
|
308
|
+
};
|
|
356
309
|
}
|
|
357
310
|
export function getStringsFromCategories(childComponents, axis) {
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
311
|
+
const iteratee = child => {
|
|
312
|
+
const childProps = child.props || {};
|
|
361
313
|
if (!Domain.isDomainComponent(child) || !childProps.categories) {
|
|
362
314
|
return null;
|
|
363
315
|
}
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
var categoryStrings = categories && categories.filter(function (val) {
|
|
367
|
-
return typeof val === "string";
|
|
368
|
-
});
|
|
316
|
+
const categories = childProps.categories && !Array.isArray(childProps.categories) ? childProps.categories[axis] : childProps.props.categories;
|
|
317
|
+
const categoryStrings = categories && categories.filter(val => typeof val === "string");
|
|
369
318
|
return categoryStrings ? Collection.removeUndefined(categoryStrings) : [];
|
|
370
319
|
};
|
|
371
|
-
|
|
372
320
|
return Helpers.reduceChildren(childComponents.slice(0), iteratee);
|
|
373
321
|
}
|
|
374
322
|
export function getStringsFromData(childComponents) {
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
323
|
+
const iteratee = child => {
|
|
324
|
+
const childProps = child.props || {};
|
|
325
|
+
let data;
|
|
379
326
|
if (!Data.isDataComponent(child)) {
|
|
380
327
|
return null;
|
|
381
328
|
} else if (child.type && Helpers.isFunction(child.type.getData)) {
|
|
@@ -383,59 +330,49 @@ export function getStringsFromData(childComponents) {
|
|
|
383
330
|
} else {
|
|
384
331
|
data = Data.getData(childProps);
|
|
385
332
|
}
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
y: d.yName
|
|
391
|
-
};
|
|
392
|
-
});
|
|
333
|
+
return data.map(d => ({
|
|
334
|
+
x: d.xName,
|
|
335
|
+
y: d.yName
|
|
336
|
+
}));
|
|
393
337
|
};
|
|
394
|
-
|
|
395
|
-
var initialMemo = {
|
|
338
|
+
const initialMemo = {
|
|
396
339
|
x: [],
|
|
397
340
|
y: []
|
|
398
341
|
};
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
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;
|
|
342
|
+
const combine = (memo, datum) => {
|
|
343
|
+
const x = Array.isArray(datum) ? datum.map(d => d.x).filter(Boolean) : datum.x;
|
|
344
|
+
const y = Array.isArray(datum) ? datum.map(d => d.y).filter(Boolean) : datum.y;
|
|
407
345
|
return {
|
|
408
346
|
x: x !== undefined ? memo.x.concat(x) : memo.x,
|
|
409
347
|
y: y !== undefined ? memo.y.concat(y) : memo.y
|
|
410
348
|
};
|
|
411
349
|
};
|
|
412
|
-
|
|
413
350
|
return Helpers.reduceChildren(childComponents.slice(0), iteratee, {}, initialMemo, combine);
|
|
414
351
|
}
|
|
415
352
|
export function getCategoryAndAxisStringsFromChildren(props, axis, childComponents) {
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
return _uniq([
|
|
353
|
+
const categories = _isPlainObject(props.categories) ? props.categories[axis] : props.categories;
|
|
354
|
+
const axisComponent = Axis.getAxisComponent(childComponents, axis);
|
|
355
|
+
const axisStrings = axisComponent ? Data.getStringsFromAxes(axisComponent.props, axis) : [];
|
|
356
|
+
const categoryStrings = categories || getStringsFromCategories(childComponents, axis);
|
|
357
|
+
return _uniq([...categoryStrings, ...axisStrings].flat());
|
|
421
358
|
}
|
|
422
359
|
export function getStringsFromChildren(props, childComponents) {
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
360
|
+
const children = childComponents || React.Children.toArray(props.children);
|
|
361
|
+
const xStrings = getCategoryAndAxisStringsFromChildren(props, "x", children);
|
|
362
|
+
const yStrings = getCategoryAndAxisStringsFromChildren(props, "y", children);
|
|
363
|
+
const dataStrings = getStringsFromData(children);
|
|
427
364
|
return {
|
|
428
|
-
x: _uniq([
|
|
429
|
-
y: _uniq([
|
|
365
|
+
x: _uniq([...xStrings, ...dataStrings.x].flat()),
|
|
366
|
+
y: _uniq([...yStrings, ...dataStrings.y].flat())
|
|
430
367
|
};
|
|
431
368
|
}
|
|
432
369
|
export function getCategories(props, childComponents, allStrings) {
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
370
|
+
const xPropCategories = props.categories && !Array.isArray(props.categories) ? props.categories.x : props.categories;
|
|
371
|
+
const yPropCategories = props.categories && !Array.isArray(props.categories) ? props.categories.y : props.categories;
|
|
372
|
+
const fallbackRequired = !xPropCategories || !yPropCategories;
|
|
373
|
+
const fallbackProps = fallbackRequired ? allStrings || getStringsFromChildren(props, childComponents) : {};
|
|
374
|
+
const xCategories = xPropCategories || fallbackProps.x;
|
|
375
|
+
const yCategories = yPropCategories || fallbackProps.y;
|
|
439
376
|
return {
|
|
440
377
|
x: xCategories.length > 0 ? xCategories : undefined,
|
|
441
378
|
y: yCategories.length > 0 ? yCategories : undefined
|