victory-group 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-group.js +991 -858
- package/dist/victory-group.min.js +1 -1
- package/es/helper-methods.js +46 -1
- package/es/index.d.ts +1 -0
- package/es/victory-group.js +96 -162
- package/lib/helper-methods.js +51 -0
- package/lib/index.d.ts +1 -0
- package/lib/victory-group.js +104 -165
- package/package.json +4 -4
- package/src/helper-methods.js +33 -1
- package/src/index.d.ts +1 -0
- package/src/victory-group.js +148 -134
package/lib/victory-group.js
CHANGED
|
@@ -29,18 +29,6 @@ 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,
|
|
@@ -48,76 +36,51 @@ var fallbackProps = {
|
|
|
48
36
|
offset: 0
|
|
49
37
|
};
|
|
50
38
|
|
|
51
|
-
var VictoryGroup =
|
|
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
|
-
animate: getAnimationProps(props, child, index)
|
|
97
|
-
}, child.props);
|
|
98
|
-
return _react.default.cloneElement(child, childProps);
|
|
99
|
-
});
|
|
100
|
-
}
|
|
101
|
-
}, {
|
|
102
|
-
key: "renderContainer",
|
|
103
|
-
value: function renderContainer(containerComponent, props) {
|
|
104
|
-
var containerProps = (0, _defaults2.default)({}, containerComponent.props, props);
|
|
105
|
-
return _react.default.cloneElement(containerComponent, containerProps);
|
|
106
|
-
}
|
|
107
|
-
}, {
|
|
108
|
-
key: "getContainerProps",
|
|
109
|
-
value: function getContainerProps(props, calculatedProps) {
|
|
110
|
-
var width = props.width,
|
|
111
|
-
height = props.height,
|
|
112
|
-
standalone = props.standalone,
|
|
113
|
-
theme = props.theme,
|
|
114
|
-
polar = props.polar,
|
|
115
|
-
horizontal = props.horizontal,
|
|
116
|
-
name = props.name;
|
|
117
|
-
var domain = calculatedProps.domain,
|
|
118
|
-
scale = calculatedProps.scale,
|
|
119
|
-
style = calculatedProps.style,
|
|
120
|
-
origin = calculatedProps.origin;
|
|
39
|
+
var VictoryGroup = function (initialProps) {
|
|
40
|
+
// eslint-disable-next-line no-use-before-define
|
|
41
|
+
var role = VictoryGroupMemo.role;
|
|
42
|
+
|
|
43
|
+
var _Hooks$useAnimationSt = _victoryCore.Hooks.useAnimationState(),
|
|
44
|
+
getAnimationProps = _Hooks$useAnimationSt.getAnimationProps,
|
|
45
|
+
setAnimationState = _Hooks$useAnimationSt.setAnimationState,
|
|
46
|
+
getProps = _Hooks$useAnimationSt.getProps;
|
|
47
|
+
|
|
48
|
+
var props = getProps(initialProps);
|
|
49
|
+
|
|
50
|
+
var modifiedProps = _victoryCore.Helpers.modifyProps(props, fallbackProps, role);
|
|
51
|
+
|
|
52
|
+
var eventKey = modifiedProps.eventKey,
|
|
53
|
+
containerComponent = modifiedProps.containerComponent,
|
|
54
|
+
standalone = modifiedProps.standalone,
|
|
55
|
+
groupComponent = modifiedProps.groupComponent,
|
|
56
|
+
externalEventMutations = modifiedProps.externalEventMutations,
|
|
57
|
+
width = modifiedProps.width,
|
|
58
|
+
height = modifiedProps.height,
|
|
59
|
+
theme = modifiedProps.theme,
|
|
60
|
+
polar = modifiedProps.polar,
|
|
61
|
+
horizontal = modifiedProps.horizontal,
|
|
62
|
+
name = modifiedProps.name;
|
|
63
|
+
|
|
64
|
+
var childComponents = _react.default.Children.toArray(modifiedProps.children);
|
|
65
|
+
|
|
66
|
+
var calculatedProps = (0, _helperMethods.useMemoizedProps)(modifiedProps);
|
|
67
|
+
var domain = calculatedProps.domain,
|
|
68
|
+
scale = calculatedProps.scale,
|
|
69
|
+
style = calculatedProps.style,
|
|
70
|
+
origin = calculatedProps.origin;
|
|
71
|
+
|
|
72
|
+
var newChildren = _react.default.useMemo(function () {
|
|
73
|
+
var children = (0, _helperMethods.getChildren)(props, childComponents, calculatedProps);
|
|
74
|
+
return children.map(function (child, index) {
|
|
75
|
+
var childProps = (0, _assign2.default)({
|
|
76
|
+
animate: getAnimationProps(props, child, index, "victory-group")
|
|
77
|
+
}, child.props);
|
|
78
|
+
return _react.default.cloneElement(child, childProps);
|
|
79
|
+
});
|
|
80
|
+
}, [props, childComponents, calculatedProps, getAnimationProps]);
|
|
81
|
+
|
|
82
|
+
var containerProps = _react.default.useMemo(function () {
|
|
83
|
+
if (standalone) {
|
|
121
84
|
return {
|
|
122
85
|
domain: domain,
|
|
123
86
|
scale: scale,
|
|
@@ -132,92 +95,68 @@ function (_React$Component) {
|
|
|
132
95
|
name: name
|
|
133
96
|
};
|
|
134
97
|
}
|
|
135
|
-
}, {
|
|
136
|
-
key: "render",
|
|
137
|
-
value: function render() {
|
|
138
|
-
var role = this.constructor.role;
|
|
139
|
-
var props = this.state && this.state.nodesWillExit ? this.state.oldProps || this.props : this.props;
|
|
140
|
-
|
|
141
|
-
var modifiedProps = _victoryCore.Helpers.modifyProps(props, fallbackProps, role);
|
|
142
|
-
|
|
143
|
-
var eventKey = modifiedProps.eventKey,
|
|
144
|
-
containerComponent = modifiedProps.containerComponent,
|
|
145
|
-
standalone = modifiedProps.standalone,
|
|
146
|
-
groupComponent = modifiedProps.groupComponent,
|
|
147
|
-
externalEventMutations = modifiedProps.externalEventMutations;
|
|
148
|
-
|
|
149
|
-
var childComponents = _react.default.Children.toArray(modifiedProps.children);
|
|
150
|
-
|
|
151
|
-
var calculatedProps = (0, _helperMethods.getCalculatedProps)(modifiedProps, childComponents);
|
|
152
|
-
var newChildren = this.getNewChildren(modifiedProps, childComponents, calculatedProps);
|
|
153
|
-
var containerProps = standalone ? this.getContainerProps(modifiedProps, calculatedProps) : {};
|
|
154
|
-
var container = standalone ? this.renderContainer(containerComponent, containerProps) : groupComponent;
|
|
155
|
-
|
|
156
|
-
var events = _victoryCore.Wrapper.getAllEvents(props);
|
|
157
|
-
|
|
158
|
-
if (!(0, _isEmpty2.default)(events)) {
|
|
159
|
-
return _react.default.createElement(_victorySharedEvents.VictorySharedEvents, {
|
|
160
|
-
container: container,
|
|
161
|
-
eventKey: eventKey,
|
|
162
|
-
events: events,
|
|
163
|
-
externalEventMutations: externalEventMutations
|
|
164
|
-
}, newChildren);
|
|
165
|
-
}
|
|
166
98
|
|
|
167
|
-
|
|
99
|
+
return {};
|
|
100
|
+
}, [standalone, domain, scale, width, height, theme, style, horizontal, polar, origin, name]);
|
|
101
|
+
|
|
102
|
+
var container = _react.default.useMemo(function () {
|
|
103
|
+
if (standalone) {
|
|
104
|
+
var defaultContainerProps = (0, _defaults2.default)({}, containerComponent.props, containerProps);
|
|
105
|
+
return _react.default.cloneElement(containerComponent, defaultContainerProps);
|
|
168
106
|
}
|
|
169
|
-
}]);
|
|
170
107
|
|
|
171
|
-
|
|
172
|
-
}
|
|
108
|
+
return groupComponent;
|
|
109
|
+
}, [groupComponent, standalone, containerComponent, containerProps]);
|
|
173
110
|
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
offset: _propTypes.default.number
|
|
197
|
-
})
|
|
198
|
-
});
|
|
199
|
-
Object.defineProperty(VictoryGroup, "defaultProps", {
|
|
200
|
-
configurable: true,
|
|
201
|
-
enumerable: true,
|
|
202
|
-
writable: true,
|
|
203
|
-
value: {
|
|
204
|
-
containerComponent: _react.default.createElement(_victoryCore.VictoryContainer, null),
|
|
205
|
-
groupComponent: _react.default.createElement("g", null),
|
|
206
|
-
samples: 50,
|
|
207
|
-
sortOrder: "ascending",
|
|
208
|
-
standalone: true,
|
|
209
|
-
theme: _victoryCore.VictoryTheme.grayscale
|
|
111
|
+
var events = _react.default.useMemo(function () {
|
|
112
|
+
return _victoryCore.Wrapper.getAllEvents(props);
|
|
113
|
+
}, [props]);
|
|
114
|
+
|
|
115
|
+
var previousProps = _victoryCore.Hooks.usePreviousProps(initialProps);
|
|
116
|
+
|
|
117
|
+
_react.default.useEffect(function () {
|
|
118
|
+
// This is called before dismount to keep state in sync
|
|
119
|
+
return function () {
|
|
120
|
+
if (initialProps.animate) {
|
|
121
|
+
setAnimationState(previousProps, props);
|
|
122
|
+
}
|
|
123
|
+
};
|
|
124
|
+
}, [setAnimationState, previousProps, initialProps, props]);
|
|
125
|
+
|
|
126
|
+
if (!(0, _isEmpty2.default)(events)) {
|
|
127
|
+
return _react.default.createElement(_victorySharedEvents.VictorySharedEvents, {
|
|
128
|
+
container: container,
|
|
129
|
+
eventKey: eventKey,
|
|
130
|
+
events: events,
|
|
131
|
+
externalEventMutations: externalEventMutations
|
|
132
|
+
}, newChildren);
|
|
210
133
|
}
|
|
134
|
+
|
|
135
|
+
return _react.default.cloneElement(container, container.props, newChildren);
|
|
136
|
+
};
|
|
137
|
+
|
|
138
|
+
VictoryGroup.propTypes = _objectSpread({}, _victoryCore.CommonProps.baseProps, _victoryCore.CommonProps.dataProps, {
|
|
139
|
+
children: _propTypes.default.oneOfType([_propTypes.default.arrayOf(_propTypes.default.node), _propTypes.default.node]),
|
|
140
|
+
color: _propTypes.default.oneOfType([_propTypes.default.string, _propTypes.default.func]),
|
|
141
|
+
colorScale: _propTypes.default.oneOfType([_propTypes.default.arrayOf(_propTypes.default.string), _propTypes.default.oneOf(["grayscale", "qualitative", "heatmap", "warm", "cool", "red", "green", "blue"])]),
|
|
142
|
+
horizontal: _propTypes.default.bool,
|
|
143
|
+
offset: _propTypes.default.number
|
|
211
144
|
});
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
145
|
+
VictoryGroup.defaultProps = {
|
|
146
|
+
containerComponent: _react.default.createElement(_victoryCore.VictoryContainer, null),
|
|
147
|
+
groupComponent: _react.default.createElement("g", null),
|
|
148
|
+
samples: 50,
|
|
149
|
+
sortOrder: "ascending",
|
|
150
|
+
standalone: true,
|
|
151
|
+
theme: _victoryCore.VictoryTheme.grayscale
|
|
152
|
+
}; // We need to attatch the static properties to the memoized version, or else
|
|
153
|
+
// VictoryChart will not be able to get this component's role type
|
|
154
|
+
|
|
155
|
+
var VictoryGroupMemo = _react.default.memo(VictoryGroup, _reactFastCompare.default);
|
|
156
|
+
|
|
157
|
+
VictoryGroupMemo.displayName = "VictoryGroup";
|
|
158
|
+
VictoryGroupMemo.role = "group";
|
|
159
|
+
VictoryGroupMemo.expectedComponents = ["groupComponent", "containerComponent", "labelComponent"];
|
|
160
|
+
VictoryGroupMemo.getChildren = _helperMethods.getChildren;
|
|
161
|
+
var _default = VictoryGroupMemo;
|
|
162
|
+
exports.default = _default;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "victory-group",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "36.2.0",
|
|
4
4
|
"description": "Group 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
|
@@ -2,7 +2,8 @@
|
|
|
2
2
|
/* eslint-disable no-use-before-define */
|
|
3
3
|
import { assign } from "lodash";
|
|
4
4
|
import React from "react";
|
|
5
|
-
import { Helpers, Scale,
|
|
5
|
+
import { Data, Helpers, Scale, Wrapper } from "victory-core";
|
|
6
|
+
import isEqual from "react-fast-compare";
|
|
6
7
|
|
|
7
8
|
const fallbackProps = {
|
|
8
9
|
width: 450,
|
|
@@ -63,6 +64,37 @@ export function getCalculatedProps(props, childComponents) {
|
|
|
63
64
|
};
|
|
64
65
|
}
|
|
65
66
|
|
|
67
|
+
// We need to remove sharedEvents in order to memoize the calculated data
|
|
68
|
+
// With shared events, the props change on every event, and every value is re-calculated
|
|
69
|
+
const withoutSharedEvents = (props) => {
|
|
70
|
+
const { children } = props;
|
|
71
|
+
const modifiedChildren = React.Children.toArray(children).map((child) => {
|
|
72
|
+
return {
|
|
73
|
+
...child,
|
|
74
|
+
props: Helpers.omit(child.props, ["sharedEvents"])
|
|
75
|
+
};
|
|
76
|
+
});
|
|
77
|
+
props.children = modifiedChildren;
|
|
78
|
+
return props;
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
export function useMemoizedProps(initialProps) {
|
|
82
|
+
const modifiedProps = withoutSharedEvents(initialProps);
|
|
83
|
+
const [props, setProps] = React.useState(modifiedProps);
|
|
84
|
+
|
|
85
|
+
// React.memo uses shallow equality to compare objects. This way props
|
|
86
|
+
// will only be re-calculated when they change.
|
|
87
|
+
React.useEffect(() => {
|
|
88
|
+
if (!isEqual(modifiedProps, props)) {
|
|
89
|
+
setProps(modifiedProps);
|
|
90
|
+
}
|
|
91
|
+
}, [props, setProps, modifiedProps]);
|
|
92
|
+
|
|
93
|
+
return React.useMemo(() => {
|
|
94
|
+
return getCalculatedProps(props, props.children);
|
|
95
|
+
}, [props]);
|
|
96
|
+
}
|
|
97
|
+
|
|
66
98
|
function pixelsToValue(props, axis, calculatedProps) {
|
|
67
99
|
if (!props.offset) {
|
|
68
100
|
return 0;
|
package/src/index.d.ts
CHANGED