victory-chart 18.2.0 → 19.1.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/CHANGELOG.md +28 -0
- package/README.md +9 -5
- package/dist/victory-chart.js +17058 -24378
- package/dist/victory-chart.min.js +13 -14
- package/lib/components/containers/brush-helpers.js +7 -4
- package/lib/components/containers/create-container.js +40 -32
- package/lib/components/containers/cursor-helpers.js +48 -0
- package/lib/components/containers/victory-brush-container.js +7 -3
- package/lib/components/containers/victory-cursor-container.js +145 -0
- package/lib/components/containers/victory-selection-container.js +5 -2
- package/lib/components/containers/victory-voronoi-container.js +40 -15
- package/lib/components/containers/victory-zoom-container.js +9 -2
- package/lib/components/containers/zoom-helpers.js +7 -2
- package/lib/components/victory-area/helper-methods.js +2 -1
- package/lib/components/victory-area/victory-area.js +9 -105
- package/lib/components/victory-axis/helper-methods.js +5 -2
- package/lib/components/victory-axis/victory-axis.js +11 -53
- package/lib/components/victory-bar/helper-methods.js +3 -1
- package/lib/components/victory-bar/victory-bar.js +8 -114
- package/lib/components/victory-candlestick/helper-methods.js +2 -1
- package/lib/components/victory-candlestick/victory-candlestick.js +10 -111
- package/lib/components/victory-chart/helper-methods.js +4 -3
- package/lib/components/victory-chart/victory-chart.js +12 -67
- package/lib/components/victory-errorbar/helper-methods.js +1 -1
- package/lib/components/victory-errorbar/victory-errorbar.js +8 -113
- package/lib/components/victory-group/victory-group.js +12 -86
- package/lib/components/victory-line/helper-methods.js +2 -1
- package/lib/components/victory-line/victory-line.js +9 -105
- package/lib/components/victory-scatter/helper-methods.js +1 -1
- package/lib/components/victory-scatter/victory-scatter.js +8 -111
- package/lib/components/victory-stack/victory-stack.js +11 -59
- package/lib/components/victory-voronoi/helper-methods.js +1 -1
- package/lib/components/victory-voronoi/victory-voronoi.js +7 -112
- package/lib/helpers/common-props.js +87 -0
- package/lib/helpers/wrapper.js +2 -1
- package/lib/index.js +9 -7
- package/package.json +14 -14
- package/src/components/containers/brush-helpers.js +37 -34
- package/src/components/containers/create-container.js +52 -43
- package/src/components/containers/cursor-helpers.js +49 -0
- package/src/components/containers/selection-helpers.js +13 -13
- package/src/components/containers/victory-brush-container.js +33 -29
- package/src/components/containers/victory-cursor-container.js +145 -0
- package/src/components/containers/victory-selection-container.js +14 -11
- package/src/components/containers/victory-voronoi-container.js +50 -25
- package/src/components/containers/victory-zoom-container.js +17 -10
- package/src/components/containers/voronoi-helpers.js +9 -9
- package/src/components/containers/zoom-helpers.js +18 -13
- package/src/components/victory-area/helper-methods.js +7 -6
- package/src/components/victory-area/victory-area.js +14 -110
- package/src/components/victory-axis/helper-methods.js +22 -19
- package/src/components/victory-axis/victory-axis.js +15 -57
- package/src/components/victory-bar/helper-methods.js +7 -5
- package/src/components/victory-bar/victory-bar.js +14 -120
- package/src/components/victory-candlestick/helper-methods.js +10 -9
- package/src/components/victory-candlestick/victory-candlestick.js +20 -121
- package/src/components/victory-chart/helper-methods.js +7 -6
- package/src/components/victory-chart/victory-chart.js +24 -79
- package/src/components/victory-errorbar/helper-methods.js +7 -7
- package/src/components/victory-errorbar/victory-errorbar.js +15 -120
- package/src/components/victory-group/victory-group.js +26 -100
- package/src/components/victory-line/helper-methods.js +5 -4
- package/src/components/victory-line/victory-line.js +16 -112
- package/src/components/victory-scatter/helper-methods.js +8 -8
- package/src/components/victory-scatter/victory-scatter.js +11 -114
- package/src/components/victory-stack/victory-stack.js +21 -69
- package/src/components/victory-voronoi/helper-methods.js +3 -3
- package/src/components/victory-voronoi/victory-voronoi.js +10 -115
- package/src/helpers/axis.js +6 -6
- package/src/helpers/common-props.js +89 -0
- package/src/helpers/wrapper.js +10 -9
- package/src/index.js +7 -5
- package/lib/components/victory-voronoi-tooltip/helper-methods.js +0 -100
- package/lib/components/victory-voronoi-tooltip/victory-voronoi-tooltip.js +0 -180
- package/lib/components/victory-zoom/helper-methods.js +0 -48
- package/lib/components/victory-zoom/victory-zoom.js +0 -221
- package/src/components/victory-voronoi-tooltip/helper-methods.js +0 -101
- package/src/components/victory-voronoi-tooltip/victory-voronoi-tooltip.js +0 -180
- package/src/components/victory-zoom/helper-methods.js +0 -49
- package/src/components/victory-zoom/victory-zoom.js +0 -221
|
@@ -1,10 +1,12 @@
|
|
|
1
|
-
import
|
|
1
|
+
import PropTypes from "prop-types";
|
|
2
|
+
import React from "react";
|
|
2
3
|
import { partialRight } from "lodash";
|
|
3
4
|
import {
|
|
4
|
-
PropTypes as CustomPropTypes, Helpers,
|
|
5
|
+
PropTypes as CustomPropTypes, Helpers, VictoryLabel, addEvents,
|
|
5
6
|
VictoryContainer, VictoryTheme, DefaultTransitions, Point, Data, Domain
|
|
6
7
|
} from "victory-core";
|
|
7
8
|
import ScatterHelpers from "./helper-methods";
|
|
9
|
+
import { BaseProps, DataProps } from "../../helpers/common-props";
|
|
8
10
|
|
|
9
11
|
const fallbackProps = {
|
|
10
12
|
width: 450,
|
|
@@ -24,93 +26,16 @@ class VictoryScatter extends React.Component {
|
|
|
24
26
|
static defaultTransitions = DefaultTransitions.discreteTransitions();
|
|
25
27
|
|
|
26
28
|
static propTypes = {
|
|
27
|
-
|
|
29
|
+
...BaseProps,
|
|
30
|
+
...DataProps,
|
|
28
31
|
bubbleProperty: PropTypes.string,
|
|
29
|
-
categories: PropTypes.oneOfType([
|
|
30
|
-
PropTypes.arrayOf(PropTypes.string),
|
|
31
|
-
PropTypes.shape({
|
|
32
|
-
x: PropTypes.arrayOf(PropTypes.string), y: PropTypes.arrayOf(PropTypes.string)
|
|
33
|
-
})
|
|
34
|
-
]),
|
|
35
|
-
containerComponent: PropTypes.element,
|
|
36
|
-
data: PropTypes.array,
|
|
37
|
-
domainPadding: PropTypes.oneOfType([
|
|
38
|
-
PropTypes.shape({
|
|
39
|
-
x: PropTypes.oneOfType([ PropTypes.number, CustomPropTypes.domain ]),
|
|
40
|
-
y: PropTypes.oneOfType([ PropTypes.number, CustomPropTypes.domain ])
|
|
41
|
-
}),
|
|
42
|
-
PropTypes.number
|
|
43
|
-
]),
|
|
44
|
-
dataComponent: PropTypes.element,
|
|
45
|
-
domain: PropTypes.oneOfType([
|
|
46
|
-
CustomPropTypes.domain,
|
|
47
|
-
PropTypes.shape({ x: CustomPropTypes.domain, y: CustomPropTypes.domain })
|
|
48
|
-
]),
|
|
49
|
-
events: PropTypes.arrayOf(PropTypes.shape({
|
|
50
|
-
target: PropTypes.oneOf(["data", "labels", "parent"]),
|
|
51
|
-
eventKey: PropTypes.oneOfType([
|
|
52
|
-
PropTypes.array,
|
|
53
|
-
CustomPropTypes.allOfType([CustomPropTypes.integer, CustomPropTypes.nonNegative]),
|
|
54
|
-
PropTypes.string
|
|
55
|
-
]),
|
|
56
|
-
eventHandlers: PropTypes.object
|
|
57
|
-
})),
|
|
58
|
-
eventKey: PropTypes.oneOfType([
|
|
59
|
-
PropTypes.func,
|
|
60
|
-
CustomPropTypes.allOfType([CustomPropTypes.integer, CustomPropTypes.nonNegative]),
|
|
61
|
-
PropTypes.string
|
|
62
|
-
]),
|
|
63
|
-
groupComponent: PropTypes.element,
|
|
64
|
-
height: CustomPropTypes.nonNegative,
|
|
65
|
-
labels: PropTypes.oneOfType([ PropTypes.func, PropTypes.array ]),
|
|
66
|
-
labelComponent: PropTypes.element,
|
|
67
32
|
maxBubbleSize: CustomPropTypes.nonNegative,
|
|
68
|
-
|
|
69
|
-
padding: PropTypes.oneOfType([
|
|
70
|
-
PropTypes.number,
|
|
71
|
-
PropTypes.shape({
|
|
72
|
-
top: PropTypes.number, bottom: PropTypes.number,
|
|
73
|
-
left: PropTypes.number, right: PropTypes.number
|
|
74
|
-
})
|
|
75
|
-
]),
|
|
76
|
-
samples: CustomPropTypes.nonNegative,
|
|
77
|
-
scale: PropTypes.oneOfType([
|
|
78
|
-
CustomPropTypes.scale,
|
|
79
|
-
PropTypes.shape({ x: CustomPropTypes.scale, y: CustomPropTypes.scale })
|
|
80
|
-
]),
|
|
81
|
-
sharedEvents: PropTypes.shape({
|
|
82
|
-
events: PropTypes.array,
|
|
83
|
-
getEventState: PropTypes.func
|
|
84
|
-
}),
|
|
85
|
-
sortKey: PropTypes.oneOfType([
|
|
86
|
-
PropTypes.func,
|
|
87
|
-
CustomPropTypes.allOfType([CustomPropTypes.integer, CustomPropTypes.nonNegative]),
|
|
88
|
-
PropTypes.string,
|
|
89
|
-
PropTypes.arrayOf(PropTypes.string)
|
|
90
|
-
]),
|
|
91
|
-
standalone: PropTypes.bool,
|
|
92
|
-
style: PropTypes.shape({
|
|
93
|
-
parent: PropTypes.object, data: PropTypes.object, labels: PropTypes.object
|
|
94
|
-
}),
|
|
33
|
+
size: PropTypes.oneOfType([ CustomPropTypes.nonNegative, PropTypes.func ]),
|
|
95
34
|
symbol: PropTypes.oneOfType([
|
|
96
35
|
PropTypes.oneOf([
|
|
97
36
|
"circle", "diamond", "plus", "square", "star", "triangleDown", "triangleUp"
|
|
98
37
|
]),
|
|
99
38
|
PropTypes.func
|
|
100
|
-
]),
|
|
101
|
-
theme: PropTypes.object,
|
|
102
|
-
width: CustomPropTypes.nonNegative,
|
|
103
|
-
x: PropTypes.oneOfType([
|
|
104
|
-
PropTypes.func,
|
|
105
|
-
CustomPropTypes.allOfType([CustomPropTypes.integer, CustomPropTypes.nonNegative]),
|
|
106
|
-
PropTypes.string,
|
|
107
|
-
PropTypes.arrayOf(PropTypes.string)
|
|
108
|
-
]),
|
|
109
|
-
y: PropTypes.oneOfType([
|
|
110
|
-
PropTypes.func,
|
|
111
|
-
CustomPropTypes.allOfType([CustomPropTypes.integer, CustomPropTypes.nonNegative]),
|
|
112
|
-
PropTypes.string,
|
|
113
|
-
PropTypes.arrayOf(PropTypes.string)
|
|
114
39
|
])
|
|
115
40
|
};
|
|
116
41
|
|
|
@@ -133,47 +58,19 @@ class VictoryScatter extends React.Component {
|
|
|
133
58
|
"dataComponent", "labelComponent", "groupComponent", "containerComponent"
|
|
134
59
|
];
|
|
135
60
|
|
|
136
|
-
|
|
137
|
-
const { dataComponent, labelComponent, groupComponent } = props;
|
|
138
|
-
|
|
139
|
-
const dataComponents = this.dataKeys.map((_dataKey, index) => {
|
|
140
|
-
const dataProps = this.getComponentProps(dataComponent, "data", index);
|
|
141
|
-
return React.cloneElement(dataComponent, dataProps);
|
|
142
|
-
});
|
|
143
|
-
|
|
144
|
-
const labelComponents = this.dataKeys.map((_dataKey, index) => {
|
|
145
|
-
const labelProps = this.getComponentProps(labelComponent, "labels", index);
|
|
146
|
-
if (labelProps.text !== undefined && labelProps.text !== null) {
|
|
147
|
-
return React.cloneElement(labelComponent, labelProps);
|
|
148
|
-
}
|
|
149
|
-
}).filter(Boolean);
|
|
150
|
-
|
|
151
|
-
const children = [...dataComponents, ...labelComponents];
|
|
152
|
-
return this.renderContainer(groupComponent, children);
|
|
153
|
-
}
|
|
154
|
-
|
|
61
|
+
// Overridden in native versions
|
|
155
62
|
shouldAnimate() {
|
|
156
63
|
return !!this.props.animate;
|
|
157
64
|
}
|
|
158
65
|
|
|
159
|
-
renderContainer(component, children) {
|
|
160
|
-
const isContainer = component.type && component.type.role === "container";
|
|
161
|
-
const parentProps = isContainer ? this.getComponentProps(component, "parent", "parent") : {};
|
|
162
|
-
return React.cloneElement(component, parentProps, children);
|
|
163
|
-
}
|
|
164
|
-
|
|
165
66
|
render() {
|
|
166
|
-
const {role} = this.constructor;
|
|
67
|
+
const { role } = this.constructor;
|
|
167
68
|
const props = Helpers.modifyProps(this.props, fallbackProps, role);
|
|
168
69
|
if (this.shouldAnimate()) {
|
|
169
|
-
return (
|
|
170
|
-
<VictoryTransition animate={props.animate} animationWhitelist={animationWhitelist}>
|
|
171
|
-
{React.createElement(this.constructor, props)}
|
|
172
|
-
</VictoryTransition>
|
|
173
|
-
);
|
|
70
|
+
return this.animateComponent(props, animationWhitelist);
|
|
174
71
|
}
|
|
175
72
|
const children = this.renderData(props);
|
|
176
|
-
return this.renderContainer(props.containerComponent, children);
|
|
73
|
+
return props.standalone ? this.renderContainer(props.containerComponent, children) : children;
|
|
177
74
|
}
|
|
178
75
|
}
|
|
179
76
|
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { assign, defaults } from "lodash";
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
|
|
5
|
-
VictoryTheme, Scale
|
|
6
|
-
} from "victory-core";
|
|
2
|
+
import PropTypes from "prop-types";
|
|
3
|
+
import React from "react";
|
|
4
|
+
import { Helpers, VictorySharedEvents, VictoryContainer, VictoryTheme, Scale } from "victory-core";
|
|
7
5
|
import Wrapper from "../../helpers/wrapper";
|
|
6
|
+
import { BaseProps } from "../../helpers/common-props";
|
|
7
|
+
|
|
8
8
|
|
|
9
9
|
const fallbackProps = {
|
|
10
10
|
width: 450,
|
|
@@ -18,15 +18,15 @@ export default class VictoryStack extends React.Component {
|
|
|
18
18
|
static role = "stack";
|
|
19
19
|
|
|
20
20
|
static propTypes = {
|
|
21
|
-
|
|
21
|
+
...BaseProps,
|
|
22
22
|
categories: PropTypes.oneOfType([
|
|
23
23
|
PropTypes.arrayOf(PropTypes.string),
|
|
24
24
|
PropTypes.shape({
|
|
25
25
|
x: PropTypes.arrayOf(PropTypes.string), y: PropTypes.arrayOf(PropTypes.string)
|
|
26
26
|
})
|
|
27
27
|
]),
|
|
28
|
-
children:
|
|
29
|
-
|
|
28
|
+
children: PropTypes.oneOfType([
|
|
29
|
+
PropTypes.arrayOf(PropTypes.node), PropTypes.node
|
|
30
30
|
]),
|
|
31
31
|
colorScale: PropTypes.oneOfType([
|
|
32
32
|
PropTypes.arrayOf(PropTypes.string),
|
|
@@ -34,77 +34,27 @@ export default class VictoryStack extends React.Component {
|
|
|
34
34
|
"grayscale", "qualitative", "heatmap", "warm", "cool", "red", "green", "blue"
|
|
35
35
|
])
|
|
36
36
|
]),
|
|
37
|
-
containerComponent: PropTypes.element,
|
|
38
|
-
domainPadding: PropTypes.oneOfType([
|
|
39
|
-
PropTypes.shape({
|
|
40
|
-
x: PropTypes.oneOfType([ PropTypes.number, CustomPropTypes.domain ]),
|
|
41
|
-
y: PropTypes.oneOfType([ PropTypes.number, CustomPropTypes.domain ])
|
|
42
|
-
}),
|
|
43
|
-
PropTypes.number
|
|
44
|
-
]),
|
|
45
|
-
dataComponent: PropTypes.element,
|
|
46
|
-
domain: PropTypes.oneOfType([
|
|
47
|
-
CustomPropTypes.domain,
|
|
48
|
-
PropTypes.shape({ x: CustomPropTypes.domain, y: CustomPropTypes.domain })
|
|
49
|
-
]),
|
|
50
|
-
events: PropTypes.arrayOf(PropTypes.shape({
|
|
51
|
-
childName: PropTypes.oneOfType([
|
|
52
|
-
PropTypes.string,
|
|
53
|
-
PropTypes.array
|
|
54
|
-
]),
|
|
55
|
-
target: PropTypes.oneOf(["data", "labels", "parent"]),
|
|
56
|
-
eventKey: PropTypes.oneOfType([
|
|
57
|
-
PropTypes.array,
|
|
58
|
-
PropTypes.func,
|
|
59
|
-
CustomPropTypes.allOfType([CustomPropTypes.integer, CustomPropTypes.nonNegative]),
|
|
60
|
-
PropTypes.string
|
|
61
|
-
]),
|
|
62
|
-
eventHandlers: PropTypes.object
|
|
63
|
-
})),
|
|
64
|
-
eventKey: PropTypes.oneOfType([
|
|
65
|
-
PropTypes.func,
|
|
66
|
-
CustomPropTypes.allOfType([CustomPropTypes.integer, CustomPropTypes.nonNegative]),
|
|
67
|
-
PropTypes.string
|
|
68
|
-
]),
|
|
69
|
-
groupComponent: PropTypes.element,
|
|
70
|
-
height: CustomPropTypes.nonNegative,
|
|
71
37
|
horizontal: PropTypes.bool,
|
|
72
|
-
labels: PropTypes.oneOfType([ PropTypes.func, PropTypes.array ]),
|
|
73
38
|
labelComponent: PropTypes.element,
|
|
74
|
-
|
|
75
|
-
padding: PropTypes.oneOfType([
|
|
76
|
-
PropTypes.number,
|
|
77
|
-
PropTypes.shape({
|
|
78
|
-
top: PropTypes.number, bottom: PropTypes.number,
|
|
79
|
-
left: PropTypes.number, right: PropTypes.number
|
|
80
|
-
})
|
|
81
|
-
]),
|
|
82
|
-
samples: CustomPropTypes.nonNegative,
|
|
83
|
-
scale: PropTypes.oneOfType([
|
|
84
|
-
CustomPropTypes.scale,
|
|
85
|
-
PropTypes.shape({ x: CustomPropTypes.scale, y: CustomPropTypes.scale })
|
|
86
|
-
]),
|
|
87
|
-
sharedEvents: PropTypes.shape({
|
|
88
|
-
events: PropTypes.array,
|
|
89
|
-
getEventState: PropTypes.func
|
|
90
|
-
}),
|
|
91
|
-
standalone: PropTypes.bool,
|
|
39
|
+
labels: PropTypes.oneOfType([ PropTypes.func, PropTypes.array ]),
|
|
92
40
|
style: PropTypes.shape({
|
|
93
41
|
parent: PropTypes.object, data: PropTypes.object, labels: PropTypes.object
|
|
94
42
|
}),
|
|
95
|
-
theme: PropTypes.object,
|
|
96
|
-
width: CustomPropTypes.nonNegative,
|
|
97
43
|
xOffset: PropTypes.number
|
|
98
44
|
};
|
|
99
45
|
|
|
100
46
|
static defaultProps = {
|
|
101
|
-
scale: "linear",
|
|
102
|
-
standalone: true,
|
|
103
47
|
containerComponent: <VictoryContainer/>,
|
|
104
48
|
groupComponent: <g/>,
|
|
49
|
+
scale: "linear",
|
|
50
|
+
standalone: true,
|
|
105
51
|
theme: VictoryTheme. grayscale
|
|
106
52
|
};
|
|
107
53
|
|
|
54
|
+
static expectedComponents = [
|
|
55
|
+
"groupComponent", "containerComponent", "labelComponent"
|
|
56
|
+
];
|
|
57
|
+
|
|
108
58
|
static getDomain = Wrapper.getStackedDomain.bind(Wrapper);
|
|
109
59
|
static getData = Wrapper.getData.bind(Wrapper);
|
|
110
60
|
|
|
@@ -162,7 +112,7 @@ export default class VictoryStack extends React.Component {
|
|
|
162
112
|
y: Wrapper.getCategories(props, "y")
|
|
163
113
|
};
|
|
164
114
|
const colorScale = props.colorScale;
|
|
165
|
-
return {datasets, categories, range, domain, horizontal, scale, style, colorScale};
|
|
115
|
+
return { datasets, categories, range, domain, horizontal, scale, style, colorScale };
|
|
166
116
|
}
|
|
167
117
|
|
|
168
118
|
addLayoutData(props, calculatedProps, datasets, index) { // eslint-disable-line max-params
|
|
@@ -249,7 +199,7 @@ export default class VictoryStack extends React.Component {
|
|
|
249
199
|
|
|
250
200
|
getStyle(theme, style, role) {
|
|
251
201
|
const defaultStyle = theme && theme[role] && theme[role].style ? theme[role].style : {};
|
|
252
|
-
return Helpers.getStyles(style, defaultStyle
|
|
202
|
+
return Helpers.getStyles(style, defaultStyle);
|
|
253
203
|
}
|
|
254
204
|
|
|
255
205
|
render() {
|
|
@@ -257,12 +207,14 @@ export default class VictoryStack extends React.Component {
|
|
|
257
207
|
const props = this.state && this.state.nodesWillExit ?
|
|
258
208
|
this.state.oldProps || this.props : this.props;
|
|
259
209
|
const modifiedProps = Helpers.modifyProps(props, fallbackProps, role);
|
|
260
|
-
const { eventKey, containerComponent} = modifiedProps;
|
|
210
|
+
const { eventKey, containerComponent, standalone, groupComponent } = modifiedProps;
|
|
261
211
|
const childComponents = React.Children.toArray(modifiedProps.children);
|
|
262
212
|
const calculatedProps = this.getCalculatedProps(modifiedProps, childComponents);
|
|
263
213
|
const newChildren = this.getNewChildren(modifiedProps, childComponents, calculatedProps);
|
|
264
214
|
const containerProps = this.getContainerProps(modifiedProps, calculatedProps);
|
|
265
|
-
const container =
|
|
215
|
+
const container = standalone ?
|
|
216
|
+
this.renderContainer(containerComponent, containerProps) :
|
|
217
|
+
React.cloneElement(groupComponent, {});
|
|
266
218
|
if (this.events) {
|
|
267
219
|
return (
|
|
268
220
|
<VictorySharedEvents events={this.events} eventKey={eventKey} container={container}>
|
|
@@ -9,7 +9,7 @@ export default {
|
|
|
9
9
|
const { width, height, standalone, theme, events, sharedEvents } = props;
|
|
10
10
|
const initialChildProps = { parent: {
|
|
11
11
|
style: style.parent, scale, domain, data, standalone, height, width, theme
|
|
12
|
-
}};
|
|
12
|
+
} };
|
|
13
13
|
|
|
14
14
|
return data.reduce((childProps, datum, index) => {
|
|
15
15
|
const polygon = without(polygons[index], "data");
|
|
@@ -53,7 +53,7 @@ export default {
|
|
|
53
53
|
getCalculatedValues(props) {
|
|
54
54
|
const defaultStyles = props.theme && props.theme.voronoi && props.theme.voronoi.style ?
|
|
55
55
|
props.theme.voronoi.style : {};
|
|
56
|
-
const style = Helpers.getStyles(props.style, defaultStyles
|
|
56
|
+
const style = Helpers.getStyles(props.style, defaultStyles);
|
|
57
57
|
const data = Data.getData(props);
|
|
58
58
|
const range = {
|
|
59
59
|
x: Helpers.getRange(props, "x"),
|
|
@@ -69,7 +69,7 @@ export default {
|
|
|
69
69
|
};
|
|
70
70
|
const voronoi = this.getVoronoi(range, scale);
|
|
71
71
|
const polygons = voronoi.polygons(data);
|
|
72
|
-
return {domain, data, scale, style, polygons};
|
|
72
|
+
return { domain, data, scale, style, polygons };
|
|
73
73
|
},
|
|
74
74
|
|
|
75
75
|
getVoronoi(range, scale) {
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import React
|
|
1
|
+
import React from "react";
|
|
2
2
|
import { partialRight } from "lodash";
|
|
3
3
|
import {
|
|
4
|
-
PropTypes as CustomPropTypes, Helpers,
|
|
4
|
+
PropTypes as CustomPropTypes, Helpers, VictoryLabel, addEvents,
|
|
5
5
|
VictoryContainer, VictoryTheme, DefaultTransitions, Voronoi, Data, Domain, Log
|
|
6
6
|
} from "victory-core";
|
|
7
7
|
import VoronoiHelpers from "./helper-methods";
|
|
8
|
+
import { BaseProps, DataProps } from "../../helpers/common-props";
|
|
8
9
|
|
|
9
10
|
const fallbackProps = {
|
|
10
11
|
width: 450,
|
|
@@ -22,87 +23,9 @@ class VictoryVoronoi extends React.Component {
|
|
|
22
23
|
static defaultTransitions = DefaultTransitions.discreteTransitions();
|
|
23
24
|
|
|
24
25
|
static propTypes = {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
PropTypes.shape({
|
|
29
|
-
x: PropTypes.arrayOf(PropTypes.string), y: PropTypes.arrayOf(PropTypes.string)
|
|
30
|
-
})
|
|
31
|
-
]),
|
|
32
|
-
containerComponent: PropTypes.element,
|
|
33
|
-
data: PropTypes.array,
|
|
34
|
-
domainPadding: PropTypes.oneOfType([
|
|
35
|
-
PropTypes.shape({
|
|
36
|
-
x: PropTypes.oneOfType([ PropTypes.number, CustomPropTypes.domain ]),
|
|
37
|
-
y: PropTypes.oneOfType([ PropTypes.number, CustomPropTypes.domain ])
|
|
38
|
-
}),
|
|
39
|
-
PropTypes.number
|
|
40
|
-
]),
|
|
41
|
-
dataComponent: PropTypes.element,
|
|
42
|
-
domain: PropTypes.oneOfType([
|
|
43
|
-
CustomPropTypes.domain,
|
|
44
|
-
PropTypes.shape({ x: CustomPropTypes.domain, y: CustomPropTypes.domain })
|
|
45
|
-
]),
|
|
46
|
-
events: PropTypes.arrayOf(PropTypes.shape({
|
|
47
|
-
target: PropTypes.oneOf(["data", "labels", "parent"]),
|
|
48
|
-
eventKey: PropTypes.oneOfType([
|
|
49
|
-
PropTypes.array,
|
|
50
|
-
CustomPropTypes.allOfType([CustomPropTypes.integer, CustomPropTypes.nonNegative]),
|
|
51
|
-
PropTypes.string
|
|
52
|
-
]),
|
|
53
|
-
eventHandlers: PropTypes.object
|
|
54
|
-
})),
|
|
55
|
-
eventKey: PropTypes.oneOfType([
|
|
56
|
-
PropTypes.func,
|
|
57
|
-
CustomPropTypes.allOfType([CustomPropTypes.integer, CustomPropTypes.nonNegative]),
|
|
58
|
-
PropTypes.string
|
|
59
|
-
]),
|
|
60
|
-
groupComponent: PropTypes.element,
|
|
61
|
-
height: CustomPropTypes.nonNegative,
|
|
62
|
-
labels: PropTypes.oneOfType([ PropTypes.func, PropTypes.array ]),
|
|
63
|
-
labelComponent: PropTypes.element,
|
|
64
|
-
name: PropTypes.string,
|
|
65
|
-
padding: PropTypes.oneOfType([
|
|
66
|
-
PropTypes.number,
|
|
67
|
-
PropTypes.shape({
|
|
68
|
-
top: PropTypes.number, bottom: PropTypes.number,
|
|
69
|
-
left: PropTypes.number, right: PropTypes.number
|
|
70
|
-
})
|
|
71
|
-
]),
|
|
72
|
-
samples: CustomPropTypes.nonNegative,
|
|
73
|
-
scale: PropTypes.oneOfType([
|
|
74
|
-
CustomPropTypes.scale,
|
|
75
|
-
PropTypes.shape({ x: CustomPropTypes.scale, y: CustomPropTypes.scale })
|
|
76
|
-
]),
|
|
77
|
-
sharedEvents: PropTypes.shape({
|
|
78
|
-
events: PropTypes.array,
|
|
79
|
-
getEventState: PropTypes.func
|
|
80
|
-
}),
|
|
81
|
-
sortKey: PropTypes.oneOfType([
|
|
82
|
-
PropTypes.func,
|
|
83
|
-
CustomPropTypes.allOfType([CustomPropTypes.integer, CustomPropTypes.nonNegative]),
|
|
84
|
-
PropTypes.string,
|
|
85
|
-
PropTypes.arrayOf(PropTypes.string)
|
|
86
|
-
]),
|
|
87
|
-
size: CustomPropTypes.nonNegative,
|
|
88
|
-
standalone: PropTypes.bool,
|
|
89
|
-
style: PropTypes.shape({
|
|
90
|
-
parent: PropTypes.object, data: PropTypes.object, labels: PropTypes.object
|
|
91
|
-
}),
|
|
92
|
-
theme: PropTypes.object,
|
|
93
|
-
width: CustomPropTypes.nonNegative,
|
|
94
|
-
x: PropTypes.oneOfType([
|
|
95
|
-
PropTypes.func,
|
|
96
|
-
CustomPropTypes.allOfType([CustomPropTypes.integer, CustomPropTypes.nonNegative]),
|
|
97
|
-
PropTypes.string,
|
|
98
|
-
PropTypes.arrayOf(PropTypes.string)
|
|
99
|
-
]),
|
|
100
|
-
y: PropTypes.oneOfType([
|
|
101
|
-
PropTypes.func,
|
|
102
|
-
CustomPropTypes.allOfType([CustomPropTypes.integer, CustomPropTypes.nonNegative]),
|
|
103
|
-
PropTypes.string,
|
|
104
|
-
PropTypes.arrayOf(PropTypes.string)
|
|
105
|
-
])
|
|
26
|
+
...BaseProps,
|
|
27
|
+
...DataProps,
|
|
28
|
+
size: CustomPropTypes.nonNegative
|
|
106
29
|
};
|
|
107
30
|
|
|
108
31
|
static defaultProps = {
|
|
@@ -130,47 +53,19 @@ class VictoryVoronoi extends React.Component {
|
|
|
130
53
|
);
|
|
131
54
|
}
|
|
132
55
|
|
|
133
|
-
|
|
134
|
-
const { dataComponent, labelComponent, groupComponent } = props;
|
|
135
|
-
|
|
136
|
-
const dataComponents = this.dataKeys.map((_dataKey, index) => {
|
|
137
|
-
const dataProps = this.getComponentProps(dataComponent, "data", index);
|
|
138
|
-
return React.cloneElement(dataComponent, dataProps);
|
|
139
|
-
});
|
|
140
|
-
|
|
141
|
-
const labelComponents = this.dataKeys.map((_dataKey, index) => {
|
|
142
|
-
const labelProps = this.getComponentProps(labelComponent, "labels", index);
|
|
143
|
-
if (labelProps.text !== undefined && labelProps.text !== null) {
|
|
144
|
-
return React.cloneElement(labelComponent, labelProps);
|
|
145
|
-
}
|
|
146
|
-
}).filter(Boolean);
|
|
147
|
-
|
|
148
|
-
const children = [...dataComponents, ...labelComponents];
|
|
149
|
-
return this.renderContainer(groupComponent, children);
|
|
150
|
-
}
|
|
151
|
-
|
|
56
|
+
// Overridden in native versions
|
|
152
57
|
shouldAnimate() {
|
|
153
58
|
return !!this.props.animate;
|
|
154
59
|
}
|
|
155
60
|
|
|
156
|
-
renderContainer(component, children) {
|
|
157
|
-
const isContainer = component.type && component.type.role === "container";
|
|
158
|
-
const parentProps = isContainer ? this.getComponentProps(component, "parent", "parent") : {};
|
|
159
|
-
return React.cloneElement(component, parentProps, children);
|
|
160
|
-
}
|
|
161
|
-
|
|
162
61
|
render() {
|
|
163
|
-
const {role} = this.constructor;
|
|
62
|
+
const { role } = this.constructor;
|
|
164
63
|
const props = Helpers.modifyProps(this.props, fallbackProps, role);
|
|
165
64
|
if (this.shouldAnimate()) {
|
|
166
|
-
return (
|
|
167
|
-
<VictoryTransition animate={props.animate} animationWhitelist={animationWhitelist}>
|
|
168
|
-
{React.createElement(this.constructor, props)}
|
|
169
|
-
</VictoryTransition>
|
|
170
|
-
);
|
|
65
|
+
return this.animateComponent(props, animationWhitelist);
|
|
171
66
|
}
|
|
172
67
|
const children = this.renderData(props);
|
|
173
|
-
return this.renderContainer(props.containerComponent, children);
|
|
68
|
+
return props.standalone ? this.renderContainer(props.containerComponent, children) : children;
|
|
174
69
|
}
|
|
175
70
|
}
|
|
176
71
|
|
package/src/helpers/axis.js
CHANGED
|
@@ -10,7 +10,7 @@ export default {
|
|
|
10
10
|
*/
|
|
11
11
|
getAxis(props) {
|
|
12
12
|
if (props.orientation) {
|
|
13
|
-
const vertical = {top: "x", bottom: "x", left: "y", right: "y"};
|
|
13
|
+
const vertical = { top: "x", bottom: "x", left: "y", right: "y" };
|
|
14
14
|
return vertical[props.orientation];
|
|
15
15
|
}
|
|
16
16
|
return props.dependentAxis ? "y" : "x";
|
|
@@ -120,12 +120,12 @@ export default {
|
|
|
120
120
|
}
|
|
121
121
|
const sign = originSign || "positive";
|
|
122
122
|
const typicalOrientations = {
|
|
123
|
-
positive: {x: "bottom", y: "left"},
|
|
124
|
-
negative: {x: "top", y: "right"}
|
|
123
|
+
positive: { x: "bottom", y: "left" },
|
|
124
|
+
negative: { x: "top", y: "right" }
|
|
125
125
|
};
|
|
126
126
|
const flippedOrientations = {
|
|
127
|
-
positive: {x: "left", y: "bottom"},
|
|
128
|
-
negative: {x: "right", y: "top"}
|
|
127
|
+
positive: { x: "left", y: "bottom" },
|
|
128
|
+
negative: { x: "right", y: "top" }
|
|
129
129
|
};
|
|
130
130
|
if (!component) {
|
|
131
131
|
return typicalOrientations[sign][axis];
|
|
@@ -152,7 +152,7 @@ export default {
|
|
|
152
152
|
*/
|
|
153
153
|
isVertical(props) {
|
|
154
154
|
const orientation = props.orientation || (props.dependentAxis ? "left" : "bottom");
|
|
155
|
-
const vertical = {top: false, bottom: false, left: true, right: true};
|
|
155
|
+
const vertical = { top: false, bottom: false, left: true, right: true };
|
|
156
156
|
return vertical[orientation];
|
|
157
157
|
},
|
|
158
158
|
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import PropTypes from "prop-types";
|
|
2
|
+
import { PropTypes as CustomPropTypes } from "victory-core";
|
|
3
|
+
|
|
4
|
+
export default {
|
|
5
|
+
DataProps: {
|
|
6
|
+
categories: PropTypes.oneOfType([
|
|
7
|
+
PropTypes.arrayOf(PropTypes.string),
|
|
8
|
+
PropTypes.shape({
|
|
9
|
+
x: PropTypes.arrayOf(PropTypes.string), y: PropTypes.arrayOf(PropTypes.string)
|
|
10
|
+
})
|
|
11
|
+
]),
|
|
12
|
+
data: PropTypes.array,
|
|
13
|
+
dataComponent: PropTypes.element,
|
|
14
|
+
labelComponent: PropTypes.element,
|
|
15
|
+
labels: PropTypes.oneOfType([ PropTypes.func, PropTypes.array ]),
|
|
16
|
+
samples: CustomPropTypes.nonNegative,
|
|
17
|
+
sortKey: PropTypes.oneOfType([
|
|
18
|
+
PropTypes.func,
|
|
19
|
+
CustomPropTypes.allOfType([CustomPropTypes.integer, CustomPropTypes.nonNegative]),
|
|
20
|
+
PropTypes.string,
|
|
21
|
+
PropTypes.arrayOf(PropTypes.string)
|
|
22
|
+
]),
|
|
23
|
+
style: PropTypes.shape({
|
|
24
|
+
parent: PropTypes.object, data: PropTypes.object, labels: PropTypes.object
|
|
25
|
+
}),
|
|
26
|
+
x: PropTypes.oneOfType([
|
|
27
|
+
PropTypes.func,
|
|
28
|
+
CustomPropTypes.allOfType([CustomPropTypes.integer, CustomPropTypes.nonNegative]),
|
|
29
|
+
PropTypes.string,
|
|
30
|
+
PropTypes.arrayOf(PropTypes.string)
|
|
31
|
+
]),
|
|
32
|
+
y: PropTypes.oneOfType([
|
|
33
|
+
PropTypes.func,
|
|
34
|
+
CustomPropTypes.allOfType([CustomPropTypes.integer, CustomPropTypes.nonNegative]),
|
|
35
|
+
PropTypes.string,
|
|
36
|
+
PropTypes.arrayOf(PropTypes.string)
|
|
37
|
+
])
|
|
38
|
+
}, BaseProps: {
|
|
39
|
+
animate: PropTypes.object,
|
|
40
|
+
containerComponent: PropTypes.element,
|
|
41
|
+
domain: PropTypes.oneOfType([
|
|
42
|
+
CustomPropTypes.domain,
|
|
43
|
+
PropTypes.shape({ x: CustomPropTypes.domain, y: CustomPropTypes.domain })
|
|
44
|
+
]),
|
|
45
|
+
domainPadding: PropTypes.oneOfType([
|
|
46
|
+
PropTypes.shape({
|
|
47
|
+
x: PropTypes.oneOfType([ PropTypes.number, PropTypes.arrayOf(PropTypes.number) ]),
|
|
48
|
+
y: PropTypes.oneOfType([ PropTypes.number, PropTypes.arrayOf(PropTypes.number) ])
|
|
49
|
+
}),
|
|
50
|
+
PropTypes.number,
|
|
51
|
+
PropTypes.arrayOf(PropTypes.number)
|
|
52
|
+
]),
|
|
53
|
+
eventKey: PropTypes.oneOfType([
|
|
54
|
+
PropTypes.func,
|
|
55
|
+
CustomPropTypes.allOfType([CustomPropTypes.integer, CustomPropTypes.nonNegative]),
|
|
56
|
+
PropTypes.string
|
|
57
|
+
]),
|
|
58
|
+
events: PropTypes.arrayOf(PropTypes.shape({
|
|
59
|
+
target: PropTypes.oneOf(["data", "labels", "parent"]),
|
|
60
|
+
eventKey: PropTypes.oneOfType([
|
|
61
|
+
PropTypes.array,
|
|
62
|
+
CustomPropTypes.allOfType([CustomPropTypes.integer, CustomPropTypes.nonNegative]),
|
|
63
|
+
PropTypes.string
|
|
64
|
+
]),
|
|
65
|
+
eventHandlers: PropTypes.object
|
|
66
|
+
})),
|
|
67
|
+
groupComponent: PropTypes.element,
|
|
68
|
+
height: CustomPropTypes.nonNegative,
|
|
69
|
+
name: PropTypes.string,
|
|
70
|
+
padding: PropTypes.oneOfType([
|
|
71
|
+
PropTypes.number,
|
|
72
|
+
PropTypes.shape({
|
|
73
|
+
top: PropTypes.number, bottom: PropTypes.number,
|
|
74
|
+
left: PropTypes.number, right: PropTypes.number
|
|
75
|
+
})
|
|
76
|
+
]),
|
|
77
|
+
scale: PropTypes.oneOfType([
|
|
78
|
+
CustomPropTypes.scale,
|
|
79
|
+
PropTypes.shape({ x: CustomPropTypes.scale, y: CustomPropTypes.scale })
|
|
80
|
+
]),
|
|
81
|
+
sharedEvents: PropTypes.shape({
|
|
82
|
+
events: PropTypes.array,
|
|
83
|
+
getEventState: PropTypes.func
|
|
84
|
+
}),
|
|
85
|
+
standalone: PropTypes.bool,
|
|
86
|
+
theme: PropTypes.object,
|
|
87
|
+
width: CustomPropTypes.nonNegative
|
|
88
|
+
}
|
|
89
|
+
};
|