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.
@@ -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
- /*#__PURE__*/
35
- function (_React$Component) {
36
- _inherits(VictoryStack, _React$Component);
37
-
38
- function VictoryStack(props) {
39
- var _this;
40
-
41
- _classCallCheck(this, VictoryStack);
42
-
43
- _this = _possibleConstructorReturn(this, (VictoryStack.__proto__ || Object.getPrototypeOf(VictoryStack)).call(this, props));
44
-
45
- if (props.animate) {
46
- _this.state = {
47
- nodesShouldLoad: false,
48
- nodesDoneLoad: false,
49
- animating: true
50
- };
51
- _this.setAnimationState = Wrapper.setAnimationState.bind(_assertThisInitialized(_this));
52
- }
53
-
54
- return _this;
55
- }
56
-
57
- _createClass(VictoryStack, [{
58
- key: "shouldComponentUpdate",
59
- value: function shouldComponentUpdate(nextProps) {
60
- if (this.props.animate) {
61
- if (!isEqual(this.props, nextProps)) {
62
- this.setAnimationState(this.props, nextProps);
63
- return false;
64
- }
65
- }
66
-
67
- return true;
68
- }
69
- }, {
70
- key: "getNewChildren",
71
- value: function getNewChildren(props, childComponents, calculatedProps) {
72
- var children = getChildren(props, childComponents, calculatedProps);
73
- var getAnimationProps = Wrapper.getAnimationProps.bind(this);
74
- var newChildren = children.map(function (child, index) {
75
- var childProps = _assign({
76
- animate: getAnimationProps(props, child, index)
77
- }, child.props);
78
-
79
- return React.cloneElement(child, childProps);
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
- if (!_isEmpty(events)) {
143
- return React.createElement(VictorySharedEvents, {
144
- container: container,
145
- eventKey: eventKey,
146
- events: events,
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(container, container.props, newChildren);
89
+ return React.cloneElement(containerComponent, defaultContainerProps);
152
90
  }
153
- }]);
154
-
155
- return VictoryStack;
156
- }(React.Component);
157
91
 
158
- Object.defineProperty(VictoryStack, "displayName", {
159
- configurable: true,
160
- enumerable: true,
161
- writable: true,
162
- value: "VictoryStack"
163
- });
164
- Object.defineProperty(VictoryStack, "role", {
165
- configurable: true,
166
- enumerable: true,
167
- writable: true,
168
- value: "stack"
169
- });
170
- Object.defineProperty(VictoryStack, "propTypes", {
171
- configurable: true,
172
- enumerable: true,
173
- writable: true,
174
- value: _objectSpread({}, CommonProps.baseProps, {
175
- bins: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([CustomPropTypes.nonNegative, PropTypes.instanceOf(Date)])), CustomPropTypes.nonNegative]),
176
- categories: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.string), PropTypes.shape({
177
- x: PropTypes.arrayOf(PropTypes.string),
178
- y: PropTypes.arrayOf(PropTypes.string)
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
- Object.defineProperty(VictoryStack, "expectedComponents", {
207
- configurable: true,
208
- enumerable: true,
209
- writable: true,
210
- value: ["groupComponent", "containerComponent", "labelComponent"]
211
- });
212
- Object.defineProperty(VictoryStack, "getChildren", {
213
- configurable: true,
214
- enumerable: true,
215
- writable: true,
216
- value: getChildren
217
- });
218
- export { VictoryStack as default };
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;
@@ -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
- /*#__PURE__*/
52
- function (_React$Component) {
53
- _inherits(VictoryStack, _React$Component);
54
-
55
- function VictoryStack(props) {
56
- var _this;
57
-
58
- _classCallCheck(this, VictoryStack);
59
-
60
- _this = _possibleConstructorReturn(this, (VictoryStack.__proto__ || Object.getPrototypeOf(VictoryStack)).call(this, props));
61
-
62
- if (props.animate) {
63
- _this.state = {
64
- nodesShouldLoad: false,
65
- nodesDoneLoad: false,
66
- animating: true
67
- };
68
- _this.setAnimationState = _victoryCore.Wrapper.setAnimationState.bind(_assertThisInitialized(_this));
69
- }
70
-
71
- return _this;
72
- }
73
-
74
- _createClass(VictoryStack, [{
75
- key: "shouldComponentUpdate",
76
- value: function shouldComponentUpdate(nextProps) {
77
- if (this.props.animate) {
78
- if (!(0, _reactFastCompare.default)(this.props, nextProps)) {
79
- this.setAnimationState(this.props, nextProps);
80
- return false;
81
- }
82
- }
83
-
84
- return true;
85
- }
86
- }, {
87
- key: "getNewChildren",
88
- value: function getNewChildren(props, childComponents, calculatedProps) {
89
- var children = (0, _helperMethods.getChildren)(props, childComponents, calculatedProps);
90
-
91
- var getAnimationProps = _victoryCore.Wrapper.getAnimationProps.bind(this);
92
-
93
- var newChildren = children.map(function (child, index) {
94
- var childProps = (0, _assign2.default)({
95
- animate: getAnimationProps(props, child, index)
96
- }, child.props);
97
- return _react.default.cloneElement(child, childProps);
98
- });
99
- /*
100
- reverse render order for children of `VictoryStack` so that higher children in the stack
101
- are rendered behind lower children. This looks nicer for stacked bars with cornerRadius, and
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
- return _react.default.cloneElement(container, container.props, newChildren);
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
- return VictoryStack;
178
- }(_react.default.Component);
114
+ return groupComponent;
115
+ }, [groupComponent, standalone, containerComponent, containerProps]);
179
116
 
180
- exports.default = VictoryStack;
181
- Object.defineProperty(VictoryStack, "displayName", {
182
- configurable: true,
183
- enumerable: true,
184
- writable: true,
185
- value: "VictoryStack"
186
- });
187
- Object.defineProperty(VictoryStack, "role", {
188
- configurable: true,
189
- enumerable: true,
190
- writable: true,
191
- value: "stack"
192
- });
193
- Object.defineProperty(VictoryStack, "propTypes", {
194
- configurable: true,
195
- enumerable: true,
196
- writable: true,
197
- value: _objectSpread({}, _victoryCore.CommonProps.baseProps, {
198
- bins: _propTypes.default.oneOfType([_propTypes.default.arrayOf(_propTypes.default.oneOfType([_victoryCore.PropTypes.nonNegative, _propTypes.default.instanceOf(Date)])), _victoryCore.PropTypes.nonNegative]),
199
- categories: _propTypes.default.oneOfType([_propTypes.default.arrayOf(_propTypes.default.string), _propTypes.default.shape({
200
- x: _propTypes.default.arrayOf(_propTypes.default.string),
201
- y: _propTypes.default.arrayOf(_propTypes.default.string)
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
- Object.defineProperty(VictoryStack, "expectedComponents", {
230
- configurable: true,
231
- enumerable: true,
232
- writable: true,
233
- value: ["groupComponent", "containerComponent", "labelComponent"]
234
- });
235
- Object.defineProperty(VictoryStack, "getChildren", {
236
- configurable: true,
237
- enumerable: true,
238
- writable: true,
239
- value: _helperMethods.getChildren
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;