victory-stack 35.11.2 → 36.1.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/LICENSE.txt +30 -0
- package/dist/victory-stack.js +681 -668
- package/dist/victory-stack.min.js +1 -1
- package/es/victory-stack.js +111 -179
- package/lib/victory-stack.js +121 -183
- package/package.json +6 -5
- package/src/victory-stack.js +171 -157
package/es/victory-stack.js
CHANGED
|
@@ -6,21 +6,9 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
|
|
|
6
6
|
|
|
7
7
|
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; }
|
|
8
8
|
|
|
9
|
-
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
10
|
-
|
|
11
|
-
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
|
|
12
|
-
|
|
13
|
-
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
|
|
14
|
-
|
|
15
|
-
function _possibleConstructorReturn(self, call) { if (call && (typeof call === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
|
|
16
|
-
|
|
17
|
-
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
|
|
18
|
-
|
|
19
|
-
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
|
20
|
-
|
|
21
9
|
import PropTypes from "prop-types";
|
|
22
10
|
import React from "react";
|
|
23
|
-
import { Helpers, VictoryContainer, VictoryTheme, CommonProps, Wrapper, PropTypes as CustomPropTypes } from "victory-core";
|
|
11
|
+
import { Helpers, VictoryContainer, VictoryTheme, CommonProps, Wrapper, PropTypes as CustomPropTypes, useAnimationState, usePreviousProps } from "victory-core";
|
|
24
12
|
import { VictorySharedEvents } from "victory-shared-events";
|
|
25
13
|
import { getChildren, getCalculatedProps } from "./helper-methods";
|
|
26
14
|
import isEqual from "react-fast-compare";
|
|
@@ -30,83 +18,53 @@ var fallbackProps = {
|
|
|
30
18
|
padding: 50
|
|
31
19
|
};
|
|
32
20
|
|
|
33
|
-
var VictoryStack =
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
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
|
-
/*
|
|
82
|
-
reverse render order for children of `VictoryStack` so that higher children in the stack
|
|
83
|
-
are rendered behind lower children. This looks nicer for stacked bars with cornerRadius, and
|
|
84
|
-
areas with strokes
|
|
85
|
-
*/
|
|
86
|
-
|
|
87
|
-
return newChildren.reverse();
|
|
88
|
-
}
|
|
89
|
-
}, {
|
|
90
|
-
key: "renderContainer",
|
|
91
|
-
value: function renderContainer(containerComponent, props) {
|
|
92
|
-
var containerProps = _defaults({}, containerComponent.props, props);
|
|
93
|
-
|
|
94
|
-
return React.cloneElement(containerComponent, containerProps);
|
|
95
|
-
}
|
|
96
|
-
}, {
|
|
97
|
-
key: "getContainerProps",
|
|
98
|
-
value: function getContainerProps(props, calculatedProps) {
|
|
99
|
-
var width = props.width,
|
|
100
|
-
height = props.height,
|
|
101
|
-
standalone = props.standalone,
|
|
102
|
-
theme = props.theme,
|
|
103
|
-
polar = props.polar,
|
|
104
|
-
horizontal = props.horizontal,
|
|
105
|
-
name = props.name;
|
|
106
|
-
var domain = calculatedProps.domain,
|
|
107
|
-
scale = calculatedProps.scale,
|
|
108
|
-
style = calculatedProps.style,
|
|
109
|
-
origin = calculatedProps.origin;
|
|
21
|
+
var VictoryStack = function (initialProps) {
|
|
22
|
+
// eslint-disable-next-line no-use-before-define
|
|
23
|
+
var role = VictoryStackMemo.role;
|
|
24
|
+
|
|
25
|
+
var _useAnimationState = useAnimationState(),
|
|
26
|
+
setAnimationState = _useAnimationState.setAnimationState,
|
|
27
|
+
getAnimationProps = _useAnimationState.getAnimationProps,
|
|
28
|
+
getProps = _useAnimationState.getProps;
|
|
29
|
+
|
|
30
|
+
var props = getProps(initialProps);
|
|
31
|
+
var modifiedProps = Helpers.modifyProps(props, fallbackProps, role);
|
|
32
|
+
var eventKey = modifiedProps.eventKey,
|
|
33
|
+
containerComponent = modifiedProps.containerComponent,
|
|
34
|
+
standalone = modifiedProps.standalone,
|
|
35
|
+
groupComponent = modifiedProps.groupComponent,
|
|
36
|
+
externalEventMutations = modifiedProps.externalEventMutations,
|
|
37
|
+
width = modifiedProps.width,
|
|
38
|
+
height = modifiedProps.height,
|
|
39
|
+
theme = modifiedProps.theme,
|
|
40
|
+
polar = modifiedProps.polar,
|
|
41
|
+
horizontal = modifiedProps.horizontal,
|
|
42
|
+
name = modifiedProps.name;
|
|
43
|
+
var childComponents = React.Children.toArray(modifiedProps.children);
|
|
44
|
+
var calculatedProps = getCalculatedProps(modifiedProps, childComponents);
|
|
45
|
+
var domain = calculatedProps.domain,
|
|
46
|
+
scale = calculatedProps.scale,
|
|
47
|
+
style = calculatedProps.style,
|
|
48
|
+
origin = calculatedProps.origin;
|
|
49
|
+
var newChildren = React.useMemo(function () {
|
|
50
|
+
var children = getChildren(props, childComponents, calculatedProps);
|
|
51
|
+
var orderedChildren = children.map(function (child, index) {
|
|
52
|
+
var childProps = _assign({
|
|
53
|
+
animate: getAnimationProps(props, child, index, "victory-stack")
|
|
54
|
+
}, child.props);
|
|
55
|
+
|
|
56
|
+
return React.cloneElement(child, childProps);
|
|
57
|
+
});
|
|
58
|
+
/*
|
|
59
|
+
reverse render order for children of `VictoryStack` so that higher children in the stack
|
|
60
|
+
are rendered behind lower children. This looks nicer for stacked bars with cornerRadius, and
|
|
61
|
+
areas with strokes
|
|
62
|
+
*/
|
|
63
|
+
|
|
64
|
+
return orderedChildren.reverse();
|
|
65
|
+
}, [props, childComponents, calculatedProps, getAnimationProps]);
|
|
66
|
+
var containerProps = React.useMemo(function () {
|
|
67
|
+
if (standalone) {
|
|
110
68
|
return {
|
|
111
69
|
domain: domain,
|
|
112
70
|
scale: scale,
|
|
@@ -121,98 +79,72 @@ function (_React$Component) {
|
|
|
121
79
|
name: name
|
|
122
80
|
};
|
|
123
81
|
}
|
|
124
|
-
}, {
|
|
125
|
-
key: "render",
|
|
126
|
-
value: function render() {
|
|
127
|
-
var role = this.constructor.role;
|
|
128
|
-
var props = this.state && this.state.nodesWillExit ? this.state.oldProps || this.props : this.props;
|
|
129
|
-
var modifiedProps = Helpers.modifyProps(props, fallbackProps, role);
|
|
130
|
-
var eventKey = modifiedProps.eventKey,
|
|
131
|
-
containerComponent = modifiedProps.containerComponent,
|
|
132
|
-
standalone = modifiedProps.standalone,
|
|
133
|
-
groupComponent = modifiedProps.groupComponent,
|
|
134
|
-
externalEventMutations = modifiedProps.externalEventMutations;
|
|
135
|
-
var childComponents = React.Children.toArray(modifiedProps.children);
|
|
136
|
-
var calculatedProps = getCalculatedProps(modifiedProps, childComponents);
|
|
137
|
-
var newChildren = this.getNewChildren(modifiedProps, childComponents, calculatedProps);
|
|
138
|
-
var containerProps = standalone ? this.getContainerProps(modifiedProps, calculatedProps) : {};
|
|
139
|
-
var container = standalone ? this.renderContainer(containerComponent, containerProps) : groupComponent;
|
|
140
|
-
var events = Wrapper.getAllEvents(props);
|
|
141
82
|
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
externalEventMutations: externalEventMutations
|
|
148
|
-
}, newChildren);
|
|
149
|
-
}
|
|
83
|
+
return {};
|
|
84
|
+
}, [standalone, domain, scale, width, height, theme, style, horizontal, polar, origin, name]);
|
|
85
|
+
var container = React.useMemo(function () {
|
|
86
|
+
if (standalone) {
|
|
87
|
+
var defaultContainerProps = _defaults({}, containerComponent.props, containerProps);
|
|
150
88
|
|
|
151
|
-
return React.cloneElement(
|
|
89
|
+
return React.cloneElement(containerComponent, defaultContainerProps);
|
|
152
90
|
}
|
|
153
|
-
}]);
|
|
154
|
-
|
|
155
|
-
return VictoryStack;
|
|
156
|
-
}(React.Component);
|
|
157
91
|
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
})
|
|
180
|
-
children: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.node), PropTypes.node]),
|
|
181
|
-
colorScale: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.string), PropTypes.oneOf(["grayscale", "qualitative", "heatmap", "warm", "cool", "red", "green", "blue"])]),
|
|
182
|
-
fillInMissingData: PropTypes.bool,
|
|
183
|
-
horizontal: PropTypes.bool,
|
|
184
|
-
labelComponent: PropTypes.element,
|
|
185
|
-
labels: PropTypes.oneOfType([PropTypes.func, PropTypes.array]),
|
|
186
|
-
style: PropTypes.shape({
|
|
187
|
-
parent: PropTypes.object,
|
|
188
|
-
data: PropTypes.object,
|
|
189
|
-
labels: PropTypes.object
|
|
190
|
-
}),
|
|
191
|
-
xOffset: PropTypes.number
|
|
192
|
-
})
|
|
193
|
-
});
|
|
194
|
-
Object.defineProperty(VictoryStack, "defaultProps", {
|
|
195
|
-
configurable: true,
|
|
196
|
-
enumerable: true,
|
|
197
|
-
writable: true,
|
|
198
|
-
value: {
|
|
199
|
-
containerComponent: React.createElement(VictoryContainer, null),
|
|
200
|
-
groupComponent: React.createElement("g", null),
|
|
201
|
-
standalone: true,
|
|
202
|
-
theme: VictoryTheme.grayscale,
|
|
203
|
-
fillInMissingData: true
|
|
92
|
+
return groupComponent;
|
|
93
|
+
}, [groupComponent, standalone, containerComponent, containerProps]);
|
|
94
|
+
var events = React.useMemo(function () {
|
|
95
|
+
return Wrapper.getAllEvents(props);
|
|
96
|
+
}, [props]);
|
|
97
|
+
var previousProps = usePreviousProps(initialProps);
|
|
98
|
+
React.useEffect(function () {
|
|
99
|
+
// This is called before dismount to keep state in sync
|
|
100
|
+
return function () {
|
|
101
|
+
if (initialProps.animate) {
|
|
102
|
+
setAnimationState(previousProps, initialProps);
|
|
103
|
+
}
|
|
104
|
+
};
|
|
105
|
+
}, [setAnimationState, previousProps, initialProps]);
|
|
106
|
+
|
|
107
|
+
if (!_isEmpty(events)) {
|
|
108
|
+
return React.createElement(VictorySharedEvents, {
|
|
109
|
+
container: container,
|
|
110
|
+
eventKey: eventKey,
|
|
111
|
+
events: events,
|
|
112
|
+
externalEventMutations: externalEventMutations
|
|
113
|
+
}, newChildren);
|
|
204
114
|
}
|
|
115
|
+
|
|
116
|
+
return React.cloneElement(container, container.props, newChildren);
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
VictoryStack.propTypes = _objectSpread({}, CommonProps.baseProps, {
|
|
120
|
+
bins: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([CustomPropTypes.nonNegative, PropTypes.instanceOf(Date)])), CustomPropTypes.nonNegative]),
|
|
121
|
+
categories: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.string), PropTypes.shape({
|
|
122
|
+
x: PropTypes.arrayOf(PropTypes.string),
|
|
123
|
+
y: PropTypes.arrayOf(PropTypes.string)
|
|
124
|
+
})]),
|
|
125
|
+
children: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.node), PropTypes.node]),
|
|
126
|
+
colorScale: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.string), PropTypes.oneOf(["grayscale", "qualitative", "heatmap", "warm", "cool", "red", "green", "blue"])]),
|
|
127
|
+
fillInMissingData: PropTypes.bool,
|
|
128
|
+
horizontal: PropTypes.bool,
|
|
129
|
+
labelComponent: PropTypes.element,
|
|
130
|
+
labels: PropTypes.oneOfType([PropTypes.func, PropTypes.array]),
|
|
131
|
+
style: PropTypes.shape({
|
|
132
|
+
parent: PropTypes.object,
|
|
133
|
+
data: PropTypes.object,
|
|
134
|
+
labels: PropTypes.object
|
|
135
|
+
}),
|
|
136
|
+
xOffset: PropTypes.number
|
|
205
137
|
});
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
export
|
|
138
|
+
VictoryStack.defaultProps = {
|
|
139
|
+
containerComponent: React.createElement(VictoryContainer, null),
|
|
140
|
+
groupComponent: React.createElement("g", null),
|
|
141
|
+
standalone: true,
|
|
142
|
+
theme: VictoryTheme.grayscale,
|
|
143
|
+
fillInMissingData: true
|
|
144
|
+
};
|
|
145
|
+
var VictoryStackMemo = React.memo(VictoryStack, isEqual);
|
|
146
|
+
VictoryStackMemo.displayName = "VictoryStack";
|
|
147
|
+
VictoryStackMemo.role = "stack";
|
|
148
|
+
VictoryStackMemo.expectedComponents = ["groupComponent", "containerComponent", "labelComponent"];
|
|
149
|
+
VictoryStackMemo.getChildren = getChildren;
|
|
150
|
+
export default VictoryStackMemo;
|
package/lib/victory-stack.js
CHANGED
|
@@ -29,101 +29,64 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
|
|
|
29
29
|
|
|
30
30
|
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; }
|
|
31
31
|
|
|
32
|
-
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
33
|
-
|
|
34
|
-
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
|
|
35
|
-
|
|
36
|
-
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
|
|
37
|
-
|
|
38
|
-
function _possibleConstructorReturn(self, call) { if (call && (typeof call === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
|
|
39
|
-
|
|
40
|
-
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
|
|
41
|
-
|
|
42
|
-
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
|
43
|
-
|
|
44
32
|
var fallbackProps = {
|
|
45
33
|
width: 450,
|
|
46
34
|
height: 300,
|
|
47
35
|
padding: 50
|
|
48
36
|
};
|
|
49
37
|
|
|
50
|
-
var VictoryStack =
|
|
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
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
areas with strokes
|
|
103
|
-
*/
|
|
104
|
-
|
|
105
|
-
return newChildren.reverse();
|
|
106
|
-
}
|
|
107
|
-
}, {
|
|
108
|
-
key: "renderContainer",
|
|
109
|
-
value: function renderContainer(containerComponent, props) {
|
|
110
|
-
var containerProps = (0, _defaults2.default)({}, containerComponent.props, props);
|
|
111
|
-
return _react.default.cloneElement(containerComponent, containerProps);
|
|
112
|
-
}
|
|
113
|
-
}, {
|
|
114
|
-
key: "getContainerProps",
|
|
115
|
-
value: function getContainerProps(props, calculatedProps) {
|
|
116
|
-
var width = props.width,
|
|
117
|
-
height = props.height,
|
|
118
|
-
standalone = props.standalone,
|
|
119
|
-
theme = props.theme,
|
|
120
|
-
polar = props.polar,
|
|
121
|
-
horizontal = props.horizontal,
|
|
122
|
-
name = props.name;
|
|
123
|
-
var domain = calculatedProps.domain,
|
|
124
|
-
scale = calculatedProps.scale,
|
|
125
|
-
style = calculatedProps.style,
|
|
126
|
-
origin = calculatedProps.origin;
|
|
38
|
+
var VictoryStack = function (initialProps) {
|
|
39
|
+
// eslint-disable-next-line no-use-before-define
|
|
40
|
+
var role = VictoryStackMemo.role;
|
|
41
|
+
|
|
42
|
+
var _useAnimationState = (0, _victoryCore.useAnimationState)(),
|
|
43
|
+
setAnimationState = _useAnimationState.setAnimationState,
|
|
44
|
+
getAnimationProps = _useAnimationState.getAnimationProps,
|
|
45
|
+
getProps = _useAnimationState.getProps;
|
|
46
|
+
|
|
47
|
+
var props = getProps(initialProps);
|
|
48
|
+
|
|
49
|
+
var modifiedProps = _victoryCore.Helpers.modifyProps(props, fallbackProps, role);
|
|
50
|
+
|
|
51
|
+
var eventKey = modifiedProps.eventKey,
|
|
52
|
+
containerComponent = modifiedProps.containerComponent,
|
|
53
|
+
standalone = modifiedProps.standalone,
|
|
54
|
+
groupComponent = modifiedProps.groupComponent,
|
|
55
|
+
externalEventMutations = modifiedProps.externalEventMutations,
|
|
56
|
+
width = modifiedProps.width,
|
|
57
|
+
height = modifiedProps.height,
|
|
58
|
+
theme = modifiedProps.theme,
|
|
59
|
+
polar = modifiedProps.polar,
|
|
60
|
+
horizontal = modifiedProps.horizontal,
|
|
61
|
+
name = modifiedProps.name;
|
|
62
|
+
|
|
63
|
+
var childComponents = _react.default.Children.toArray(modifiedProps.children);
|
|
64
|
+
|
|
65
|
+
var calculatedProps = (0, _helperMethods.getCalculatedProps)(modifiedProps, childComponents);
|
|
66
|
+
var domain = calculatedProps.domain,
|
|
67
|
+
scale = calculatedProps.scale,
|
|
68
|
+
style = calculatedProps.style,
|
|
69
|
+
origin = calculatedProps.origin;
|
|
70
|
+
|
|
71
|
+
var newChildren = _react.default.useMemo(function () {
|
|
72
|
+
var children = (0, _helperMethods.getChildren)(props, childComponents, calculatedProps);
|
|
73
|
+
var orderedChildren = children.map(function (child, index) {
|
|
74
|
+
var childProps = (0, _assign2.default)({
|
|
75
|
+
animate: getAnimationProps(props, child, index, "victory-stack")
|
|
76
|
+
}, child.props);
|
|
77
|
+
return _react.default.cloneElement(child, childProps);
|
|
78
|
+
});
|
|
79
|
+
/*
|
|
80
|
+
reverse render order for children of `VictoryStack` so that higher children in the stack
|
|
81
|
+
are rendered behind lower children. This looks nicer for stacked bars with cornerRadius, and
|
|
82
|
+
areas with strokes
|
|
83
|
+
*/
|
|
84
|
+
|
|
85
|
+
return orderedChildren.reverse();
|
|
86
|
+
}, [props, childComponents, calculatedProps, getAnimationProps]);
|
|
87
|
+
|
|
88
|
+
var containerProps = _react.default.useMemo(function () {
|
|
89
|
+
if (standalone) {
|
|
127
90
|
return {
|
|
128
91
|
domain: domain,
|
|
129
92
|
scale: scale,
|
|
@@ -138,103 +101,78 @@ function (_React$Component) {
|
|
|
138
101
|
name: name
|
|
139
102
|
};
|
|
140
103
|
}
|
|
141
|
-
}, {
|
|
142
|
-
key: "render",
|
|
143
|
-
value: function render() {
|
|
144
|
-
var role = this.constructor.role;
|
|
145
|
-
var props = this.state && this.state.nodesWillExit ? this.state.oldProps || this.props : this.props;
|
|
146
|
-
|
|
147
|
-
var modifiedProps = _victoryCore.Helpers.modifyProps(props, fallbackProps, role);
|
|
148
|
-
|
|
149
|
-
var eventKey = modifiedProps.eventKey,
|
|
150
|
-
containerComponent = modifiedProps.containerComponent,
|
|
151
|
-
standalone = modifiedProps.standalone,
|
|
152
|
-
groupComponent = modifiedProps.groupComponent,
|
|
153
|
-
externalEventMutations = modifiedProps.externalEventMutations;
|
|
154
|
-
|
|
155
|
-
var childComponents = _react.default.Children.toArray(modifiedProps.children);
|
|
156
|
-
|
|
157
|
-
var calculatedProps = (0, _helperMethods.getCalculatedProps)(modifiedProps, childComponents);
|
|
158
|
-
var newChildren = this.getNewChildren(modifiedProps, childComponents, calculatedProps);
|
|
159
|
-
var containerProps = standalone ? this.getContainerProps(modifiedProps, calculatedProps) : {};
|
|
160
|
-
var container = standalone ? this.renderContainer(containerComponent, containerProps) : groupComponent;
|
|
161
|
-
|
|
162
|
-
var events = _victoryCore.Wrapper.getAllEvents(props);
|
|
163
|
-
|
|
164
|
-
if (!(0, _isEmpty2.default)(events)) {
|
|
165
|
-
return _react.default.createElement(_victorySharedEvents.VictorySharedEvents, {
|
|
166
|
-
container: container,
|
|
167
|
-
eventKey: eventKey,
|
|
168
|
-
events: events,
|
|
169
|
-
externalEventMutations: externalEventMutations
|
|
170
|
-
}, newChildren);
|
|
171
|
-
}
|
|
172
104
|
|
|
173
|
-
|
|
105
|
+
return {};
|
|
106
|
+
}, [standalone, domain, scale, width, height, theme, style, horizontal, polar, origin, name]);
|
|
107
|
+
|
|
108
|
+
var container = _react.default.useMemo(function () {
|
|
109
|
+
if (standalone) {
|
|
110
|
+
var defaultContainerProps = (0, _defaults2.default)({}, containerComponent.props, containerProps);
|
|
111
|
+
return _react.default.cloneElement(containerComponent, defaultContainerProps);
|
|
174
112
|
}
|
|
175
|
-
}]);
|
|
176
113
|
|
|
177
|
-
|
|
178
|
-
}
|
|
114
|
+
return groupComponent;
|
|
115
|
+
}, [groupComponent, standalone, containerComponent, containerProps]);
|
|
179
116
|
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
})]),
|
|
203
|
-
children: _propTypes.default.oneOfType([_propTypes.default.arrayOf(_propTypes.default.node), _propTypes.default.node]),
|
|
204
|
-
colorScale: _propTypes.default.oneOfType([_propTypes.default.arrayOf(_propTypes.default.string), _propTypes.default.oneOf(["grayscale", "qualitative", "heatmap", "warm", "cool", "red", "green", "blue"])]),
|
|
205
|
-
fillInMissingData: _propTypes.default.bool,
|
|
206
|
-
horizontal: _propTypes.default.bool,
|
|
207
|
-
labelComponent: _propTypes.default.element,
|
|
208
|
-
labels: _propTypes.default.oneOfType([_propTypes.default.func, _propTypes.default.array]),
|
|
209
|
-
style: _propTypes.default.shape({
|
|
210
|
-
parent: _propTypes.default.object,
|
|
211
|
-
data: _propTypes.default.object,
|
|
212
|
-
labels: _propTypes.default.object
|
|
213
|
-
}),
|
|
214
|
-
xOffset: _propTypes.default.number
|
|
215
|
-
})
|
|
216
|
-
});
|
|
217
|
-
Object.defineProperty(VictoryStack, "defaultProps", {
|
|
218
|
-
configurable: true,
|
|
219
|
-
enumerable: true,
|
|
220
|
-
writable: true,
|
|
221
|
-
value: {
|
|
222
|
-
containerComponent: _react.default.createElement(_victoryCore.VictoryContainer, null),
|
|
223
|
-
groupComponent: _react.default.createElement("g", null),
|
|
224
|
-
standalone: true,
|
|
225
|
-
theme: _victoryCore.VictoryTheme.grayscale,
|
|
226
|
-
fillInMissingData: true
|
|
117
|
+
var events = _react.default.useMemo(function () {
|
|
118
|
+
return _victoryCore.Wrapper.getAllEvents(props);
|
|
119
|
+
}, [props]);
|
|
120
|
+
|
|
121
|
+
var previousProps = (0, _victoryCore.usePreviousProps)(initialProps);
|
|
122
|
+
|
|
123
|
+
_react.default.useEffect(function () {
|
|
124
|
+
// This is called before dismount to keep state in sync
|
|
125
|
+
return function () {
|
|
126
|
+
if (initialProps.animate) {
|
|
127
|
+
setAnimationState(previousProps, initialProps);
|
|
128
|
+
}
|
|
129
|
+
};
|
|
130
|
+
}, [setAnimationState, previousProps, initialProps]);
|
|
131
|
+
|
|
132
|
+
if (!(0, _isEmpty2.default)(events)) {
|
|
133
|
+
return _react.default.createElement(_victorySharedEvents.VictorySharedEvents, {
|
|
134
|
+
container: container,
|
|
135
|
+
eventKey: eventKey,
|
|
136
|
+
events: events,
|
|
137
|
+
externalEventMutations: externalEventMutations
|
|
138
|
+
}, newChildren);
|
|
227
139
|
}
|
|
140
|
+
|
|
141
|
+
return _react.default.cloneElement(container, container.props, newChildren);
|
|
142
|
+
};
|
|
143
|
+
|
|
144
|
+
VictoryStack.propTypes = _objectSpread({}, _victoryCore.CommonProps.baseProps, {
|
|
145
|
+
bins: _propTypes.default.oneOfType([_propTypes.default.arrayOf(_propTypes.default.oneOfType([_victoryCore.PropTypes.nonNegative, _propTypes.default.instanceOf(Date)])), _victoryCore.PropTypes.nonNegative]),
|
|
146
|
+
categories: _propTypes.default.oneOfType([_propTypes.default.arrayOf(_propTypes.default.string), _propTypes.default.shape({
|
|
147
|
+
x: _propTypes.default.arrayOf(_propTypes.default.string),
|
|
148
|
+
y: _propTypes.default.arrayOf(_propTypes.default.string)
|
|
149
|
+
})]),
|
|
150
|
+
children: _propTypes.default.oneOfType([_propTypes.default.arrayOf(_propTypes.default.node), _propTypes.default.node]),
|
|
151
|
+
colorScale: _propTypes.default.oneOfType([_propTypes.default.arrayOf(_propTypes.default.string), _propTypes.default.oneOf(["grayscale", "qualitative", "heatmap", "warm", "cool", "red", "green", "blue"])]),
|
|
152
|
+
fillInMissingData: _propTypes.default.bool,
|
|
153
|
+
horizontal: _propTypes.default.bool,
|
|
154
|
+
labelComponent: _propTypes.default.element,
|
|
155
|
+
labels: _propTypes.default.oneOfType([_propTypes.default.func, _propTypes.default.array]),
|
|
156
|
+
style: _propTypes.default.shape({
|
|
157
|
+
parent: _propTypes.default.object,
|
|
158
|
+
data: _propTypes.default.object,
|
|
159
|
+
labels: _propTypes.default.object
|
|
160
|
+
}),
|
|
161
|
+
xOffset: _propTypes.default.number
|
|
228
162
|
});
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
163
|
+
VictoryStack.defaultProps = {
|
|
164
|
+
containerComponent: _react.default.createElement(_victoryCore.VictoryContainer, null),
|
|
165
|
+
groupComponent: _react.default.createElement("g", null),
|
|
166
|
+
standalone: true,
|
|
167
|
+
theme: _victoryCore.VictoryTheme.grayscale,
|
|
168
|
+
fillInMissingData: true
|
|
169
|
+
};
|
|
170
|
+
|
|
171
|
+
var VictoryStackMemo = _react.default.memo(VictoryStack, _reactFastCompare.default);
|
|
172
|
+
|
|
173
|
+
VictoryStackMemo.displayName = "VictoryStack";
|
|
174
|
+
VictoryStackMemo.role = "stack";
|
|
175
|
+
VictoryStackMemo.expectedComponents = ["groupComponent", "containerComponent", "labelComponent"];
|
|
176
|
+
VictoryStackMemo.getChildren = _helperMethods.getChildren;
|
|
177
|
+
var _default = VictoryStackMemo;
|
|
178
|
+
exports.default = _default;
|