victory-stack 36.0.0 → 36.2.2
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 +368 -257
- package/dist/victory-stack.min.js +1 -1
- package/es/helper-methods.js +46 -0
- package/es/victory-stack.js +8 -8
- package/lib/helper-methods.js +51 -0
- package/lib/victory-stack.js +6 -6
- package/package.json +4 -4
- package/src/helper-methods.js +32 -0
- package/src/victory-stack.js +5 -6
package/es/helper-methods.js
CHANGED
|
@@ -1,8 +1,22 @@
|
|
|
1
1
|
import _orderBy from "lodash/orderBy";
|
|
2
2
|
import _keys from "lodash/keys";
|
|
3
3
|
import _assign from "lodash/assign";
|
|
4
|
+
|
|
5
|
+
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _nonIterableRest(); }
|
|
6
|
+
|
|
7
|
+
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance"); }
|
|
8
|
+
|
|
9
|
+
function _iterableToArrayLimit(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_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; }
|
|
10
|
+
|
|
11
|
+
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
12
|
+
|
|
13
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; var ownKeys = Object.keys(source); if (typeof Object.getOwnPropertySymbols === 'function') { ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function (sym) { return Object.getOwnPropertyDescriptor(source, sym).enumerable; })); } ownKeys.forEach(function (key) { _defineProperty(target, key, source[key]); }); } return target; }
|
|
14
|
+
|
|
15
|
+
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; }
|
|
16
|
+
|
|
4
17
|
import React from "react";
|
|
5
18
|
import { Helpers, Scale, Wrapper } from "victory-core";
|
|
19
|
+
import isEqual from "react-fast-compare";
|
|
6
20
|
var fallbackProps = {
|
|
7
21
|
width: 450,
|
|
8
22
|
height: 300,
|
|
@@ -165,6 +179,38 @@ export function getCalculatedProps(props, childComponents) {
|
|
|
165
179
|
colorScale: colorScale,
|
|
166
180
|
role: role
|
|
167
181
|
};
|
|
182
|
+
} // We need to remove sharedEvents in order to memoize the calculated data
|
|
183
|
+
// With shared events, the props change on every event, and every value is re-calculated
|
|
184
|
+
|
|
185
|
+
var withoutSharedEvents = function (props) {
|
|
186
|
+
var children = props.children;
|
|
187
|
+
var modifiedChildren = React.Children.toArray(children).map(function (child) {
|
|
188
|
+
return _objectSpread({}, child, {
|
|
189
|
+
props: Helpers.omit(child.props, ["sharedEvents"])
|
|
190
|
+
});
|
|
191
|
+
});
|
|
192
|
+
props.children = modifiedChildren;
|
|
193
|
+
return props;
|
|
194
|
+
};
|
|
195
|
+
|
|
196
|
+
export function useMemoizedProps(initialProps) {
|
|
197
|
+
var modifiedProps = withoutSharedEvents(initialProps);
|
|
198
|
+
|
|
199
|
+
var _React$useState = React.useState(modifiedProps),
|
|
200
|
+
_React$useState2 = _slicedToArray(_React$useState, 2),
|
|
201
|
+
props = _React$useState2[0],
|
|
202
|
+
setProps = _React$useState2[1]; // React.memo uses shallow equality to compare objects. This way props
|
|
203
|
+
// will only be re-calculated when they change.
|
|
204
|
+
|
|
205
|
+
|
|
206
|
+
React.useEffect(function () {
|
|
207
|
+
if (!isEqual(modifiedProps, props)) {
|
|
208
|
+
setProps(modifiedProps);
|
|
209
|
+
}
|
|
210
|
+
}, [props, setProps, modifiedProps]);
|
|
211
|
+
return React.useMemo(function () {
|
|
212
|
+
return getCalculatedProps(props, props.children);
|
|
213
|
+
}, [props]);
|
|
168
214
|
}
|
|
169
215
|
|
|
170
216
|
function getLabels(props, datasets, index) {
|
package/es/victory-stack.js
CHANGED
|
@@ -8,9 +8,9 @@ function _defineProperty(obj, key, value) { if (key in obj) { Object.definePrope
|
|
|
8
8
|
|
|
9
9
|
import PropTypes from "prop-types";
|
|
10
10
|
import React from "react";
|
|
11
|
-
import { Helpers, VictoryContainer, VictoryTheme, CommonProps, Wrapper, PropTypes as CustomPropTypes,
|
|
11
|
+
import { Helpers, VictoryContainer, VictoryTheme, CommonProps, Wrapper, PropTypes as CustomPropTypes, Hooks } from "victory-core";
|
|
12
12
|
import { VictorySharedEvents } from "victory-shared-events";
|
|
13
|
-
import { getChildren,
|
|
13
|
+
import { getChildren, useMemoizedProps } from "./helper-methods";
|
|
14
14
|
import isEqual from "react-fast-compare";
|
|
15
15
|
var fallbackProps = {
|
|
16
16
|
width: 450,
|
|
@@ -22,10 +22,10 @@ var VictoryStack = function (initialProps) {
|
|
|
22
22
|
// eslint-disable-next-line no-use-before-define
|
|
23
23
|
var role = VictoryStackMemo.role;
|
|
24
24
|
|
|
25
|
-
var
|
|
26
|
-
setAnimationState =
|
|
27
|
-
getAnimationProps =
|
|
28
|
-
getProps =
|
|
25
|
+
var _Hooks$useAnimationSt = Hooks.useAnimationState(),
|
|
26
|
+
setAnimationState = _Hooks$useAnimationSt.setAnimationState,
|
|
27
|
+
getAnimationProps = _Hooks$useAnimationSt.getAnimationProps,
|
|
28
|
+
getProps = _Hooks$useAnimationSt.getProps;
|
|
29
29
|
|
|
30
30
|
var props = getProps(initialProps);
|
|
31
31
|
var modifiedProps = Helpers.modifyProps(props, fallbackProps, role);
|
|
@@ -41,7 +41,7 @@ var VictoryStack = function (initialProps) {
|
|
|
41
41
|
horizontal = modifiedProps.horizontal,
|
|
42
42
|
name = modifiedProps.name;
|
|
43
43
|
var childComponents = React.Children.toArray(modifiedProps.children);
|
|
44
|
-
var calculatedProps =
|
|
44
|
+
var calculatedProps = useMemoizedProps(modifiedProps);
|
|
45
45
|
var domain = calculatedProps.domain,
|
|
46
46
|
scale = calculatedProps.scale,
|
|
47
47
|
style = calculatedProps.style,
|
|
@@ -94,7 +94,7 @@ var VictoryStack = function (initialProps) {
|
|
|
94
94
|
var events = React.useMemo(function () {
|
|
95
95
|
return Wrapper.getAllEvents(props);
|
|
96
96
|
}, [props]);
|
|
97
|
-
var previousProps = usePreviousProps(initialProps);
|
|
97
|
+
var previousProps = Hooks.usePreviousProps(initialProps);
|
|
98
98
|
React.useEffect(function () {
|
|
99
99
|
// This is called before dismount to keep state in sync
|
|
100
100
|
return function () {
|
package/lib/helper-methods.js
CHANGED
|
@@ -4,6 +4,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.getCalculatedProps = getCalculatedProps;
|
|
7
|
+
exports.useMemoizedProps = useMemoizedProps;
|
|
7
8
|
exports.getChildProps = getChildProps;
|
|
8
9
|
exports.getChildren = getChildren;
|
|
9
10
|
|
|
@@ -17,8 +18,22 @@ var _react = _interopRequireDefault(require("react"));
|
|
|
17
18
|
|
|
18
19
|
var _victoryCore = require("victory-core");
|
|
19
20
|
|
|
21
|
+
var _reactFastCompare = _interopRequireDefault(require("react-fast-compare"));
|
|
22
|
+
|
|
20
23
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
21
24
|
|
|
25
|
+
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _nonIterableRest(); }
|
|
26
|
+
|
|
27
|
+
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance"); }
|
|
28
|
+
|
|
29
|
+
function _iterableToArrayLimit(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_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; }
|
|
30
|
+
|
|
31
|
+
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
32
|
+
|
|
33
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; var ownKeys = Object.keys(source); if (typeof Object.getOwnPropertySymbols === 'function') { ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function (sym) { return Object.getOwnPropertyDescriptor(source, sym).enumerable; })); } ownKeys.forEach(function (key) { _defineProperty(target, key, source[key]); }); } return target; }
|
|
34
|
+
|
|
35
|
+
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; }
|
|
36
|
+
|
|
22
37
|
var fallbackProps = {
|
|
23
38
|
width: 450,
|
|
24
39
|
height: 300,
|
|
@@ -182,6 +197,42 @@ function getCalculatedProps(props, childComponents) {
|
|
|
182
197
|
colorScale: colorScale,
|
|
183
198
|
role: role
|
|
184
199
|
};
|
|
200
|
+
} // We need to remove sharedEvents in order to memoize the calculated data
|
|
201
|
+
// With shared events, the props change on every event, and every value is re-calculated
|
|
202
|
+
|
|
203
|
+
|
|
204
|
+
var withoutSharedEvents = function (props) {
|
|
205
|
+
var children = props.children;
|
|
206
|
+
|
|
207
|
+
var modifiedChildren = _react.default.Children.toArray(children).map(function (child) {
|
|
208
|
+
return _objectSpread({}, child, {
|
|
209
|
+
props: _victoryCore.Helpers.omit(child.props, ["sharedEvents"])
|
|
210
|
+
});
|
|
211
|
+
});
|
|
212
|
+
|
|
213
|
+
props.children = modifiedChildren;
|
|
214
|
+
return props;
|
|
215
|
+
};
|
|
216
|
+
|
|
217
|
+
function useMemoizedProps(initialProps) {
|
|
218
|
+
var modifiedProps = withoutSharedEvents(initialProps);
|
|
219
|
+
|
|
220
|
+
var _React$useState = _react.default.useState(modifiedProps),
|
|
221
|
+
_React$useState2 = _slicedToArray(_React$useState, 2),
|
|
222
|
+
props = _React$useState2[0],
|
|
223
|
+
setProps = _React$useState2[1]; // React.memo uses shallow equality to compare objects. This way props
|
|
224
|
+
// will only be re-calculated when they change.
|
|
225
|
+
|
|
226
|
+
|
|
227
|
+
_react.default.useEffect(function () {
|
|
228
|
+
if (!(0, _reactFastCompare.default)(modifiedProps, props)) {
|
|
229
|
+
setProps(modifiedProps);
|
|
230
|
+
}
|
|
231
|
+
}, [props, setProps, modifiedProps]);
|
|
232
|
+
|
|
233
|
+
return _react.default.useMemo(function () {
|
|
234
|
+
return getCalculatedProps(props, props.children);
|
|
235
|
+
}, [props]);
|
|
185
236
|
}
|
|
186
237
|
|
|
187
238
|
function getLabels(props, datasets, index) {
|
package/lib/victory-stack.js
CHANGED
|
@@ -39,10 +39,10 @@ var VictoryStack = function (initialProps) {
|
|
|
39
39
|
// eslint-disable-next-line no-use-before-define
|
|
40
40
|
var role = VictoryStackMemo.role;
|
|
41
41
|
|
|
42
|
-
var
|
|
43
|
-
setAnimationState =
|
|
44
|
-
getAnimationProps =
|
|
45
|
-
getProps =
|
|
42
|
+
var _Hooks$useAnimationSt = _victoryCore.Hooks.useAnimationState(),
|
|
43
|
+
setAnimationState = _Hooks$useAnimationSt.setAnimationState,
|
|
44
|
+
getAnimationProps = _Hooks$useAnimationSt.getAnimationProps,
|
|
45
|
+
getProps = _Hooks$useAnimationSt.getProps;
|
|
46
46
|
|
|
47
47
|
var props = getProps(initialProps);
|
|
48
48
|
|
|
@@ -62,7 +62,7 @@ var VictoryStack = function (initialProps) {
|
|
|
62
62
|
|
|
63
63
|
var childComponents = _react.default.Children.toArray(modifiedProps.children);
|
|
64
64
|
|
|
65
|
-
var calculatedProps = (0, _helperMethods.
|
|
65
|
+
var calculatedProps = (0, _helperMethods.useMemoizedProps)(modifiedProps);
|
|
66
66
|
var domain = calculatedProps.domain,
|
|
67
67
|
scale = calculatedProps.scale,
|
|
68
68
|
style = calculatedProps.style,
|
|
@@ -118,7 +118,7 @@ var VictoryStack = function (initialProps) {
|
|
|
118
118
|
return _victoryCore.Wrapper.getAllEvents(props);
|
|
119
119
|
}, [props]);
|
|
120
120
|
|
|
121
|
-
var previousProps =
|
|
121
|
+
var previousProps = _victoryCore.Hooks.usePreviousProps(initialProps);
|
|
122
122
|
|
|
123
123
|
_react.default.useEffect(function () {
|
|
124
124
|
// This is called before dismount to keep state in sync
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "victory-stack",
|
|
3
|
-
"version": "36.
|
|
3
|
+
"version": "36.2.2",
|
|
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": "^36.
|
|
26
|
-
"victory-shared-events": "^36.
|
|
25
|
+
"victory-core": "^36.2.2",
|
|
26
|
+
"victory-shared-events": "^36.2.2"
|
|
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": "e09146d4bede80e27ed095fcd7e1167c00fba864"
|
|
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;
|
package/src/victory-stack.js
CHANGED
|
@@ -8,11 +8,10 @@ import {
|
|
|
8
8
|
CommonProps,
|
|
9
9
|
Wrapper,
|
|
10
10
|
PropTypes as CustomPropTypes,
|
|
11
|
-
|
|
12
|
-
usePreviousProps
|
|
11
|
+
Hooks
|
|
13
12
|
} from "victory-core";
|
|
14
13
|
import { VictorySharedEvents } from "victory-shared-events";
|
|
15
|
-
import { getChildren,
|
|
14
|
+
import { getChildren, useMemoizedProps } from "./helper-methods";
|
|
16
15
|
import isEqual from "react-fast-compare";
|
|
17
16
|
|
|
18
17
|
const fallbackProps = {
|
|
@@ -25,7 +24,7 @@ const VictoryStack = (initialProps) => {
|
|
|
25
24
|
// eslint-disable-next-line no-use-before-define
|
|
26
25
|
const { role } = VictoryStackMemo;
|
|
27
26
|
const { setAnimationState, getAnimationProps, getProps } =
|
|
28
|
-
useAnimationState();
|
|
27
|
+
Hooks.useAnimationState();
|
|
29
28
|
|
|
30
29
|
const props = getProps(initialProps);
|
|
31
30
|
|
|
@@ -45,7 +44,7 @@ const VictoryStack = (initialProps) => {
|
|
|
45
44
|
} = modifiedProps;
|
|
46
45
|
|
|
47
46
|
const childComponents = React.Children.toArray(modifiedProps.children);
|
|
48
|
-
const calculatedProps =
|
|
47
|
+
const calculatedProps = useMemoizedProps(modifiedProps);
|
|
49
48
|
const { domain, scale, style, origin } = calculatedProps;
|
|
50
49
|
|
|
51
50
|
const newChildren = React.useMemo(() => {
|
|
@@ -112,7 +111,7 @@ const VictoryStack = (initialProps) => {
|
|
|
112
111
|
return Wrapper.getAllEvents(props);
|
|
113
112
|
}, [props]);
|
|
114
113
|
|
|
115
|
-
const previousProps = usePreviousProps(initialProps);
|
|
114
|
+
const previousProps = Hooks.usePreviousProps(initialProps);
|
|
116
115
|
|
|
117
116
|
React.useEffect(() => {
|
|
118
117
|
// This is called before dismount to keep state in sync
|