victory-stack 36.9.1-next.0 → 36.9.2-next.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 +9 -3
- package/dist/victory-stack.js +2642 -3542
- package/dist/victory-stack.min.js +1 -1
- package/es/helper-methods.js +116 -163
- package/es/victory-stack.js +61 -72
- package/lib/helper-methods.js +116 -179
- package/lib/index.js +0 -2
- package/lib/victory-stack.js +60 -91
- package/package.json +12 -12
package/lib/helper-methods.js
CHANGED
|
@@ -7,87 +7,59 @@ exports.getCalculatedProps = getCalculatedProps;
|
|
|
7
7
|
exports.getChildProps = getChildProps;
|
|
8
8
|
exports.getChildren = getChildren;
|
|
9
9
|
exports.useMemoizedProps = useMemoizedProps;
|
|
10
|
-
|
|
11
10
|
var _orderBy2 = _interopRequireDefault(require("lodash/orderBy"));
|
|
12
|
-
|
|
13
11
|
var _keys2 = _interopRequireDefault(require("lodash/keys"));
|
|
14
|
-
|
|
15
12
|
var _react = _interopRequireDefault(require("react"));
|
|
16
|
-
|
|
17
13
|
var _victoryCore = require("victory-core");
|
|
18
|
-
|
|
19
14
|
var _reactFastCompare = _interopRequireDefault(require("react-fast-compare"));
|
|
20
|
-
|
|
21
15
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
16
|
+
/* eslint-disable no-use-before-define */
|
|
22
17
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
26
|
-
|
|
27
|
-
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); }
|
|
28
|
-
|
|
29
|
-
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; }
|
|
30
|
-
|
|
31
|
-
function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
|
|
32
|
-
|
|
33
|
-
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
34
|
-
|
|
35
|
-
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; }
|
|
36
|
-
|
|
37
|
-
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; }
|
|
38
|
-
|
|
39
|
-
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; }
|
|
40
|
-
|
|
41
|
-
var fallbackProps = {
|
|
18
|
+
const fallbackProps = {
|
|
42
19
|
width: 450,
|
|
43
20
|
height: 300,
|
|
44
21
|
padding: 50
|
|
45
|
-
};
|
|
22
|
+
};
|
|
46
23
|
|
|
24
|
+
// Assumes data in `datasets` is sorted by `Data.getData`.
|
|
47
25
|
function fillData(props, datasets) {
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
26
|
+
const {
|
|
27
|
+
fillInMissingData
|
|
28
|
+
} = props;
|
|
29
|
+
const xMap = datasets.reduce((prev, dataset) => {
|
|
30
|
+
dataset.forEach(datum => {
|
|
51
31
|
prev[datum._x instanceof Date ? datum._x.getTime() : datum._x] = true;
|
|
52
32
|
});
|
|
53
33
|
return prev;
|
|
54
34
|
}, {});
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
var parsedX = Number(x);
|
|
64
|
-
var datum = dataset[index - indexOffset];
|
|
65
|
-
|
|
35
|
+
const xKeys = (0, _keys2.default)(xMap).map(k => Number(k));
|
|
36
|
+
const xArr = (0, _orderBy2.default)(xKeys);
|
|
37
|
+
return datasets.map(dataset => {
|
|
38
|
+
let indexOffset = 0;
|
|
39
|
+
const isDate = dataset[0] && dataset[0]._x instanceof Date;
|
|
40
|
+
const filledInData = xArr.map((x, index) => {
|
|
41
|
+
let parsedX = Number(x);
|
|
42
|
+
const datum = dataset[index - indexOffset];
|
|
66
43
|
if (datum) {
|
|
67
|
-
|
|
68
|
-
|
|
44
|
+
const x1 = isDate ? datum._x.getTime() : datum._x;
|
|
69
45
|
if (x1 === parsedX) {
|
|
70
46
|
return datum;
|
|
71
47
|
}
|
|
72
|
-
|
|
73
48
|
indexOffset++;
|
|
74
|
-
|
|
75
|
-
var _y = fillInMissingData ? 0 : null;
|
|
76
|
-
|
|
49
|
+
const y = fillInMissingData ? 0 : null;
|
|
77
50
|
parsedX = isDate ? new Date(parsedX) : parsedX;
|
|
78
51
|
return {
|
|
79
52
|
x: parsedX,
|
|
80
|
-
y
|
|
53
|
+
y,
|
|
81
54
|
_x: parsedX,
|
|
82
|
-
_y:
|
|
55
|
+
_y: y
|
|
83
56
|
};
|
|
84
57
|
}
|
|
85
|
-
|
|
86
|
-
var y = fillInMissingData ? 0 : null;
|
|
58
|
+
const y = fillInMissingData ? 0 : null;
|
|
87
59
|
parsedX = isDate ? new Date(parsedX) : parsedX;
|
|
88
60
|
return {
|
|
89
61
|
x: parsedX,
|
|
90
|
-
y
|
|
62
|
+
y,
|
|
91
63
|
_x: parsedX,
|
|
92
64
|
_y: y
|
|
93
65
|
};
|
|
@@ -95,40 +67,29 @@ function fillData(props, datasets) {
|
|
|
95
67
|
return filledInData;
|
|
96
68
|
});
|
|
97
69
|
}
|
|
98
|
-
|
|
99
70
|
function getY0(datum, index, datasets) {
|
|
100
71
|
if (datum.y0) {
|
|
101
72
|
return datum.y0;
|
|
102
73
|
}
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
var previousDatasets = datasets.slice(0, index);
|
|
110
|
-
var previousPoints = previousDatasets.reduce(function (prev, dataset) {
|
|
111
|
-
return prev.concat(dataset.filter(function (previousDatum) {
|
|
112
|
-
return datum._x instanceof Date ? previousDatum._x.getTime() === datum._x.getTime() : previousDatum._x === datum._x;
|
|
113
|
-
}).map(function (previousDatum) {
|
|
114
|
-
return previousDatum._y || 0;
|
|
115
|
-
}));
|
|
74
|
+
const y = datum._y;
|
|
75
|
+
const group = datum._group;
|
|
76
|
+
const firstDatasetBaseline = datasets[0].map(d => d.y0);
|
|
77
|
+
const previousDatasets = datasets.slice(0, index);
|
|
78
|
+
const previousPoints = previousDatasets.reduce((prev, dataset) => {
|
|
79
|
+
return prev.concat(dataset.filter(previousDatum => datum._x instanceof Date ? previousDatum._x.getTime() === datum._x.getTime() : previousDatum._x === datum._x).map(previousDatum => previousDatum._y || 0));
|
|
116
80
|
}, []);
|
|
117
|
-
|
|
118
|
-
|
|
81
|
+
const y0 = previousPoints.length && previousPoints.reduce((memo, value) => {
|
|
82
|
+
const sameSign = y < 0 && value < 0 || y >= 0 && value >= 0;
|
|
119
83
|
return sameSign ? Number(value) + memo : memo;
|
|
120
84
|
}, firstDatasetBaseline[group] || 0);
|
|
121
|
-
return previousPoints.some(
|
|
122
|
-
return point instanceof Date;
|
|
123
|
-
}) ? new Date(y0) : y0;
|
|
85
|
+
return previousPoints.some(point => point instanceof Date) ? new Date(y0) : y0;
|
|
124
86
|
}
|
|
125
|
-
/* eslint-disable no-nested-ternary */
|
|
126
|
-
|
|
127
87
|
|
|
88
|
+
/* eslint-disable no-nested-ternary */
|
|
128
89
|
function addLayoutData(props, datasets, index) {
|
|
129
|
-
|
|
130
|
-
return datasets[index].map(
|
|
131
|
-
|
|
90
|
+
const xOffset = props.xOffset || 0;
|
|
91
|
+
return datasets[index].map(datum => {
|
|
92
|
+
const yOffset = getY0(datum, index, datasets) || 0;
|
|
132
93
|
return Object.assign({}, datum, {
|
|
133
94
|
_y0: !(datum._y instanceof Date) ? yOffset : yOffset ? new Date(yOffset) : datum._y,
|
|
134
95
|
_y1: datum._y === null ? null : datum._y instanceof Date ? new Date(Number(datum._y) + Number(yOffset)) : datum._y + yOffset,
|
|
@@ -138,176 +99,152 @@ function addLayoutData(props, datasets, index) {
|
|
|
138
99
|
}
|
|
139
100
|
/* eslint-enable no-nested-ternary */
|
|
140
101
|
|
|
141
|
-
|
|
142
102
|
function stackData(props, childComponents) {
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
return datum._x !== null && datum._y !== null;
|
|
148
|
-
});
|
|
149
|
-
});
|
|
150
|
-
var datasets = fillData(props, filterNullChildData);
|
|
151
|
-
return datasets.map(function (d, i) {
|
|
152
|
-
return addLayoutData(props, datasets, i);
|
|
153
|
-
});
|
|
103
|
+
const dataFromChildren = _victoryCore.Wrapper.getDataFromChildren(props, childComponents);
|
|
104
|
+
const filterNullChildData = dataFromChildren.map(dataset => dataset.filter(datum => datum._x !== null && datum._y !== null));
|
|
105
|
+
const datasets = fillData(props, filterNullChildData);
|
|
106
|
+
return datasets.map((d, i) => addLayoutData(props, datasets, i));
|
|
154
107
|
}
|
|
155
|
-
|
|
156
108
|
function getCalculatedProps(initialProps, childComponents) {
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
var categories = props.categories || _victoryCore.Wrapper.getCategories(props, children);
|
|
166
|
-
|
|
167
|
-
var datasets = props.datasets || stackData(props, children);
|
|
168
|
-
var clonedChildren = children.map(function (c, i) {
|
|
109
|
+
const children = childComponents || _react.default.Children.toArray(initialProps.children);
|
|
110
|
+
const role = "stack";
|
|
111
|
+
const props = _victoryCore.Helpers.modifyProps(initialProps, fallbackProps, role);
|
|
112
|
+
const style = _victoryCore.Wrapper.getStyle(props.theme, props.style, role);
|
|
113
|
+
const categories = props.categories || _victoryCore.Wrapper.getCategories(props, children);
|
|
114
|
+
const datasets = props.datasets || stackData(props, children);
|
|
115
|
+
const clonedChildren = children.map((c, i) => {
|
|
169
116
|
return /*#__PURE__*/_react.default.cloneElement(c, {
|
|
170
117
|
data: datasets[i]
|
|
171
118
|
});
|
|
172
119
|
});
|
|
173
|
-
|
|
120
|
+
const domain = {
|
|
174
121
|
x: _victoryCore.Wrapper.getDomain(Object.assign({}, props, {
|
|
175
|
-
categories
|
|
122
|
+
categories
|
|
176
123
|
}), "x", clonedChildren),
|
|
177
124
|
y: _victoryCore.Wrapper.getDomain(Object.assign({}, props, {
|
|
178
|
-
categories
|
|
125
|
+
categories
|
|
179
126
|
}), "y", clonedChildren)
|
|
180
127
|
};
|
|
181
|
-
|
|
128
|
+
const range = props.range || {
|
|
182
129
|
x: _victoryCore.Helpers.getRange(props, "x"),
|
|
183
130
|
y: _victoryCore.Helpers.getRange(props, "y")
|
|
184
131
|
};
|
|
185
|
-
|
|
132
|
+
const baseScale = {
|
|
186
133
|
x: _victoryCore.Scale.getScaleFromProps(props, "x") || _victoryCore.Wrapper.getScale(props, "x"),
|
|
187
134
|
y: _victoryCore.Scale.getScaleFromProps(props, "y") || _victoryCore.Wrapper.getScale(props, "y")
|
|
188
135
|
};
|
|
189
|
-
|
|
136
|
+
const scale = {
|
|
190
137
|
x: baseScale.x.domain(domain.x).range(props.horizontal ? range.y : range.x),
|
|
191
138
|
y: baseScale.y.domain(domain.y).range(props.horizontal ? range.x : range.y)
|
|
192
139
|
};
|
|
193
|
-
|
|
194
|
-
|
|
140
|
+
const {
|
|
141
|
+
colorScale,
|
|
142
|
+
horizontal
|
|
143
|
+
} = props;
|
|
195
144
|
return {
|
|
196
|
-
datasets
|
|
197
|
-
categories
|
|
198
|
-
range
|
|
199
|
-
domain
|
|
200
|
-
horizontal
|
|
201
|
-
scale
|
|
202
|
-
style
|
|
203
|
-
colorScale
|
|
204
|
-
role
|
|
145
|
+
datasets,
|
|
146
|
+
categories,
|
|
147
|
+
range,
|
|
148
|
+
domain,
|
|
149
|
+
horizontal,
|
|
150
|
+
scale,
|
|
151
|
+
style,
|
|
152
|
+
colorScale,
|
|
153
|
+
role
|
|
205
154
|
};
|
|
206
|
-
}
|
|
207
|
-
// With shared events, the props change on every event, and every value is re-calculated
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
var withoutSharedEvents = function (props) {
|
|
211
|
-
var children = props.children;
|
|
155
|
+
}
|
|
212
156
|
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
157
|
+
// We need to remove sharedEvents in order to memoize the calculated data
|
|
158
|
+
// With shared events, the props change on every event, and every value is re-calculated
|
|
159
|
+
const withoutSharedEvents = props => {
|
|
160
|
+
const {
|
|
161
|
+
children
|
|
162
|
+
} = props;
|
|
163
|
+
const modifiedChildren = _react.default.Children.toArray(children).map(_child => {
|
|
164
|
+
const child = _child;
|
|
165
|
+
return {
|
|
166
|
+
...child,
|
|
216
167
|
props: _victoryCore.Helpers.omit(child.props, ["sharedEvents"])
|
|
217
|
-
}
|
|
168
|
+
};
|
|
218
169
|
});
|
|
219
|
-
|
|
220
170
|
props.children = modifiedChildren;
|
|
221
171
|
return props;
|
|
222
172
|
};
|
|
223
|
-
|
|
224
173
|
function useMemoizedProps(initialProps) {
|
|
225
|
-
|
|
174
|
+
const modifiedProps = withoutSharedEvents(initialProps);
|
|
175
|
+
const [props, setProps] = _react.default.useState(modifiedProps);
|
|
226
176
|
|
|
227
|
-
|
|
228
|
-
_React$useState2 = _slicedToArray(_React$useState, 2),
|
|
229
|
-
props = _React$useState2[0],
|
|
230
|
-
setProps = _React$useState2[1]; // React.memo uses shallow equality to compare objects. This way props
|
|
177
|
+
// React.memo uses shallow equality to compare objects. This way props
|
|
231
178
|
// will only be re-calculated when they change.
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
_react.default.useEffect(function () {
|
|
179
|
+
_react.default.useEffect(() => {
|
|
235
180
|
if (!(0, _reactFastCompare.default)(modifiedProps, props)) {
|
|
236
181
|
setProps(modifiedProps);
|
|
237
182
|
}
|
|
238
183
|
}, [props, setProps, modifiedProps]);
|
|
239
|
-
|
|
240
|
-
return _react.default.useMemo(function () {
|
|
184
|
+
return _react.default.useMemo(() => {
|
|
241
185
|
return getCalculatedProps(props, props.children);
|
|
242
186
|
}, [props]);
|
|
243
187
|
}
|
|
244
|
-
|
|
245
188
|
function getLabels(props, datasets, index) {
|
|
246
189
|
if (!props.labels) {
|
|
247
190
|
return undefined;
|
|
248
191
|
}
|
|
249
|
-
|
|
250
192
|
return datasets.length === index + 1 ? props.labels : undefined;
|
|
251
193
|
}
|
|
252
|
-
|
|
253
194
|
function getChildProps(props, calculatedProps) {
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
195
|
+
const {
|
|
196
|
+
categories,
|
|
197
|
+
domain,
|
|
198
|
+
range,
|
|
199
|
+
scale,
|
|
200
|
+
horizontal
|
|
201
|
+
} = calculatedProps;
|
|
259
202
|
return {
|
|
260
203
|
height: props.height,
|
|
261
204
|
width: props.width,
|
|
262
205
|
padding: _victoryCore.Helpers.getPadding(props),
|
|
263
206
|
standalone: false,
|
|
264
207
|
theme: props.theme,
|
|
265
|
-
categories
|
|
266
|
-
domain
|
|
267
|
-
range
|
|
268
|
-
scale
|
|
269
|
-
horizontal
|
|
208
|
+
categories,
|
|
209
|
+
domain,
|
|
210
|
+
range,
|
|
211
|
+
scale,
|
|
212
|
+
horizontal
|
|
270
213
|
};
|
|
271
214
|
}
|
|
272
|
-
|
|
273
215
|
function getColorScale(props, child) {
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
216
|
+
const role = child.type && child.type.role;
|
|
217
|
+
const colorScaleOptions = child.props.colorScale || props.colorScale;
|
|
277
218
|
if (role !== "group" && role !== "stack") {
|
|
278
219
|
return undefined;
|
|
279
220
|
}
|
|
280
|
-
|
|
281
221
|
return props.theme ? colorScaleOptions || props.theme.props.colorScale : colorScaleOptions;
|
|
282
222
|
}
|
|
283
|
-
|
|
284
223
|
function getChildren(initialProps, childComponents, calculatedProps) {
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
return children.map(
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
var labels = props.labels ? getLabels(props, datasets, index) : child.props.labels;
|
|
300
|
-
var name = child.props.name || "".concat(parentName, "-").concat(role, "-").concat(index);
|
|
224
|
+
const props = _victoryCore.Helpers.modifyProps(initialProps, fallbackProps, "stack");
|
|
225
|
+
const children = childComponents || _react.default.Children.toArray(props.children);
|
|
226
|
+
const newCalculatedProps = calculatedProps || getCalculatedProps(props, children);
|
|
227
|
+
const {
|
|
228
|
+
datasets
|
|
229
|
+
} = newCalculatedProps;
|
|
230
|
+
const childProps = getChildProps(props, newCalculatedProps);
|
|
231
|
+
const parentName = props.name || "stack";
|
|
232
|
+
return children.map((child, index) => {
|
|
233
|
+
const role = child.type && child.type.role;
|
|
234
|
+
const data = datasets[index];
|
|
235
|
+
const style = _victoryCore.Wrapper.getChildStyle(child, index, newCalculatedProps);
|
|
236
|
+
const labels = props.labels ? getLabels(props, datasets, index) : child.props.labels;
|
|
237
|
+
const name = child.props.name || `${parentName}-${role}-${index}`;
|
|
301
238
|
return /*#__PURE__*/_react.default.cloneElement(child, Object.assign({
|
|
302
|
-
key:
|
|
303
|
-
labels
|
|
304
|
-
name
|
|
239
|
+
key: `${name}-key-${index}`,
|
|
240
|
+
labels,
|
|
241
|
+
name,
|
|
305
242
|
domainPadding: child.props.domainPadding || props.domainPadding,
|
|
306
243
|
theme: props.theme,
|
|
307
244
|
labelComponent: props.labelComponent || child.props.labelComponent,
|
|
308
|
-
style
|
|
245
|
+
style,
|
|
309
246
|
colorScale: getColorScale(props, child),
|
|
310
|
-
data
|
|
247
|
+
data,
|
|
311
248
|
polar: props.polar
|
|
312
249
|
}, childProps));
|
|
313
250
|
});
|
package/lib/index.js
CHANGED
|
@@ -3,9 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
|
|
7
6
|
var _victoryStack = require("./victory-stack");
|
|
8
|
-
|
|
9
7
|
Object.keys(_victoryStack).forEach(function (key) {
|
|
10
8
|
if (key === "default" || key === "__esModule") return;
|
|
11
9
|
if (key in exports && exports[key] === _victoryStack[key]) return;
|
package/lib/victory-stack.js
CHANGED
|
@@ -4,81 +4,65 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.VictoryStack = void 0;
|
|
7
|
-
|
|
8
7
|
var _isEmpty2 = _interopRequireDefault(require("lodash/isEmpty"));
|
|
9
|
-
|
|
10
8
|
var _defaults2 = _interopRequireDefault(require("lodash/defaults"));
|
|
11
|
-
|
|
12
9
|
var _react = _interopRequireDefault(require("react"));
|
|
13
|
-
|
|
14
10
|
var _victoryCore = require("victory-core");
|
|
15
|
-
|
|
16
11
|
var _victorySharedEvents = require("victory-shared-events");
|
|
17
|
-
|
|
18
12
|
var _helperMethods = require("./helper-methods");
|
|
19
|
-
|
|
20
13
|
var _reactFastCompare = _interopRequireDefault(require("react-fast-compare"));
|
|
21
|
-
|
|
22
14
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
23
|
-
|
|
24
|
-
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; }
|
|
25
|
-
|
|
26
|
-
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; }
|
|
27
|
-
|
|
28
|
-
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; }
|
|
29
|
-
|
|
30
|
-
var fallbackProps = {
|
|
15
|
+
const fallbackProps = {
|
|
31
16
|
width: 450,
|
|
32
17
|
height: 300,
|
|
33
18
|
padding: 50
|
|
34
19
|
};
|
|
35
|
-
|
|
20
|
+
const defaultProps = {
|
|
36
21
|
containerComponent: /*#__PURE__*/_react.default.createElement(_victoryCore.VictoryContainer, null),
|
|
37
22
|
groupComponent: /*#__PURE__*/_react.default.createElement("g", null),
|
|
38
23
|
standalone: true,
|
|
39
24
|
theme: _victoryCore.VictoryTheme.grayscale,
|
|
40
25
|
fillInMissingData: true
|
|
41
26
|
};
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
var childProps = Object.assign({
|
|
27
|
+
const VictoryStackBase = initialProps => {
|
|
28
|
+
const {
|
|
29
|
+
role
|
|
30
|
+
} = VictoryStack;
|
|
31
|
+
const propsWithDefaults = _react.default.useMemo(() => ({
|
|
32
|
+
...defaultProps,
|
|
33
|
+
...initialProps
|
|
34
|
+
}), [initialProps]);
|
|
35
|
+
const {
|
|
36
|
+
setAnimationState,
|
|
37
|
+
getAnimationProps,
|
|
38
|
+
getProps
|
|
39
|
+
} = _victoryCore.Hooks.useAnimationState();
|
|
40
|
+
const props = getProps(propsWithDefaults);
|
|
41
|
+
const modifiedProps = _victoryCore.Helpers.modifyProps(props, fallbackProps, role);
|
|
42
|
+
const {
|
|
43
|
+
eventKey,
|
|
44
|
+
containerComponent,
|
|
45
|
+
standalone,
|
|
46
|
+
groupComponent,
|
|
47
|
+
externalEventMutations,
|
|
48
|
+
width,
|
|
49
|
+
height,
|
|
50
|
+
theme,
|
|
51
|
+
polar,
|
|
52
|
+
horizontal,
|
|
53
|
+
name
|
|
54
|
+
} = modifiedProps;
|
|
55
|
+
const childComponents = _react.default.Children.toArray(modifiedProps.children);
|
|
56
|
+
const calculatedProps = (0, _helperMethods.useMemoizedProps)(modifiedProps);
|
|
57
|
+
const {
|
|
58
|
+
domain,
|
|
59
|
+
scale,
|
|
60
|
+
style
|
|
61
|
+
} = calculatedProps;
|
|
62
|
+
const newChildren = _react.default.useMemo(() => {
|
|
63
|
+
const children = (0, _helperMethods.getChildren)(props, childComponents, calculatedProps);
|
|
64
|
+
const orderedChildren = children.map((child, index) => {
|
|
65
|
+
const childProps = Object.assign({
|
|
82
66
|
animate: getAnimationProps(props, child, index)
|
|
83
67
|
}, child.props);
|
|
84
68
|
return /*#__PURE__*/_react.default.cloneElement(child, childProps);
|
|
@@ -88,57 +72,45 @@ var VictoryStackBase = function (initialProps) {
|
|
|
88
72
|
are rendered behind lower children. This looks nicer for stacked bars with cornerRadius, and
|
|
89
73
|
areas with strokes
|
|
90
74
|
*/
|
|
91
|
-
|
|
92
75
|
return orderedChildren.reverse();
|
|
93
76
|
}, [props, childComponents, calculatedProps, getAnimationProps]);
|
|
94
|
-
|
|
95
|
-
var containerProps = _react.default.useMemo(function () {
|
|
77
|
+
const containerProps = _react.default.useMemo(() => {
|
|
96
78
|
if (standalone) {
|
|
97
79
|
return {
|
|
98
|
-
domain
|
|
99
|
-
scale
|
|
100
|
-
width
|
|
101
|
-
height
|
|
102
|
-
standalone
|
|
103
|
-
theme
|
|
80
|
+
domain,
|
|
81
|
+
scale,
|
|
82
|
+
width,
|
|
83
|
+
height,
|
|
84
|
+
standalone,
|
|
85
|
+
theme,
|
|
104
86
|
style: style.parent,
|
|
105
|
-
horizontal
|
|
106
|
-
polar
|
|
107
|
-
name
|
|
87
|
+
horizontal,
|
|
88
|
+
polar,
|
|
89
|
+
name
|
|
108
90
|
};
|
|
109
91
|
}
|
|
110
|
-
|
|
111
92
|
return {};
|
|
112
93
|
}, [standalone, domain, scale, width, height, theme, style, horizontal, polar, name]);
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
return _victoryCore.UserProps.getSafeUserProps(propsWithDefaults);
|
|
116
|
-
}, [propsWithDefaults]);
|
|
117
|
-
|
|
118
|
-
var container = _react.default.useMemo(function () {
|
|
94
|
+
const userProps = _react.default.useMemo(() => _victoryCore.UserProps.getSafeUserProps(propsWithDefaults), [propsWithDefaults]);
|
|
95
|
+
const container = _react.default.useMemo(() => {
|
|
119
96
|
if (standalone) {
|
|
120
|
-
|
|
97
|
+
const defaultContainerProps = (0, _defaults2.default)({}, containerComponent.props, containerProps, userProps);
|
|
121
98
|
return /*#__PURE__*/_react.default.cloneElement(containerComponent, defaultContainerProps);
|
|
122
99
|
}
|
|
123
|
-
|
|
124
100
|
return /*#__PURE__*/_react.default.cloneElement(groupComponent, userProps);
|
|
125
101
|
}, [groupComponent, standalone, containerComponent, containerProps, userProps]);
|
|
126
|
-
|
|
127
|
-
var events = _react.default.useMemo(function () {
|
|
102
|
+
const events = _react.default.useMemo(() => {
|
|
128
103
|
return _victoryCore.Wrapper.getAllEvents(props);
|
|
129
104
|
}, [props]);
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
_react.default.useEffect(function () {
|
|
105
|
+
const previousProps = _victoryCore.Hooks.usePreviousProps(propsWithDefaults);
|
|
106
|
+
_react.default.useEffect(() => {
|
|
134
107
|
// This is called before dismount to keep state in sync
|
|
135
|
-
return
|
|
108
|
+
return () => {
|
|
136
109
|
if (propsWithDefaults.animate) {
|
|
137
110
|
setAnimationState(previousProps, propsWithDefaults);
|
|
138
111
|
}
|
|
139
112
|
};
|
|
140
113
|
}, [setAnimationState, previousProps, propsWithDefaults]);
|
|
141
|
-
|
|
142
114
|
if (!(0, _isEmpty2.default)(events)) {
|
|
143
115
|
return /*#__PURE__*/_react.default.createElement(_victorySharedEvents.VictorySharedEvents, {
|
|
144
116
|
container: container,
|
|
@@ -147,15 +119,12 @@ var VictoryStackBase = function (initialProps) {
|
|
|
147
119
|
externalEventMutations: externalEventMutations
|
|
148
120
|
}, newChildren);
|
|
149
121
|
}
|
|
150
|
-
|
|
151
122
|
return /*#__PURE__*/_react.default.cloneElement(container, container.props, newChildren);
|
|
152
123
|
};
|
|
153
|
-
|
|
154
|
-
var componentConfig = {
|
|
124
|
+
const componentConfig = {
|
|
155
125
|
role: "stack",
|
|
156
126
|
expectedComponents: ["groupComponent", "containerComponent", "labelComponent"],
|
|
157
127
|
getChildren: _helperMethods.getChildren
|
|
158
128
|
};
|
|
159
|
-
|
|
160
|
-
exports.VictoryStack = VictoryStack;
|
|
129
|
+
const VictoryStack = exports.VictoryStack = Object.assign( /*#__PURE__*/_react.default.memo(VictoryStackBase, _reactFastCompare.default), componentConfig);
|
|
161
130
|
VictoryStack.displayName = "VictoryStack";
|