victory-stack 30.6.1 → 31.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.
@@ -117,10 +117,7 @@ function getCalculatedProps(props, childComponents) {
117
117
  var horizontal = props.horizontal || childComponents.every(function (component) {
118
118
  return component.props.horizontal;
119
119
  });
120
- var categories = {
121
- x: Wrapper.getCategories(props, "x"),
122
- y: Wrapper.getCategories(props, "y")
123
- };
120
+ var categories = Wrapper.getCategories(props, childComponents);
124
121
  var datasets = stackData(props);
125
122
  var children = childComponents.map(function (c, i) {
126
123
  return React.cloneElement(c, {
@@ -1,3 +1,4 @@
1
+ import _isEmpty from "lodash/isEmpty";
1
2
  import _defaults from "lodash/defaults";
2
3
  import _assign from "lodash/assign";
3
4
 
@@ -22,6 +23,7 @@ import React from "react";
22
23
  import { Helpers, VictoryContainer, VictoryTheme, CommonProps, Wrapper } from "victory-core";
23
24
  import { VictorySharedEvents } from "victory-shared-events";
24
25
  import { getChildren, getCalculatedProps } from "./helper-methods";
26
+ import isEqual from "react-fast-compare";
25
27
  var fallbackProps = {
26
28
  width: 450,
27
29
  height: 300,
@@ -47,27 +49,23 @@ function (_React$Component) {
47
49
  animating: true
48
50
  };
49
51
  _this.setAnimationState = Wrapper.setAnimationState.bind(_assertThisInitialized(_this));
50
- _this.events = Wrapper.getAllEvents(props);
51
52
  }
52
53
 
53
54
  return _this;
54
55
  }
55
56
 
56
57
  _createClass(VictoryStack, [{
57
- key: "componentWillMount",
58
- value: function componentWillMount() {
59
- this.events = Wrapper.getAllEvents(this.props);
60
- }
61
- }, {
62
- key: "componentWillReceiveProps",
63
- value: function componentWillReceiveProps(nextProps) {
58
+ key: "shouldComponentUpdate",
59
+ value: function shouldComponentUpdate(nextProps) {
64
60
  if (this.props.animate) {
65
- this.setAnimationState(this.props, nextProps);
61
+ if (!isEqual(this.props, nextProps)) {
62
+ this.setAnimationState(this.props, nextProps);
63
+ return false;
64
+ }
66
65
  }
67
66
 
68
- this.events = Wrapper.getAllEvents(nextProps);
69
- } // the old ones were bad
70
-
67
+ return true;
68
+ }
71
69
  }, {
72
70
  key: "getNewChildren",
73
71
  value: function getNewChildren(props, childComponents, calculatedProps) {
@@ -132,12 +130,13 @@ function (_React$Component) {
132
130
  var newChildren = this.getNewChildren(modifiedProps, childComponents, calculatedProps);
133
131
  var containerProps = standalone ? this.getContainerProps(modifiedProps, calculatedProps) : {};
134
132
  var container = standalone ? this.renderContainer(containerComponent, containerProps) : groupComponent;
133
+ var events = Wrapper.getAllEvents(props);
135
134
 
136
- if (this.events) {
135
+ if (!_isEmpty(events)) {
137
136
  return React.createElement(VictorySharedEvents, {
138
137
  container: container,
139
138
  eventKey: eventKey,
140
- events: this.events,
139
+ events: events,
141
140
  externalEventMutations: externalEventMutations
142
141
  }, newChildren);
143
142
  }
@@ -132,10 +132,9 @@ function getCalculatedProps(props, childComponents) {
132
132
  var horizontal = props.horizontal || childComponents.every(function (component) {
133
133
  return component.props.horizontal;
134
134
  });
135
- var categories = {
136
- x: _victoryCore.Wrapper.getCategories(props, "x"),
137
- y: _victoryCore.Wrapper.getCategories(props, "y")
138
- };
135
+
136
+ var categories = _victoryCore.Wrapper.getCategories(props, childComponents);
137
+
139
138
  var datasets = stackData(props);
140
139
  var children = childComponents.map(function (c, i) {
141
140
  return _react.default.cloneElement(c, {
@@ -5,6 +5,8 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.default = void 0;
7
7
 
8
+ var _isEmpty2 = _interopRequireDefault(require("lodash/isEmpty"));
9
+
8
10
  var _defaults2 = _interopRequireDefault(require("lodash/defaults"));
9
11
 
10
12
  var _assign2 = _interopRequireDefault(require("lodash/assign"));
@@ -19,6 +21,8 @@ var _victorySharedEvents = require("victory-shared-events");
19
21
 
20
22
  var _helperMethods = require("./helper-methods");
21
23
 
24
+ var _reactFastCompare = _interopRequireDefault(require("react-fast-compare"));
25
+
22
26
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
23
27
 
24
28
  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; }
@@ -62,27 +66,23 @@ function (_React$Component) {
62
66
  animating: true
63
67
  };
64
68
  _this.setAnimationState = _victoryCore.Wrapper.setAnimationState.bind(_assertThisInitialized(_this));
65
- _this.events = _victoryCore.Wrapper.getAllEvents(props);
66
69
  }
67
70
 
68
71
  return _this;
69
72
  }
70
73
 
71
74
  _createClass(VictoryStack, [{
72
- key: "componentWillMount",
73
- value: function componentWillMount() {
74
- this.events = _victoryCore.Wrapper.getAllEvents(this.props);
75
- }
76
- }, {
77
- key: "componentWillReceiveProps",
78
- value: function componentWillReceiveProps(nextProps) {
75
+ key: "shouldComponentUpdate",
76
+ value: function shouldComponentUpdate(nextProps) {
79
77
  if (this.props.animate) {
80
- this.setAnimationState(this.props, nextProps);
78
+ if (!(0, _reactFastCompare.default)(this.props, nextProps)) {
79
+ this.setAnimationState(this.props, nextProps);
80
+ return false;
81
+ }
81
82
  }
82
83
 
83
- this.events = _victoryCore.Wrapper.getAllEvents(nextProps);
84
- } // the old ones were bad
85
-
84
+ return true;
85
+ }
86
86
  }, {
87
87
  key: "getNewChildren",
88
88
  value: function getNewChildren(props, childComponents, calculatedProps) {
@@ -152,11 +152,13 @@ function (_React$Component) {
152
152
  var containerProps = standalone ? this.getContainerProps(modifiedProps, calculatedProps) : {};
153
153
  var container = standalone ? this.renderContainer(containerComponent, containerProps) : groupComponent;
154
154
 
155
- if (this.events) {
155
+ var events = _victoryCore.Wrapper.getAllEvents(props);
156
+
157
+ if (!(0, _isEmpty2.default)(events)) {
156
158
  return _react.default.createElement(_victorySharedEvents.VictorySharedEvents, {
157
159
  container: container,
158
160
  eventKey: eventKey,
159
- events: this.events,
161
+ events: events,
160
162
  externalEventMutations: externalEventMutations
161
163
  }, newChildren);
162
164
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "victory-stack",
3
- "version": "30.6.1",
3
+ "version": "31.2.0",
4
4
  "description": "Stack Layout Component for Victory",
5
5
  "keywords": [
6
6
  "data visualization",
@@ -21,7 +21,8 @@
21
21
  "dependencies": {
22
22
  "lodash": "^4.17.5",
23
23
  "prop-types": "^15.5.8",
24
- "victory-core": "^30.6.1"
24
+ "react-fast-compare": "^2.0.0",
25
+ "victory-core": "^31.2.0"
25
26
  },
26
27
  "scripts": {
27
28
  "version": "nps build-libs && nps build-dists"
@@ -57,17 +57,22 @@ function getY0(datum, index, datasets) {
57
57
  const y = datum._y;
58
58
  const previousDatasets = datasets.slice(0, index);
59
59
  const previousPoints = previousDatasets.reduce((prev, dataset) => {
60
- return prev.concat(dataset
61
- .filter((previousDatum) => datum._x instanceof Date
62
- ? previousDatum._x.getTime() === datum._x.getTime()
63
- : previousDatum._x === datum._x)
64
- .map((previousDatum) => previousDatum._y || 0)
60
+ return prev.concat(
61
+ dataset
62
+ .filter((previousDatum) =>
63
+ datum._x instanceof Date
64
+ ? previousDatum._x.getTime() === datum._x.getTime()
65
+ : previousDatum._x === datum._x
66
+ )
67
+ .map((previousDatum) => previousDatum._y || 0)
65
68
  );
66
69
  }, []);
67
- const y0 = previousPoints.length && previousPoints.reduce((memo, value) => {
68
- const sameSign = (y < 0 && value < 0) || (y >= 0 && value >= 0);
69
- return sameSign ? +value + memo : memo;
70
- }, 0);
70
+ const y0 =
71
+ previousPoints.length &&
72
+ previousPoints.reduce((memo, value) => {
73
+ const sameSign = (y < 0 && value < 0) || (y >= 0 && value >= 0);
74
+ return sameSign ? +value + memo : memo;
75
+ }, 0);
71
76
  return previousPoints.some((point) => point instanceof Date) ? new Date(y0) : y0;
72
77
  }
73
78
 
@@ -77,15 +82,19 @@ function addLayoutData(props, datasets, index) {
77
82
  return datasets[index].map((datum) => {
78
83
  const yOffset = getY0(datum, index, datasets) || 0;
79
84
  return assign({}, datum, {
80
- _y0: !(datum._y instanceof Date) ? yOffset : (
81
- yOffset ? new Date(yOffset) : datum._y
82
- ),
83
- _y1: datum._y === null ? null : (
84
- datum._y instanceof Date ? new Date(+datum._y + +yOffset) : datum._y + yOffset
85
- ),
86
- _x1: datum._x === null ? null : (
87
- datum._x instanceof Date ? new Date(+datum._x + +xOffset) : datum._x + xOffset
88
- )
85
+ _y0: !(datum._y instanceof Date) ? yOffset : yOffset ? new Date(yOffset) : datum._y,
86
+ _y1:
87
+ datum._y === null
88
+ ? null
89
+ : datum._y instanceof Date
90
+ ? new Date(+datum._y + +yOffset)
91
+ : datum._y + yOffset,
92
+ _x1:
93
+ datum._x === null
94
+ ? null
95
+ : datum._x instanceof Date
96
+ ? new Date(+datum._x + +xOffset)
97
+ : datum._x + xOffset
89
98
  });
90
99
  });
91
100
  }
@@ -101,13 +110,9 @@ function getCalculatedProps(props, childComponents) {
101
110
  childComponents = childComponents || React.Children.toArray(props.children);
102
111
  const role = "stack";
103
112
  const style = Wrapper.getStyle(props.theme, props.style, role);
104
- const horizontal = props.horizontal || childComponents.every(
105
- (component) => component.props.horizontal
106
- );
107
- const categories = {
108
- x: Wrapper.getCategories(props, "x"),
109
- y: Wrapper.getCategories(props, "y")
110
- };
113
+ const horizontal =
114
+ props.horizontal || childComponents.every((component) => component.props.horizontal);
115
+ const categories = Wrapper.getCategories(props, childComponents);
111
116
  const datasets = stackData(props);
112
117
  const children = childComponents.map((c, i) => {
113
118
  return React.cloneElement(c, { data: datasets[i] });
@@ -163,8 +168,7 @@ function getColorScale(props, child) {
163
168
  if (role !== "group" && role !== "stack") {
164
169
  return undefined;
165
170
  }
166
- return props.theme ? colorScaleOptions || props.theme.props.colorScale
167
- : colorScaleOptions;
171
+ return props.theme ? colorScaleOptions || props.theme.props.colorScale : colorScaleOptions;
168
172
  }
169
173
 
170
174
  function getChildren(props, childComponents, calculatedProps) {
@@ -180,20 +184,25 @@ function getChildren(props, childComponents, calculatedProps) {
180
184
  const style = Wrapper.getChildStyle(child, index, calculatedProps);
181
185
  const labels = props.labels ? getLabels(props, datasets, index) : child.props.labels;
182
186
  const name = child.props.name || `${parentName}-${role}-${index}`;
183
- return React.cloneElement(child, assign({
184
- key: `${name}-key-${index}`,
185
- labels,
186
- name,
187
- domainPadding: child.props.domainPadding || props.domainPadding,
188
- theme: props.theme,
189
- labelComponent: props.labelComponent || child.props.labelComponent,
190
- style,
191
- colorScale: getColorScale(props, child),
192
- data,
193
- polar: props.polar
194
- }, childProps));
187
+ return React.cloneElement(
188
+ child,
189
+ assign(
190
+ {
191
+ key: `${name}-key-${index}`,
192
+ labels,
193
+ name,
194
+ domainPadding: child.props.domainPadding || props.domainPadding,
195
+ theme: props.theme,
196
+ labelComponent: props.labelComponent || child.props.labelComponent,
197
+ style,
198
+ colorScale: getColorScale(props, child),
199
+ data,
200
+ polar: props.polar
201
+ },
202
+ childProps
203
+ )
204
+ );
195
205
  });
196
206
  }
197
207
 
198
-
199
208
  export { getChildren, getCalculatedProps };
@@ -1,9 +1,10 @@
1
- import { assign, defaults } from "lodash";
1
+ import { assign, defaults, isEmpty } from "lodash";
2
2
  import PropTypes from "prop-types";
3
3
  import React from "react";
4
4
  import { Helpers, VictoryContainer, VictoryTheme, CommonProps, Wrapper } from "victory-core";
5
5
  import { VictorySharedEvents } from "victory-shared-events";
6
6
  import { getChildren, getCalculatedProps } from "./helper-methods";
7
+ import isEqual from "react-fast-compare";
7
8
 
8
9
  const fallbackProps = {
9
10
  width: 450,
@@ -21,40 +22,46 @@ export default class VictoryStack extends React.Component {
21
22
  categories: PropTypes.oneOfType([
22
23
  PropTypes.arrayOf(PropTypes.string),
23
24
  PropTypes.shape({
24
- x: PropTypes.arrayOf(PropTypes.string), y: PropTypes.arrayOf(PropTypes.string)
25
+ x: PropTypes.arrayOf(PropTypes.string),
26
+ y: PropTypes.arrayOf(PropTypes.string)
25
27
  })
26
28
  ]),
27
- children: PropTypes.oneOfType([
28
- PropTypes.arrayOf(PropTypes.node), PropTypes.node
29
- ]),
29
+ children: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.node), PropTypes.node]),
30
30
  colorScale: PropTypes.oneOfType([
31
31
  PropTypes.arrayOf(PropTypes.string),
32
32
  PropTypes.oneOf([
33
- "grayscale", "qualitative", "heatmap", "warm", "cool", "red", "green", "blue"
33
+ "grayscale",
34
+ "qualitative",
35
+ "heatmap",
36
+ "warm",
37
+ "cool",
38
+ "red",
39
+ "green",
40
+ "blue"
34
41
  ])
35
42
  ]),
36
43
  fillInMissingData: PropTypes.bool,
37
44
  horizontal: PropTypes.bool,
38
45
  labelComponent: PropTypes.element,
39
- labels: PropTypes.oneOfType([ PropTypes.func, PropTypes.array ]),
46
+ labels: PropTypes.oneOfType([PropTypes.func, PropTypes.array]),
40
47
  style: PropTypes.shape({
41
- parent: PropTypes.object, data: PropTypes.object, labels: PropTypes.object
48
+ parent: PropTypes.object,
49
+ data: PropTypes.object,
50
+ labels: PropTypes.object
42
51
  }),
43
52
  xOffset: PropTypes.number
44
53
  };
45
54
 
46
55
  static defaultProps = {
47
- containerComponent: <VictoryContainer/>,
48
- groupComponent: <g/>,
56
+ containerComponent: <VictoryContainer />,
57
+ groupComponent: <g />,
49
58
  scale: "linear",
50
59
  standalone: true,
51
- theme: VictoryTheme. grayscale,
60
+ theme: VictoryTheme.grayscale,
52
61
  fillInMissingData: true
53
62
  };
54
63
 
55
- static expectedComponents = [
56
- "groupComponent", "containerComponent", "labelComponent"
57
- ];
64
+ static expectedComponents = ["groupComponent", "containerComponent", "labelComponent"];
58
65
 
59
66
  static getChildren = getChildren;
60
67
 
@@ -67,22 +74,19 @@ export default class VictoryStack extends React.Component {
67
74
  animating: true
68
75
  };
69
76
  this.setAnimationState = Wrapper.setAnimationState.bind(this);
70
- this.events = Wrapper.getAllEvents(props);
71
77
  }
72
78
  }
73
79
 
74
- componentWillMount() {
75
- this.events = Wrapper.getAllEvents(this.props);
76
- }
77
-
78
- componentWillReceiveProps(nextProps) {
80
+ shouldComponentUpdate(nextProps) {
79
81
  if (this.props.animate) {
80
- this.setAnimationState(this.props, nextProps);
82
+ if (!isEqual(this.props, nextProps)) {
83
+ this.setAnimationState(this.props, nextProps);
84
+ return false;
85
+ }
81
86
  }
82
- this.events = Wrapper.getAllEvents(nextProps);
87
+ return true;
83
88
  }
84
89
 
85
- // the old ones were bad
86
90
  getNewChildren(props, childComponents, calculatedProps) {
87
91
  const children = getChildren(props, childComponents, calculatedProps);
88
92
  const getAnimationProps = Wrapper.getAnimationProps.bind(this);
@@ -101,31 +105,46 @@ export default class VictoryStack extends React.Component {
101
105
  const { width, height, standalone, theme, polar, horizontal, name } = props;
102
106
  const { domain, scale, style, origin } = calculatedProps;
103
107
  return {
104
- domain, scale, width, height, standalone, theme, style: style.parent, horizontal,
105
- polar, origin, name
108
+ domain,
109
+ scale,
110
+ width,
111
+ height,
112
+ standalone,
113
+ theme,
114
+ style: style.parent,
115
+ horizontal,
116
+ polar,
117
+ origin,
118
+ name
106
119
  };
107
120
  }
108
121
 
109
122
  render() {
110
123
  const { role } = this.constructor;
111
- const props = this.state && this.state.nodesWillExit ?
112
- this.state.oldProps || this.props : this.props;
124
+ const props =
125
+ this.state && this.state.nodesWillExit ? this.state.oldProps || this.props : this.props;
113
126
  const modifiedProps = Helpers.modifyProps(props, fallbackProps, role);
114
127
  const {
115
- eventKey, containerComponent, standalone, groupComponent, externalEventMutations
128
+ eventKey,
129
+ containerComponent,
130
+ standalone,
131
+ groupComponent,
132
+ externalEventMutations
116
133
  } = modifiedProps;
117
134
  const childComponents = React.Children.toArray(modifiedProps.children);
118
135
  const calculatedProps = getCalculatedProps(modifiedProps, childComponents);
119
136
  const newChildren = this.getNewChildren(modifiedProps, childComponents, calculatedProps);
120
137
  const containerProps = standalone ? this.getContainerProps(modifiedProps, calculatedProps) : {};
121
- const container = standalone ?
122
- this.renderContainer(containerComponent, containerProps) : groupComponent;
123
- if (this.events) {
138
+ const container = standalone
139
+ ? this.renderContainer(containerComponent, containerProps)
140
+ : groupComponent;
141
+ const events = Wrapper.getAllEvents(props);
142
+ if (!isEmpty(events)) {
124
143
  return (
125
144
  <VictorySharedEvents
126
145
  container={container}
127
146
  eventKey={eventKey}
128
- events={this.events}
147
+ events={events}
129
148
  externalEventMutations={externalEventMutations}
130
149
  >
131
150
  {newChildren}