victory-chart 35.11.4 → 36.2.1

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "victory-chart",
3
- "version": "35.11.4",
3
+ "version": "36.2.1",
4
4
  "description": "Chart Component for Victory",
5
5
  "keywords": [
6
6
  "data visualization",
@@ -22,10 +22,10 @@
22
22
  "lodash": "^4.17.19",
23
23
  "prop-types": "^15.5.8",
24
24
  "react-fast-compare": "^2.0.0",
25
- "victory-axis": "^35.11.4",
26
- "victory-core": "^35.11.4",
27
- "victory-polar-axis": "^35.11.4",
28
- "victory-shared-events": "^35.11.4"
25
+ "victory-axis": "^36.2.1",
26
+ "victory-core": "^36.2.1",
27
+ "victory-polar-axis": "^36.2.1",
28
+ "victory-shared-events": "^36.2.1"
29
29
  },
30
30
  "peerDependencies": {
31
31
  "react": "^16.6.0 || ^17.0.0"
@@ -33,6 +33,5 @@
33
33
  "scripts": {
34
34
  "version": "yarn run nps build-libs && nps build-dists"
35
35
  },
36
- "sideEffects": false,
37
- "gitHead": "59ec44a7be4b1aea88df1a6769ed16f0a60689df"
36
+ "sideEffects": false
38
37
  }
@@ -8,7 +8,8 @@ import {
8
8
  VictoryTheme,
9
9
  CommonProps,
10
10
  PropTypes as CustomPropTypes,
11
- Wrapper
11
+ Wrapper,
12
+ Hooks
12
13
  } from "victory-core";
13
14
  import { VictorySharedEvents } from "victory-shared-events";
14
15
  import { VictoryAxis } from "victory-axis";
@@ -27,78 +28,47 @@ const fallbackProps = {
27
28
  padding: 50
28
29
  };
29
30
 
