victory-group 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-group.js +369 -259
- 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 +8 -8
- package/lib/helper-methods.js +51 -0
- package/lib/index.d.ts +1 -0
- package/lib/victory-group.js +6 -6
- package/package.json +4 -4
- package/src/helper-methods.js +33 -1
- package/src/index.d.ts +1 -0
- package/src/victory-group.js +5 -6
package/es/helper-methods.js
CHANGED
|
@@ -8,8 +8,21 @@ function _iterableToArray(iter) { if (Symbol.iterator in Object(iter) || Object.
|
|
|
8
8
|
|
|
9
9
|
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = new Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } }
|
|
10
10
|
|
|
11
|
+
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _nonIterableRest(); }
|
|
12
|
+
|
|
13
|
+
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance"); }
|
|
14
|
+
|
|
15
|
+
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; }
|
|
16
|
+
|
|
17
|
+
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
18
|
+
|
|
19
|
+
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; }
|
|
20
|
+
|
|
21
|
+
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; }
|
|
22
|
+
|
|
11
23
|
import React from "react";
|
|
12
|
-
import { Helpers, Scale,
|
|
24
|
+
import { Data, Helpers, Scale, Wrapper } from "victory-core";
|
|
25
|
+
import isEqual from "react-fast-compare";
|
|
13
26
|
var fallbackProps = {
|
|
14
27
|
width: 450,
|
|
15
28
|
height: 300,
|
|
@@ -65,6 +78,38 @@ export function getCalculatedProps(props, childComponents) {
|
|
|
65
78
|
origin: origin,
|
|
66
79
|
padding: padding
|
|
67
80
|
};
|
|
81
|
+
} // We need to remove sharedEvents in order to memoize the calculated data
|
|
82
|
+
// With shared events, the props change on every event, and every value is re-calculated
|
|
83
|
+
|
|
84
|
+
var withoutSharedEvents = function (props) {
|
|
85
|
+
var children = props.children;
|
|
86
|
+
var modifiedChildren = React.Children.toArray(children).map(function (child) {
|
|
87
|
+
return _objectSpread({}, child, {
|
|
88
|
+
props: Helpers.omit(child.props, ["sharedEvents"])
|
|
89
|
+
});
|
|
90
|
+
});
|
|
91
|
+
props.children = modifiedChildren;
|
|
92
|
+
return props;
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
export function useMemoizedProps(initialProps) {
|
|
96
|
+
var modifiedProps = withoutSharedEvents(initialProps);
|
|
97
|
+
|
|
98
|
+
var _React$useState = React.useState(modifiedProps),
|
|
99
|
+
_React$useState2 = _slicedToArray(_React$useState, 2),
|
|
100
|
+
props = _React$useState2[0],
|
|
101
|
+
setProps = _React$useState2[1]; // React.memo uses shallow equality to compare objects. This way props
|
|
102
|
+
// will only be re-calculated when they change.
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
React.useEffect(function () {
|
|
106
|
+
if (!isEqual(modifiedProps, props)) {
|
|
107
|
+
setProps(modifiedProps);
|
|
108
|
+
}
|
|
109
|
+
}, [props, setProps, modifiedProps]);
|
|
110
|
+
return React.useMemo(function () {
|
|
111
|
+
return getCalculatedProps(props, props.children);
|
|
112
|
+
}, [props]);
|
|
68
113
|
}
|
|
69
114
|
|
|
70
115
|
function pixelsToValue(props, axis, calculatedProps) {
|
package/es/index.d.ts
CHANGED
package/es/victory-group.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,
|
|
11
|
+
import { Helpers, VictoryContainer, VictoryTheme, CommonProps, Wrapper, 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,
|
|
@@ -23,10 +23,10 @@ var VictoryGroup = function (initialProps) {
|
|
|
23
23
|
// eslint-disable-next-line no-use-before-define
|
|
24
24
|
var role = VictoryGroupMemo.role;
|
|
25
25
|
|
|
26
|
-
var
|
|
27
|
-
getAnimationProps =
|
|
28
|
-
setAnimationState =
|
|
29
|
-
getProps =
|
|
26
|
+
var _Hooks$useAnimationSt = Hooks.useAnimationState(),
|
|
27
|
+
getAnimationProps = _Hooks$useAnimationSt.getAnimationProps,
|
|
28
|
+
setAnimationState = _Hooks$useAnimationSt.setAnimationState,
|
|
29
|
+
getProps = _Hooks$useAnimationSt.getProps;
|
|
30
30
|
|
|
31
31
|
var props = getProps(initialProps);
|
|
32
32
|
var modifiedProps = Helpers.modifyProps(props, fallbackProps, role);
|
|
@@ -42,7 +42,7 @@ var VictoryGroup = function (initialProps) {
|
|
|
42
42
|
horizontal = modifiedProps.horizontal,
|
|
43
43
|
name = modifiedProps.name;
|
|
44
44
|
var childComponents = React.Children.toArray(modifiedProps.children);
|
|
45
|
-
var calculatedProps =
|
|
45
|
+
var calculatedProps = useMemoizedProps(modifiedProps);
|
|
46
46
|
var domain = calculatedProps.domain,
|
|
47
47
|
scale = calculatedProps.scale,
|
|
48
48
|
style = calculatedProps.style,
|
|
@@ -88,7 +88,7 @@ var VictoryGroup = function (initialProps) {
|
|
|
88
88
|
var events = React.useMemo(function () {
|
|
89
89
|
return Wrapper.getAllEvents(props);
|
|
90
90
|
}, [props]);
|
|
91
|
-
var previousProps = usePreviousProps(initialProps);
|
|
91
|
+
var previousProps = Hooks.usePreviousProps(initialProps);
|
|
92
92
|
React.useEffect(function () {
|
|
93
93
|
// This is called before dismount to keep state in sync
|
|
94
94
|
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.getChildren = getChildren;
|
|
8
9
|
|
|
9
10
|
var _assign2 = _interopRequireDefault(require("lodash/assign"));
|
|
@@ -12,6 +13,8 @@ var _react = _interopRequireDefault(require("react"));
|
|
|
12
13
|
|
|
13
14
|
var _victoryCore = require("victory-core");
|
|
14
15
|
|
|
16
|
+
var _reactFastCompare = _interopRequireDefault(require("react-fast-compare"));
|
|
17
|
+
|
|
15
18
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
16
19
|
|
|
17
20
|
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _nonIterableSpread(); }
|
|
@@ -22,6 +25,18 @@ function _iterableToArray(iter) { if (Symbol.iterator in Object(iter) || Object.
|
|
|
22
25
|
|
|
23
26
|
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = new Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } }
|
|
24
27
|
|
|
28
|
+
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _nonIterableRest(); }
|
|
29
|
+
|
|
30
|
+
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance"); }
|
|
31
|
+
|
|
32
|
+
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; }
|
|
33
|
+
|
|
34
|
+
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
35
|
+
|
|
36
|
+
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; }
|
|
37
|
+
|
|
38
|
+
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; }
|
|
39
|
+
|
|
25
40
|
var fallbackProps = {
|
|
26
41
|
width: 450,
|
|
27
42
|
height: 300,
|
|
@@ -84,6 +99,42 @@ function getCalculatedProps(props, childComponents) {
|
|
|
84
99
|
origin: origin,
|
|
85
100
|
padding: padding
|
|
86
101
|
};
|
|
102
|
+
} // We need to remove sharedEvents in order to memoize the calculated data
|
|
103
|
+
// With shared events, the props change on every event, and every value is re-calculated
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
var withoutSharedEvents = function (props) {
|
|
107
|
+
var children = props.children;
|
|
108
|
+
|
|
109
|
+
var modifiedChildren = _react.default.Children.toArray(children).map(function (child) {
|
|
110
|
+
return _objectSpread({}, child, {
|
|
111
|
+
props: _victoryCore.Helpers.omit(child.props, ["sharedEvents"])
|
|
112
|
+
});
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
props.children = modifiedChildren;
|
|
116
|
+
return props;
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
function useMemoizedProps(initialProps) {
|
|
120
|
+
var modifiedProps = withoutSharedEvents(initialProps);
|
|
121
|
+
|
|
122
|
+
var _React$useState = _react.default.useState(modifiedProps),
|
|
123
|
+
_React$useState2 = _slicedToArray(_React$useState, 2),
|
|
124
|
+
props = _React$useState2[0],
|
|
125
|
+
setProps = _React$useState2[1]; // React.memo uses shallow equality to compare objects. This way props
|
|
126
|
+
// will only be re-calculated when they change.
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
_react.default.useEffect(function () {
|
|
130
|
+
if (!(0, _reactFastCompare.default)(modifiedProps, props)) {
|
|
131
|
+
setProps(modifiedProps);
|
|
132
|
+
}
|
|
133
|
+
}, [props, setProps, modifiedProps]);
|
|
134
|
+
|
|
135
|
+
return _react.default.useMemo(function () {
|
|
136
|
+
return getCalculatedProps(props, props.children);
|
|
137
|
+
}, [props]);
|
|
87
138
|
}
|
|
88
139
|
|
|
89
140
|
function pixelsToValue(props, axis, calculatedProps) {
|
package/lib/index.d.ts
CHANGED
package/lib/victory-group.js
CHANGED
|
@@ -40,10 +40,10 @@ var VictoryGroup = function (initialProps) {
|
|
|
40
40
|
// eslint-disable-next-line no-use-before-define
|
|
41
41
|
var role = VictoryGroupMemo.role;
|
|
42
42
|
|
|
43
|
-
var
|
|
44
|
-
getAnimationProps =
|
|
45
|
-
setAnimationState =
|
|
46
|
-
getProps =
|
|
43
|
+
var _Hooks$useAnimationSt = _victoryCore.Hooks.useAnimationState(),
|
|
44
|
+
getAnimationProps = _Hooks$useAnimationSt.getAnimationProps,
|
|
45
|
+
setAnimationState = _Hooks$useAnimationSt.setAnimationState,
|
|
46
|
+
getProps = _Hooks$useAnimationSt.getProps;
|
|
47
47
|
|
|
48
48
|
var props = getProps(initialProps);
|
|
49
49
|
|
|
@@ -63,7 +63,7 @@ var VictoryGroup = function (initialProps) {
|
|
|
63
63
|
|
|
64
64
|
var childComponents = _react.default.Children.toArray(modifiedProps.children);
|
|
65
65
|
|
|
66
|
-
var calculatedProps = (0, _helperMethods.
|
|
66
|
+
var calculatedProps = (0, _helperMethods.useMemoizedProps)(modifiedProps);
|
|
67
67
|
var domain = calculatedProps.domain,
|
|
68
68
|
scale = calculatedProps.scale,
|
|
69
69
|
style = calculatedProps.style,
|
|
@@ -112,7 +112,7 @@ var VictoryGroup = function (initialProps) {
|
|
|
112
112
|
return _victoryCore.Wrapper.getAllEvents(props);
|
|
113
113
|
}, [props]);
|
|
114
114
|
|
|
115
|
-
var previousProps =
|
|
115
|
+
var previousProps = _victoryCore.Hooks.usePreviousProps(initialProps);
|
|
116
116
|
|
|
117
117
|
_react.default.useEffect(function () {
|
|
118
118
|
// This is called before dismount to keep state in sync
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "victory-group",
|
|
3
|
-
"version": "36.
|
|
3
|
+
"version": "36.2.2",
|
|
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": "^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
|
@@ -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
package/src/victory-group.js
CHANGED
|
@@ -7,11 +7,10 @@ import {
|
|
|
7
7
|
VictoryTheme,
|
|
8
8
|
CommonProps,
|
|
9
9
|
Wrapper,
|
|
10
|
-
|
|
11
|
-
useAnimationState
|
|
10
|
+
Hooks
|
|
12
11
|
} from "victory-core";
|
|
13
12
|
import { VictorySharedEvents } from "victory-shared-events";
|
|
14
|
-
import { getChildren,
|
|
13
|
+
import { getChildren, useMemoizedProps } from "./helper-methods";
|
|
15
14
|
import isEqual from "react-fast-compare";
|
|
16
15
|
|
|
17
16
|
const fallbackProps = {
|
|
@@ -25,7 +24,7 @@ const VictoryGroup = (initialProps) => {
|
|
|
25
24
|
// eslint-disable-next-line no-use-before-define
|
|
26
25
|
const { role } = VictoryGroupMemo;
|
|
27
26
|
const { getAnimationProps, setAnimationState, getProps } =
|
|
28
|
-
useAnimationState();
|
|
27
|
+
Hooks.useAnimationState();
|
|
29
28
|
const props = getProps(initialProps);
|
|
30
29
|
|
|
31
30
|
const modifiedProps = Helpers.modifyProps(props, fallbackProps, role);
|
|
@@ -44,7 +43,7 @@ const VictoryGroup = (initialProps) => {
|
|
|
44
43
|
} = modifiedProps;
|
|
45
44
|
|
|
46
45
|
const childComponents = React.Children.toArray(modifiedProps.children);
|
|
47
|
-
const calculatedProps =
|
|
46
|
+
const calculatedProps = useMemoizedProps(modifiedProps);
|
|
48
47
|
const { domain, scale, style, origin } = calculatedProps;
|
|
49
48
|
|
|
50
49
|
const newChildren = React.useMemo(() => {
|
|
@@ -105,7 +104,7 @@ const VictoryGroup = (initialProps) => {
|
|
|
105
104
|
return Wrapper.getAllEvents(props);
|
|
106
105
|
}, [props]);
|
|
107
106
|
|
|
108
|
-
const previousProps = usePreviousProps(initialProps);
|
|
107
|
+
const previousProps = Hooks.usePreviousProps(initialProps);
|
|
109
108
|
|
|
110
109
|
React.useEffect(() => {
|
|
111
110
|
// This is called before dismount to keep state in sync
|