victory-chart 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.
- package/LICENSE.txt +30 -0
- package/dist/victory-chart.js +1051 -1038
- package/dist/victory-chart.min.js +1 -1
- package/es/victory-chart.js +121 -176
- package/lib/victory-chart.js +131 -177
- package/package.json +8 -7
- package/src/victory-chart.js +158 -140
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "victory-chart",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "36.1.0",
|
|
4
4
|
"description": "Chart Component for Victory",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"data visualization",
|
|
@@ -22,16 +22,17 @@
|
|
|
22
22
|
"lodash": "^4.17.19",
|
|
23
23
|
"prop-types": "^15.5.8",
|
|
24
24
|
"react-fast-compare": "^2.0.0",
|
|
25
|
-
"victory-axis": "^
|
|
26
|
-
"victory-core": "^
|
|
27
|
-
"victory-polar-axis": "^
|
|
28
|
-
"victory-shared-events": "^
|
|
25
|
+
"victory-axis": "^36.1.0",
|
|
26
|
+
"victory-core": "^36.1.0",
|
|
27
|
+
"victory-polar-axis": "^36.1.0",
|
|
28
|
+
"victory-shared-events": "^36.1.0"
|
|
29
29
|
},
|
|
30
30
|
"peerDependencies": {
|
|
31
31
|
"react": "^16.6.0 || ^17.0.0"
|
|
32
32
|
},
|
|
33
33
|
"scripts": {
|
|
34
|
-
"version": "nps build-libs && nps build-dists"
|
|
34
|
+
"version": "yarn run nps build-libs && nps build-dists"
|
|
35
35
|
},
|
|
36
|
-
"sideEffects": false
|
|
36
|
+
"sideEffects": false,
|
|
37
|
+
"gitHead": "038cd9b70d9ce54ac6b861014165583760734c99"
|
|
37
38
|
}
|
package/src/victory-chart.js
CHANGED
|
@@ -8,7 +8,9 @@ import {
|
|
|
8
8
|
VictoryTheme,
|
|
9
9
|
CommonProps,
|
|
10
10
|
PropTypes as CustomPropTypes,
|
|
11
|
-
Wrapper
|
|
11
|
+
Wrapper,
|
|
12
|
+
usePreviousProps,
|
|
13
|
+
useAnimationState
|
|
12
14
|
} from "victory-core";
|
|
13
15
|
import { VictorySharedEvents } from "victory-shared-events";
|
|
14
16
|
import { VictoryAxis } from "victory-axis";
|
|
@@ -27,78 +29,47 @@ const fallbackProps = {
|
|
|
27
29
|
padding: 50
|
|
28
30
|
};
|
|
29
31
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
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) {
|
|
32
|
+
const VictoryChart = (initialProps) => {
|
|
33
|
+
const role = "chart";
|
|
34
|
+
const { getAnimationProps, setAnimationState, getProps } =
|
|
35
|
+
useAnimationState();
|
|
36
|
+
const props = getProps(initialProps);
|
|
37
|
+
|
|
38
|
+
const modifiedProps = Helpers.modifyProps(props, fallbackProps, role);
|
|
39
|
+
const {
|
|
40
|
+
eventKey,
|
|
41
|
+
containerComponent,
|
|
42
|
+
standalone,
|
|
43
|
+
groupComponent,
|
|
44
|
+
externalEventMutations,
|
|
45
|
+
width,
|
|
46
|
+
height,
|
|
47
|
+
theme,
|
|
48
|
+
polar,
|
|
49
|
+
name
|
|
50
|
+
} = modifiedProps;
|
|
51
|
+
|
|
52
|
+
const axes = props.polar
|
|
53
|
+
? modifiedProps.defaultPolarAxes
|
|
54
|
+
: modifiedProps.defaultAxes;
|
|
55
|
+
|
|
56
|
+
const childComponents = React.useMemo(
|
|
57
|
+
() => getChildComponents(modifiedProps, axes),
|
|
58
|
+
[modifiedProps, axes]
|
|
59
|
+
);
|
|
60
|
+
|
|
61
|
+
const calculatedProps = React.useMemo(
|
|
62
|
+
() => getCalculatedProps(modifiedProps, childComponents),
|
|
63
|
+
[modifiedProps, childComponents]
|
|
64
|
+
);
|
|
65
|
+
const { domain, scale, style, origin, radius, horizontal } = calculatedProps;
|
|
66
|
+
|
|
67
|
+
const newChildren = React.useMemo(() => {
|
|
96
68
|
const children = getChildren(props, childComponents, calculatedProps);
|
|
97
|
-
const getAnimationProps = Wrapper.getAnimationProps.bind(this);
|
|
98
69
|
|
|
99
|
-
const
|
|
70
|
+
const mappedChildren = children.map((child, index) => {
|
|
100
71
|
const childProps = assign(
|
|
101
|
-
{ animate: getAnimationProps(props, child, index) },
|
|
72
|
+
{ animate: getAnimationProps(props, child, index, "victory chart") },
|
|
102
73
|
child.props
|
|
103
74
|
);
|
|
104
75
|
return React.cloneElement(child, childProps);
|
|
@@ -110,80 +81,127 @@ export default class VictoryChart extends React.Component {
|
|
|
110
81
|
calculatedProps
|
|
111
82
|
);
|
|
112
83
|
|
|
113
|
-
|
|
84
|
+
mappedChildren.unshift(backgroundComponent);
|
|
114
85
|
}
|
|
115
86
|
|
|
116
|
-
return
|
|
117
|
-
}
|
|
87
|
+
return mappedChildren;
|
|
88
|
+
}, [getAnimationProps, childComponents, props, calculatedProps]);
|
|
89
|
+
|
|
90
|
+
const containerProps = React.useMemo(() => {
|
|
91
|
+
if (standalone) {
|
|
92
|
+
return {
|
|
93
|
+
domain,
|
|
94
|
+
scale,
|
|
95
|
+
width,
|
|
96
|
+
height,
|
|
97
|
+
standalone,
|
|
98
|
+
theme,
|
|
99
|
+
style: style.parent,
|
|
100
|
+
horizontal,
|
|
101
|
+
name,
|
|
102
|
+
polar,
|
|
103
|
+
radius,
|
|
104
|
+
origin: polar ? origin : undefined
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
return {};
|
|
108
|
+
}, [
|
|
109
|
+
domain,
|
|
110
|
+
scale,
|
|
111
|
+
width,
|
|
112
|
+
height,
|
|
113
|
+
standalone,
|
|
114
|
+
theme,
|
|
115
|
+
style,
|
|
116
|
+
horizontal,
|
|
117
|
+
name,
|
|
118
|
+
polar,
|
|
119
|
+
radius,
|
|
120
|
+
origin
|
|
121
|
+
]);
|
|
122
|
+
|
|
123
|
+
const container = React.useMemo(() => {
|
|
124
|
+
if (standalone) {
|
|
125
|
+
const defaultContainerProps = defaults(
|
|
126
|
+
{},
|
|
127
|
+
containerComponent.props,
|
|
128
|
+
containerProps
|
|
129
|
+
);
|
|
130
|
+
return React.cloneElement(containerComponent, defaultContainerProps);
|
|
131
|
+
}
|
|
132
|
+
return groupComponent;
|
|
133
|
+
}, [groupComponent, standalone, containerComponent, containerProps]);
|
|
118
134
|
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
}
|
|
135
|
+
const events = React.useMemo(() => {
|
|
136
|
+
return Wrapper.getAllEvents(props);
|
|
137
|
+
}, [props]);
|
|
123
138
|
|
|
124
|
-
|
|
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
|
-
}
|
|
139
|
+
const previousProps = usePreviousProps(initialProps);
|
|
143
140
|
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
modifiedProps,
|
|
164
|
-
childComponents,
|
|
165
|
-
calculatedProps
|
|
141
|
+
React.useEffect(() => {
|
|
142
|
+
// This is called before dismount to keep state in sync
|
|
143
|
+
return () => {
|
|
144
|
+
if (initialProps.animate) {
|
|
145
|
+
setAnimationState(previousProps, initialProps);
|
|
146
|
+
}
|
|
147
|
+
};
|
|
148
|
+
}, [setAnimationState, previousProps, initialProps]);
|
|
149
|
+
|
|
150
|
+
if (!isEmpty(events)) {
|
|
151
|
+
return (
|
|
152
|
+
<VictorySharedEvents
|
|
153
|
+
container={container}
|
|
154
|
+
eventKey={eventKey}
|
|
155
|
+
events={events}
|
|
156
|
+
externalEventMutations={externalEventMutations}
|
|
157
|
+
>
|
|
158
|
+
{newChildren}
|
|
159
|
+
</VictorySharedEvents>
|
|
166
160
|
);
|
|
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
161
|
}
|
|
189
|
-
|
|
162
|
+
return React.cloneElement(container, container.props, newChildren);
|
|
163
|
+
};
|
|
164
|
+
|
|
165
|
+
VictoryChart.propTypes = {
|
|
166
|
+
...CommonProps.baseProps,
|
|
167
|
+
backgroundComponent: PropTypes.element,
|
|
168
|
+
children: PropTypes.oneOfType([
|
|
169
|
+
PropTypes.arrayOf(PropTypes.node),
|
|
170
|
+
PropTypes.node
|
|
171
|
+
]),
|
|
172
|
+
defaultAxes: PropTypes.shape({
|
|
173
|
+
independent: PropTypes.element,
|
|
174
|
+
dependent: PropTypes.element
|
|
175
|
+
}),
|
|
176
|
+
defaultPolarAxes: PropTypes.shape({
|
|
177
|
+
independent: PropTypes.element,
|
|
178
|
+
dependent: PropTypes.element
|
|
179
|
+
}),
|
|
180
|
+
endAngle: PropTypes.number,
|
|
181
|
+
innerRadius: CustomPropTypes.nonNegative,
|
|
182
|
+
prependDefaultAxes: PropTypes.bool,
|
|
183
|
+
startAngle: PropTypes.number
|
|
184
|
+
};
|
|
185
|
+
|
|
186
|
+
VictoryChart.defaultProps = {
|
|
187
|
+
backgroundComponent: <Background />,
|
|
188
|
+
containerComponent: <VictoryContainer />,
|
|
189
|
+
defaultAxes: {
|
|
190
|
+
independent: <VictoryAxis />,
|
|
191
|
+
dependent: <VictoryAxis dependentAxis />
|
|
192
|
+
},
|
|
193
|
+
defaultPolarAxes: {
|
|
194
|
+
independent: <VictoryPolarAxis />,
|
|
195
|
+
dependent: <VictoryPolarAxis dependentAxis />
|
|
196
|
+
},
|
|
197
|
+
groupComponent: <g />,
|
|
198
|
+
standalone: true,
|
|
199
|
+
theme: VictoryTheme.grayscale
|
|
200
|
+
};
|
|
201
|
+
|
|
202
|
+
const VictoryChartMemo = React.memo(VictoryChart, isEqual);
|
|
203
|
+
|
|
204
|
+
VictoryChartMemo.displayName = "VictoryChart";
|
|
205
|
+
VictoryChartMemo.expectedComponents = ["groupComponent", "containerComponent"];
|
|
206
|
+
|
|
207
|
+
export default VictoryChartMemo;
|