30
- export default class VictoryChart extends React.Component {
31
- static displayName = "VictoryChart";
32
-
33
- static propTypes = {
34
- ...CommonProps.baseProps,
35
- backgroundComponent: PropTypes.element,
36
- children: PropTypes.oneOfType([
37
- PropTypes.arrayOf(PropTypes.node),
38
- PropTypes.node
39
- ]),
40
- defaultAxes: PropTypes.shape({
41
- independent: PropTypes.element,
42
- dependent: PropTypes.element
43
- }),
44
- defaultPolarAxes: PropTypes.shape({
45
- independent: PropTypes.element,
46
- dependent: PropTypes.element
47
- }),
48
- endAngle: PropTypes.number,
49
- innerRadius: CustomPropTypes.nonNegative,
50
- prependDefaultAxes: PropTypes.bool,
51
- startAngle: PropTypes.number
52
- };
53
-
54
- static defaultProps = {
55
- backgroundComponent: <Background />,
56
- containerComponent: <VictoryContainer />,
57
- defaultAxes: {
58
- independent: <VictoryAxis />,
59
- dependent: <VictoryAxis dependentAxis />
60
- },
61
- defaultPolarAxes: {
62
- independent: <VictoryPolarAxis />,
63
- dependent: <VictoryPolarAxis dependentAxis />
64
- },
65
- groupComponent: <g />,
66
- standalone: true,
67
- theme: VictoryTheme.grayscale
68
- };
69
-
70
- static expectedComponents = ["groupComponent", "containerComponent"];
71
-
72
- constructor(props) {
73
- super(props);
74
- this.state = {};
75
- if (props.animate) {
76
- this.state = {
77
- nodesShouldLoad: false,
78
- nodesDoneLoad: false,
79
- animating: true
80
- };
81
- this.setAnimationState = Wrapper.setAnimationState.bind(this);
82
- }
83
- }
84
-
85
- shouldComponentUpdate(nextProps) {
86
- if (this.props.animate) {
87
- if (!isEqual(this.props, nextProps)) {
88
- this.setAnimationState(this.props, nextProps);
89
- return false;
90
- }
91
- }
92
- return true;
93
- }
94
-
95
- getNewChildren(props, childComponents, calculatedProps) {
31
+ const VictoryChart = (initialProps) => {
32
+ const role = "chart";
33
+ const { getAnimationProps, setAnimationState, getProps } =
34
+ Hooks.useAnimationState();
35
+ const props = getProps(initialProps);
36
+
37
+ const modifiedProps = Helpers.modifyProps(props, fallbackProps, role);
38
+ const {
39
+ eventKey,
40
+ containerComponent,
41
+ standalone,
42
+ groupComponent,
43
+ externalEventMutations,
44
+ width,
45
+ height,
46
+ theme,
47
+ polar,
48
+ name
49
+ } = modifiedProps;
50
+
51
+ const axes = props.polar
52
+ ? modifiedProps.defaultPolarAxes
53
+ : modifiedProps.defaultAxes;
54
+
55
+ const childComponents = React.useMemo(
56
+ () => getChildComponents(modifiedProps, axes),
57
+ [modifiedProps, axes]
58
+ );
59
+
60
+ const calculatedProps = React.useMemo(
61
+ () => getCalculatedProps(modifiedProps, childComponents),
62
+ [modifiedProps, childComponents]
63
+ );
64
+ const { domain, scale, style, origin, radius, horizontal } = calculatedProps;
65
+
66
+ const newChildren = React.useMemo(() => {
96
67
  const children = getChildren(props, childComponents, calculatedProps);
97
- const getAnimationProps = Wrapper.getAnimationProps.bind(this);
98
68
 
99
- const newChildren = children.map((child, index) => {
69
+ const mappedChildren = children.map((child, index) => {
100
70
  const childProps = assign(
101
- { animate: getAnimationProps(props, child, index) },
71
+ { animate: getAnimationProps(props, child, index, "victory chart") },
102
72
  child.props
103
73
  );
104
74
  return React.cloneElement(child, childProps);
@@ -110,80 +80,127 @@ export default class VictoryChart extends React.Component {
110
80
  calculatedProps
111
81
  );
112
82
 
113
- newChildren.unshift(backgroundComponent);
83
+ mappedChildren.unshift(backgroundComponent);
114
84
  }
115
85
 
116
- return newChildren;
117
- }
86
+ return mappedChildren;
87
+ }, [getAnimationProps, childComponents, props, calculatedProps]);
88
+
89
+ const containerProps = React.useMemo(() => {
90
+ if (standalone) {
91
+ return {
92
+ domain,
93
+ scale,
94
+ width,
95
+ height,
96
+ standalone,
97
+ theme,
98
+ style: style.parent,
99
+ horizontal,
100
+ name,
101
+ polar,
102
+ radius,
103
+ origin: polar ? origin : undefined
104
+ };
105
+ }
106
+ return {};
107
+ }, [
108
+ domain,
109
+ scale,
110
+ width,
111
+ height,
112
+ standalone,
113
+ theme,
114
+ style,
115
+ horizontal,
116
+ name,
117
+ polar,
118
+ radius,
119
+ origin
120
+ ]);
121
+
122
+ const container = React.useMemo(() => {
123
+ if (standalone) {
124
+ const defaultContainerProps = defaults(
125
+ {},
126
+ containerComponent.props,
127
+ containerProps
128
+ );
129
+ return React.cloneElement(containerComponent, defaultContainerProps);
130
+ }
131
+ return groupComponent;
132
+ }, [groupComponent, standalone, containerComponent, containerProps]);
118
133
 
119
- renderContainer(containerComponent, props) {
120
- const containerProps = defaults({}, containerComponent.props, props);
121
- return React.cloneElement(containerComponent, containerProps);
122
- }
134
+ const events = React.useMemo(() => {
135
+ return Wrapper.getAllEvents(props);
136
+ }, [props]);
123
137
 
124
- getContainerProps(props, calculatedProps) {
125
- const { width, height, standalone, theme, polar, name } = props;
126
- const { domain, scale, style, origin, radius, horizontal } =
127
- calculatedProps;
128
- return {
129
- domain,
130
- scale,
131
- width,
132
- height,
133
- standalone,
134
- theme,
135
- style: style.parent,
136
- horizontal,
137
- name,
138
- polar,
139
- radius,
140
- origin: polar ? origin : undefined
141
- };
142
- }
138
+ const previousProps = Hooks.usePreviousProps(initialProps);
143
139
 
144
- render() {
145
- const props =
146
- this.state && this.state.nodesWillExit
147
- ? this.state.oldProps || this.props
148
- : this.props;
149
- const modifiedProps = Helpers.modifyProps(props, fallbackProps, "chart");
150
- const {
151
- eventKey,
152
- containerComponent,
153
- groupComponent,
154
- standalone,
155
- externalEventMutations
156
- } = modifiedProps;
157
- const axes = props.polar
158
- ? modifiedProps.defaultPolarAxes
159
- : modifiedProps.defaultAxes;
160
- const childComponents = getChildComponents(modifiedProps, axes);
161
- const calculatedProps = getCalculatedProps(modifiedProps, childComponents);
162
- const newChildren = this.getNewChildren(
163
- modifiedProps,
164
- childComponents,
165
- calculatedProps
140
+ React.useEffect(() => {
141
+ // This is called before dismount to keep state in sync
142
+ return () => {
143
+ if (initialProps.animate) {
144
+ setAnimationState(previousProps, initialProps);
145
+ }
146
+ };
147
+ }, [setAnimationState, previousProps, initialProps]);
148
+
149
+ if (!isEmpty(events)) {
150
+ return (
151
+ <VictorySharedEvents
152
+ container={container}
153
+ eventKey={eventKey}
154
+ events={events}
155
+ externalEventMutations={externalEventMutations}
156
+ >
157
+ {newChildren}
158
+ </VictorySharedEvents>
166
159
  );
167
- const containerProps = standalone
168
- ? this.getContainerProps(modifiedProps, calculatedProps)
169
- : {};
170
- const container = standalone
171
- ? this.renderContainer(containerComponent, containerProps)
172
- : groupComponent;
173
- const events = Wrapper.getAllEvents(props);
174
-
175
- if (!isEmpty(events)) {
176
- return (
177
- <VictorySharedEvents
178
- container={container}
179
- eventKey={eventKey}
180
- events={events}
181
- externalEventMutations={externalEventMutations}
182
- >
183
- {newChildren}
184
- </VictorySharedEvents>
185
- );
186
- }
187
- return React.cloneElement(container, container.props, newChildren);
188
160
  }
189
- }
161
+ return React.cloneElement(container, container.props, newChildren);
162
+ };
163
+
164
+ VictoryChart.propTypes = {
165
+ ...CommonProps.baseProps,
166
+ backgroundComponent: PropTypes.element,
167
+ children: PropTypes.oneOfType([
168
+ PropTypes.arrayOf(PropTypes.node),
169
+ PropTypes.node
170
+ ]),
171
+ defaultAxes: PropTypes.shape({
172
+ independent: PropTypes.element,
173
+ dependent: PropTypes.element
174
+ }),
175
+ defaultPolarAxes: PropTypes.shape({
176
+ independent: PropTypes.element,
177
+ dependent: PropTypes.element
178
+ }),
179
+ endAngle: PropTypes.number,
180
+ innerRadius: CustomPropTypes.nonNegative,
181
+ prependDefaultAxes: PropTypes.bool,
182
+ startAngle: PropTypes.number
183
+ };
184
+
185
+ VictoryChart.defaultProps = {
186
+ backgroundComponent: <Background />,
187
+ containerComponent: <VictoryContainer />,
188
+ defaultAxes: {
189
+ independent: <VictoryAxis />,
190
+ dependent: <VictoryAxis dependentAxis />
191
+ },
192
+ defaultPolarAxes: {
193
+ independent: <VictoryPolarAxis />,
194
+ dependent: <VictoryPolarAxis dependentAxis />
195
+ },
196
+ groupComponent: <g />,
197
+ standalone: true,
198
+ theme: VictoryTheme.grayscale
199
+ };
200
+
201
+ const VictoryChartMemo = React.memo(VictoryChart, isEqual);
202
+
203
+ VictoryChartMemo.displayName = "VictoryChart";
204
+ VictoryChartMemo.expectedComponents = ["groupComponent", "containerComponent"];
205
+
206
+ export default VictoryChartMemo;
package/LICENSE.txt DELETED
@@ -1,30 +0,0 @@
1
- The MIT License (MIT)
2
-
3
- Copyright (c) 2015-2020 Formidable Labs.
4
-
5
- Copyright (c) 2016-2020 Alexey Svetliakov <https://github.com/asvetliakov>,
6
- snerks <https://github.com/snerks>, Krzysztof Cebula <https://github.com
7
- Havret>, Vitaliy Polyanskiy <https://github.com/alreadyExisted>, James Lismore
8
- <https://github.com/jlismore>, Stack Builders <https://github.com
9
- stackbuilders>, Esteban Ibarra <https://github.com/ibarrae>, Dominic Lee
10
- <https://github.com/dominictwlee>, Dave Vedder <https://github.com
11
- veddermatic>, Alec Flett <https://github.com/alecf> and potentially other
12
- DefinitelyTyped contributors.
13
-
14
- Permission is hereby granted, free of charge, to any person obtaining a copy
15
- of this software and associated documentation files (the "Software"), to deal
16
- in the Software without restriction, including without limitation the rights
17
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
18
- copies of the Software, and to permit persons to whom the Software is
19
- furnished to do so, subject to the following conditions:
20
-
21
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
24
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
26
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
27
- SOFTWARE.
28
-
29
- The above copyright notice and this permission notice shall be included in all
30
- copies or substantial portions of the Software.