victory-stack 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.
- package/dist/victory-stack.js +1106 -974
- package/dist/victory-stack.min.js +1 -1
- package/es/helper-methods.js +46 -0
- package/es/victory-stack.js +112 -180
- package/lib/helper-methods.js +51 -0
- package/lib/victory-stack.js +121 -183
- package/package.json +4 -4
- package/src/helper-methods.js +32 -0
- package/src/victory-stack.js +171 -158
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 _Hooks$useAnimationSt = _victoryCore.Hooks.useAnimationState(),
|
|
43
|
+
setAnimationState = _Hooks$useAnimationSt.setAnimationState,
|
|
44
|
+
getAnimationProps = _Hooks$useAnimationSt.getAnimationProps,
|
|
45
|
+
getProps = _Hooks$useAnimationSt.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.useMemoizedProps)(modifiedProps);
|
|
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 = _victoryCore.Hooks.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;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "victory-stack",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "36.2.0",
|
|
4
4
|
"description": "Stack Layout Component for Victory",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"data visualization",
|
|
@@ -22,8 +22,8 @@
|
|
|
22
22
|
"lodash": "^4.17.19",
|
|
23
23
|
"prop-types": "^15.5.8",
|
|
24
24
|
"react-fast-compare": "^2.0.0",
|
|
25
|
-
"victory-core": "^
|
|
26
|
-
"victory-shared-events": "^
|
|
25
|
+
"victory-core": "^36.2.0",
|
|
26
|
+
"victory-shared-events": "^36.2.0"
|
|
27
27
|
},
|
|
28
28
|
"peerDependencies": {
|
|
29
29
|
"react": "^16.6.0 || ^17.0.0"
|
|
@@ -32,5 +32,5 @@
|
|
|
32
32
|
"version": "yarn run nps build-libs && nps build-dists"
|
|
33
33
|
},
|
|
34
34
|
"sideEffects": false,
|
|
35
|
-
"gitHead": "
|
|
35
|
+
"gitHead": "00c362fcd3e8f3880e14d3ba42873c34dd69c577"
|
|
36
36
|
}
|
package/src/helper-methods.js
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
import { assign, keys, orderBy } from "lodash";
|
|
4
4
|
import React from "react";
|
|
5
5
|
import { Helpers, Scale, Wrapper } from "victory-core";
|
|
6
|
+
import isEqual from "react-fast-compare";
|
|
6
7
|
|
|
7
8
|
const fallbackProps = {
|
|
8
9
|
width: 450,
|
|
@@ -160,6 +161,37 @@ export function getCalculatedProps(props, childComponents) {
|
|
|
160
161
|
};
|
|
161
162
|
}
|
|
162
163
|
|
|
164
|
+
// We need to remove sharedEvents in order to memoize the calculated data
|
|
165
|
+
// With shared events, the props change on every event, and every value is re-calculated
|
|
166
|
+
const withoutSharedEvents = (props) => {
|
|
167
|
+
const { children } = props;
|
|
168
|
+
const modifiedChildren = React.Children.toArray(children).map((child) => {
|
|
169
|
+
return {
|
|
170
|
+
...child,
|
|
171
|
+
props: Helpers.omit(child.props, ["sharedEvents"])
|
|
172
|
+
};
|
|
173
|
+
});
|
|
174
|
+
props.children = modifiedChildren;
|
|
175
|
+
return props;
|
|
176
|
+
};
|
|
177
|
+
|
|
178
|
+
export function useMemoizedProps(initialProps) {
|
|
179
|
+
const modifiedProps = withoutSharedEvents(initialProps);
|
|
180
|
+
const [props, setProps] = React.useState(modifiedProps);
|
|
181
|
+
|
|
182
|
+
// React.memo uses shallow equality to compare objects. This way props
|
|
183
|
+
// will only be re-calculated when they change.
|
|
184
|
+
React.useEffect(() => {
|
|
185
|
+
if (!isEqual(modifiedProps, props)) {
|
|
186
|
+
setProps(modifiedProps);
|
|
187
|
+
}
|
|
188
|
+
}, [props, setProps, modifiedProps]);
|
|
189
|
+
|
|
190
|
+
return React.useMemo(() => {
|
|
191
|
+
return getCalculatedProps(props, props.children);
|
|
192
|
+
}, [props]);
|
|
193
|
+
}
|
|
194
|
+
|
|
163
195
|
function getLabels(props, datasets, index) {
|
|
164
196
|
if (!props.labels) {
|
|
165
197
|
return undefined;
|