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,11 @@
|
|
|
1
|
-
import
|
|
1
|
+
import PropTypes from "prop-types";
|
|
2
|
+
import React from "react";
|
|
2
3
|
import BarHelpers from "./helper-methods";
|
|
3
4
|
import { partialRight } from "lodash";
|
|
4
5
|
import {
|
|
5
|
-
|
|
6
|
-
VictoryTheme, Bar, addEvents, Data, Domain
|
|
6
|
+
Helpers, VictoryLabel, VictoryContainer, VictoryTheme, Bar, addEvents, Data, Domain
|
|
7
7
|
} from "victory-core";
|
|
8
|
+
import { BaseProps, DataProps } from "../../helpers/common-props";
|
|
8
9
|
|
|
9
10
|
const fallbackProps = {
|
|
10
11
|
width: 450,
|
|
@@ -13,10 +14,10 @@ const fallbackProps = {
|
|
|
13
14
|
};
|
|
14
15
|
|
|
15
16
|
const defaultData = [
|
|
16
|
-
{x: 1, y: 1},
|
|
17
|
-
{x: 2, y: 2},
|
|
18
|
-
{x: 3, y: 3},
|
|
19
|
-
{x: 4, y: 4}
|
|
17
|
+
{ x: 1, y: 1 },
|
|
18
|
+
{ x: 2, y: 2 },
|
|
19
|
+
{ x: 3, y: 3 },
|
|
20
|
+
{ x: 4, y: 4 }
|
|
20
21
|
];
|
|
21
22
|
|
|
22
23
|
const animationWhitelist = ["data", "domain", "height", "padding", "style", "width"];
|
|
@@ -44,87 +45,9 @@ class VictoryBar extends React.Component {
|
|
|
44
45
|
};
|
|
45
46
|
|
|
46
47
|
static propTypes = {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
PropTypes.shape({
|
|
51
|
-
x: PropTypes.arrayOf(PropTypes.string), y: PropTypes.arrayOf(PropTypes.string)
|
|
52
|
-
})
|
|
53
|
-
]),
|
|
54
|
-
containerComponent: PropTypes.element,
|
|
55
|
-
data: PropTypes.array,
|
|
56
|
-
domainPadding: PropTypes.oneOfType([
|
|
57
|
-
PropTypes.shape({
|
|
58
|
-
x: PropTypes.oneOfType([ PropTypes.number, CustomPropTypes.domain ]),
|
|
59
|
-
y: PropTypes.oneOfType([ PropTypes.number, CustomPropTypes.domain ])
|
|
60
|
-
}),
|
|
61
|
-
PropTypes.number
|
|
62
|
-
]),
|
|
63
|
-
dataComponent: PropTypes.element,
|
|
64
|
-
domain: PropTypes.oneOfType([
|
|
65
|
-
CustomPropTypes.domain,
|
|
66
|
-
PropTypes.shape({ x: CustomPropTypes.domain, y: CustomPropTypes.domain })
|
|
67
|
-
]),
|
|
68
|
-
events: PropTypes.arrayOf(PropTypes.shape({
|
|
69
|
-
target: PropTypes.oneOf(["data", "labels", "parent"]),
|
|
70
|
-
eventKey: PropTypes.oneOfType([
|
|
71
|
-
PropTypes.array,
|
|
72
|
-
CustomPropTypes.allOfType([CustomPropTypes.integer, CustomPropTypes.nonNegative]),
|
|
73
|
-
PropTypes.string
|
|
74
|
-
]),
|
|
75
|
-
eventHandlers: PropTypes.object
|
|
76
|
-
})),
|
|
77
|
-
eventKey: PropTypes.oneOfType([
|
|
78
|
-
PropTypes.func,
|
|
79
|
-
CustomPropTypes.allOfType([CustomPropTypes.integer, CustomPropTypes.nonNegative]),
|
|
80
|
-
PropTypes.string
|
|
81
|
-
]),
|
|
82
|
-
groupComponent: PropTypes.element,
|
|
83
|
-
height: CustomPropTypes.nonNegative,
|
|
84
|
-
horizontal: PropTypes.bool,
|
|
85
|
-
labels: PropTypes.oneOfType([ PropTypes.func, PropTypes.array ]),
|
|
86
|
-
labelComponent: PropTypes.element,
|
|
87
|
-
name: PropTypes.string,
|
|
88
|
-
padding: PropTypes.oneOfType([
|
|
89
|
-
PropTypes.number,
|
|
90
|
-
PropTypes.shape({
|
|
91
|
-
top: PropTypes.number, bottom: PropTypes.number,
|
|
92
|
-
left: PropTypes.number, right: PropTypes.number
|
|
93
|
-
})
|
|
94
|
-
]),
|
|
95
|
-
samples: CustomPropTypes.nonNegative,
|
|
96
|
-
scale: PropTypes.oneOfType([
|
|
97
|
-
CustomPropTypes.scale,
|
|
98
|
-
PropTypes.shape({ x: CustomPropTypes.scale, y: CustomPropTypes.scale })
|
|
99
|
-
]),
|
|
100
|
-
sharedEvents: PropTypes.shape({
|
|
101
|
-
events: PropTypes.array,
|
|
102
|
-
getEventState: PropTypes.func
|
|
103
|
-
}),
|
|
104
|
-
sortKey: PropTypes.oneOfType([
|
|
105
|
-
PropTypes.func,
|
|
106
|
-
CustomPropTypes.allOfType([CustomPropTypes.integer, CustomPropTypes.nonNegative]),
|
|
107
|
-
PropTypes.string,
|
|
108
|
-
PropTypes.arrayOf(PropTypes.string)
|
|
109
|
-
]),
|
|
110
|
-
standalone: PropTypes.bool,
|
|
111
|
-
style: PropTypes.shape({
|
|
112
|
-
parent: PropTypes.object, data: PropTypes.object, labels: PropTypes.object
|
|
113
|
-
}),
|
|
114
|
-
theme: PropTypes.object,
|
|
115
|
-
width: CustomPropTypes.nonNegative,
|
|
116
|
-
x: PropTypes.oneOfType([
|
|
117
|
-
PropTypes.func,
|
|
118
|
-
CustomPropTypes.allOfType([CustomPropTypes.integer, CustomPropTypes.nonNegative]),
|
|
119
|
-
PropTypes.string,
|
|
120
|
-
PropTypes.arrayOf(PropTypes.string)
|
|
121
|
-
]),
|
|
122
|
-
y: PropTypes.oneOfType([
|
|
123
|
-
PropTypes.func,
|
|
124
|
-
CustomPropTypes.allOfType([CustomPropTypes.integer, CustomPropTypes.nonNegative]),
|
|
125
|
-
PropTypes.string,
|
|
126
|
-
PropTypes.arrayOf(PropTypes.string)
|
|
127
|
-
])
|
|
48
|
+
...BaseProps,
|
|
49
|
+
...DataProps,
|
|
50
|
+
horizontal: PropTypes.bool
|
|
128
51
|
};
|
|
129
52
|
|
|
130
53
|
static defaultProps = {
|
|
@@ -145,48 +68,19 @@ class VictoryBar extends React.Component {
|
|
|
145
68
|
"dataComponent", "labelComponent", "groupComponent", "containerComponent"
|
|
146
69
|
];
|
|
147
70
|
|
|
148
|
-
|
|
149
|
-
const { dataComponent, labelComponent, groupComponent } = props;
|
|
150
|
-
|
|
151
|
-
const dataComponents = this.dataKeys.map((_dataKey, index) => {
|
|
152
|
-
const dataProps = this.getComponentProps(dataComponent, "data", index);
|
|
153
|
-
return React.cloneElement(dataComponent, dataProps);
|
|
154
|
-
});
|
|
155
|
-
|
|
156
|
-
const labelComponents = this.dataKeys.map((_dataKey, index) => {
|
|
157
|
-
const labelProps = this.getComponentProps(labelComponent, "labels", index);
|
|
158
|
-
if (labelProps.text !== undefined && labelProps.text !== null) {
|
|
159
|
-
return React.cloneElement(labelComponent, labelProps);
|
|
160
|
-
}
|
|
161
|
-
}).filter(Boolean);
|
|
162
|
-
|
|
163
|
-
const children = [...dataComponents, ...labelComponents];
|
|
164
|
-
return this.renderContainer(groupComponent, children);
|
|
165
|
-
|
|
166
|
-
}
|
|
167
|
-
|
|
71
|
+
// Overridden in native versions
|
|
168
72
|
shouldAnimate() {
|
|
169
73
|
return !!this.props.animate;
|
|
170
74
|
}
|
|
171
75
|
|
|
172
|
-
renderContainer(component, children) {
|
|
173
|
-
const isContainer = component.type && component.type.role === "container";
|
|
174
|
-
const parentProps = isContainer ? this.getComponentProps(component, "parent", "parent") : {};
|
|
175
|
-
return React.cloneElement(component, parentProps, children);
|
|
176
|
-
}
|
|
177
|
-
|
|
178
76
|
render() {
|
|
179
77
|
const { role } = this.constructor;
|
|
180
78
|
const props = Helpers.modifyProps((this.props), fallbackProps, role);
|
|
181
79
|
if (this.shouldAnimate()) {
|
|
182
|
-
return (
|
|
183
|
-
<VictoryTransition animate={props.animate} animationWhitelist={animationWhitelist}>
|
|
184
|
-
{React.createElement(this.constructor, props)}
|
|
185
|
-
</VictoryTransition>
|
|
186
|
-
);
|
|
80
|
+
return this.animateComponent(props, animationWhitelist);
|
|
187
81
|
}
|
|
188
82
|
const children = this.renderData(props);
|
|
189
|
-
return this.renderContainer(props.containerComponent, children);
|
|
83
|
+
return props.standalone ? this.renderContainer(props.containerComponent, children) : children;
|
|
190
84
|
}
|
|
191
85
|
}
|
|
192
86
|
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
/*eslint no-magic-numbers: ["error", { "ignore": [0, 1] }]*/
|
|
1
2
|
import { assign, pick, sortBy, omit, defaults } from "lodash";
|
|
2
3
|
import { Helpers, Log, Scale, Domain, Data } from "victory-core";
|
|
3
4
|
|
|
@@ -7,9 +8,9 @@ export default {
|
|
|
7
8
|
const calculatedValues = this.getCalculatedValues(props);
|
|
8
9
|
const { data, style, scale, domain } = calculatedValues;
|
|
9
10
|
const { groupComponent, width, height, padding, standalone, theme } = props;
|
|
10
|
-
const initialChildProps = {parent: {
|
|
11
|
+
const initialChildProps = { parent: {
|
|
11
12
|
domain, scale, width, height, data, standalone, theme, style: style.parent
|
|
12
|
-
}};
|
|
13
|
+
} };
|
|
13
14
|
|
|
14
15
|
return data.reduce((childProps, datum, index) => {
|
|
15
16
|
const eventKey = datum.eventKey || index;
|
|
@@ -37,7 +38,7 @@ export default {
|
|
|
37
38
|
},
|
|
38
39
|
|
|
39
40
|
getLabelProps(dataProps, text, calculatedStyle) {
|
|
40
|
-
const {x, y1, index, scale, datum, data } = dataProps;
|
|
41
|
+
const { x, y1, index, scale, datum, data } = dataProps;
|
|
41
42
|
const labelStyle = this.getLabelStyle(calculatedStyle.labels, dataProps) || {};
|
|
42
43
|
return {
|
|
43
44
|
style: labelStyle,
|
|
@@ -58,7 +59,7 @@ export default {
|
|
|
58
59
|
const { theme } = props;
|
|
59
60
|
const defaultStyle = theme && theme.candlestick && theme.candlestick.style ?
|
|
60
61
|
theme.candlestick.style : {};
|
|
61
|
-
const style = Helpers.getStyles(props.style, defaultStyle
|
|
62
|
+
const style = Helpers.getStyles(props.style, defaultStyle);
|
|
62
63
|
const data = Data.addEventKeys(props, this.getData(props));
|
|
63
64
|
const range = {
|
|
64
65
|
x: Helpers.getRange(props, "x"),
|
|
@@ -72,7 +73,7 @@ export default {
|
|
|
72
73
|
x: Scale.getBaseScale(props, "x").domain(domain.x).range(range.x),
|
|
73
74
|
y: Scale.getBaseScale(props, "y").domain(domain.y).range(range.y)
|
|
74
75
|
};
|
|
75
|
-
return {domain, data, scale, style};
|
|
76
|
+
return { domain, data, scale, style };
|
|
76
77
|
},
|
|
77
78
|
|
|
78
79
|
getData(props) {
|
|
@@ -102,7 +103,7 @@ export default {
|
|
|
102
103
|
return assign(
|
|
103
104
|
{},
|
|
104
105
|
datum,
|
|
105
|
-
{_x, _y, _open, _close, _high, _low},
|
|
106
|
+
{ _x, _y, _open, _close, _high, _low },
|
|
106
107
|
typeof _x === "string" ? { _x: stringMap.x[_x], x: _x } : {}
|
|
107
108
|
);
|
|
108
109
|
}), props.sortKey);
|
|
@@ -163,7 +164,7 @@ export default {
|
|
|
163
164
|
const fill = datum.fill || style.fill || candleColor;
|
|
164
165
|
const strokeColor = datum.stroke || style.stroke;
|
|
165
166
|
const stroke = this.isTransparent(strokeColor) ? fill : strokeColor || "black";
|
|
166
|
-
return defaults({}, stylesFromData, {stroke, fill}, style);
|
|
167
|
+
return defaults({}, stylesFromData, { stroke, fill }, style);
|
|
167
168
|
},
|
|
168
169
|
|
|
169
170
|
getLabelText(props, datum, index) {
|
|
@@ -175,7 +176,7 @@ export default {
|
|
|
175
176
|
labelStyle = labelStyle || {};
|
|
176
177
|
const { size, style } = dataProps;
|
|
177
178
|
const matchedStyle = pick(style, ["opacity", "fill"]);
|
|
178
|
-
const padding = labelStyle.padding || size * 0.25;
|
|
179
|
-
return defaults({}, labelStyle, matchedStyle, {padding});
|
|
179
|
+
const padding = labelStyle.padding || size * 0.25; // eslint-disable-line no-magic-numbers
|
|
180
|
+
return defaults({}, labelStyle, matchedStyle, { padding });
|
|
180
181
|
}
|
|
181
182
|
};
|
|
@@ -1,11 +1,14 @@
|
|
|
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, Candle
|
|
6
7
|
} from "victory-core";
|
|
7
8
|
import CandlestickHelpers from "./helper-methods";
|
|
9
|
+
import { BaseProps, DataProps } from "../../helpers/common-props";
|
|
8
10
|
|
|
11
|
+
/*eslint-disable no-magic-numbers */
|
|
9
12
|
const fallbackProps = {
|
|
10
13
|
width: 450,
|
|
11
14
|
height: 300,
|
|
@@ -17,15 +20,16 @@ const fallbackProps = {
|
|
|
17
20
|
};
|
|
18
21
|
|
|
19
22
|
const defaultData = [
|
|
20
|
-
{x: new Date(2016, 6, 1), open: 5, close: 10, high: 15, low: 0},
|
|
21
|
-
{x: new Date(2016, 6, 2), open: 10, close: 15, high: 20, low: 5},
|
|
22
|
-
{x: new Date(2016, 6, 3), open: 15, close: 20, high: 25, low: 10},
|
|
23
|
-
{x: new Date(2016, 6, 4), open: 20, close: 25, high: 30, low: 15},
|
|
24
|
-
{x: new Date(2016, 6, 5), open: 25, close: 30, high: 35, low: 20},
|
|
25
|
-
{x: new Date(2016, 6, 6), open: 30, close: 35, high: 40, low: 25},
|
|
26
|
-
{x: new Date(2016, 6, 7), open: 35, close: 40, high: 45, low: 30},
|
|
27
|
-
{x: new Date(2016, 6, 8), open: 40, close: 45, high: 50, low: 35}
|
|
23
|
+
{ x: new Date(2016, 6, 1), open: 5, close: 10, high: 15, low: 0 },
|
|
24
|
+
{ x: new Date(2016, 6, 2), open: 10, close: 15, high: 20, low: 5 },
|
|
25
|
+
{ x: new Date(2016, 6, 3), open: 15, close: 20, high: 25, low: 10 },
|
|
26
|
+
{ x: new Date(2016, 6, 4), open: 20, close: 25, high: 30, low: 15 },
|
|
27
|
+
{ x: new Date(2016, 6, 5), open: 25, close: 30, high: 35, low: 20 },
|
|
28
|
+
{ x: new Date(2016, 6, 6), open: 30, close: 35, high: 40, low: 25 },
|
|
29
|
+
{ x: new Date(2016, 6, 7), open: 35, close: 40, high: 45, low: 30 },
|
|
30
|
+
{ x: new Date(2016, 6, 8), open: 40, close: 45, high: 50, low: 35 }
|
|
28
31
|
];
|
|
32
|
+
/*eslint-enable no-magic-numbers */
|
|
29
33
|
|
|
30
34
|
const animationWhitelist = [
|
|
31
35
|
"data", "domain", "height", "padding", "samples", "size", "style", "width"
|
|
@@ -37,109 +41,32 @@ class VictoryCandlestick extends React.Component {
|
|
|
37
41
|
static defaultTransitions = DefaultTransitions.discreteTransitions();
|
|
38
42
|
|
|
39
43
|
static propTypes = {
|
|
40
|
-
|
|
44
|
+
...BaseProps,
|
|
45
|
+
...DataProps,
|
|
41
46
|
candleColors: PropTypes.shape({ positive: PropTypes.string, negative: PropTypes.string }),
|
|
42
|
-
categories: PropTypes.oneOfType([
|
|
43
|
-
PropTypes.arrayOf(PropTypes.string),
|
|
44
|
-
PropTypes.shape({
|
|
45
|
-
x: PropTypes.arrayOf(PropTypes.string), y: PropTypes.arrayOf(PropTypes.string)
|
|
46
|
-
})
|
|
47
|
-
]),
|
|
48
47
|
close: PropTypes.oneOfType([
|
|
49
48
|
PropTypes.func,
|
|
50
49
|
CustomPropTypes.allOfType([CustomPropTypes.integer, CustomPropTypes.nonNegative]),
|
|
51
50
|
PropTypes.string,
|
|
52
51
|
PropTypes.arrayOf(PropTypes.string)
|
|
53
52
|
]),
|
|
54
|
-
containerComponent: PropTypes.element,
|
|
55
|
-
data: PropTypes.array,
|
|
56
|
-
domainPadding: PropTypes.oneOfType([
|
|
57
|
-
PropTypes.shape({
|
|
58
|
-
x: PropTypes.oneOfType([ PropTypes.number, CustomPropTypes.domain ]),
|
|
59
|
-
y: PropTypes.oneOfType([ PropTypes.number, CustomPropTypes.domain ])
|
|
60
|
-
}),
|
|
61
|
-
PropTypes.number
|
|
62
|
-
]),
|
|
63
|
-
dataComponent: PropTypes.element,
|
|
64
|
-
domain: PropTypes.oneOfType([
|
|
65
|
-
CustomPropTypes.domain,
|
|
66
|
-
PropTypes.shape({ x: CustomPropTypes.domain, y: CustomPropTypes.domain })
|
|
67
|
-
]),
|
|
68
|
-
events: PropTypes.arrayOf(PropTypes.shape({
|
|
69
|
-
target: PropTypes.oneOf(["data", "labels", "parent"]),
|
|
70
|
-
eventKey: PropTypes.oneOfType([
|
|
71
|
-
PropTypes.array,
|
|
72
|
-
PropTypes.func,
|
|
73
|
-
CustomPropTypes.allOfType([CustomPropTypes.integer, CustomPropTypes.nonNegative]),
|
|
74
|
-
PropTypes.string
|
|
75
|
-
]),
|
|
76
|
-
eventHandlers: PropTypes.object
|
|
77
|
-
})),
|
|
78
|
-
eventKey: PropTypes.oneOfType([
|
|
79
|
-
PropTypes.func,
|
|
80
|
-
CustomPropTypes.allOfType([CustomPropTypes.integer, CustomPropTypes.nonNegative]),
|
|
81
|
-
PropTypes.string
|
|
82
|
-
]),
|
|
83
|
-
groupComponent: PropTypes.element,
|
|
84
|
-
height: CustomPropTypes.nonNegative,
|
|
85
53
|
high: PropTypes.oneOfType([
|
|
86
54
|
PropTypes.func,
|
|
87
55
|
CustomPropTypes.allOfType([CustomPropTypes.integer, CustomPropTypes.nonNegative]),
|
|
88
56
|
PropTypes.string,
|
|
89
57
|
PropTypes.arrayOf(PropTypes.string)
|
|
90
58
|
]),
|
|
91
|
-
labels: PropTypes.oneOfType([ PropTypes.func, PropTypes.array ]),
|
|
92
|
-
labelComponent: PropTypes.element,
|
|
93
59
|
low: PropTypes.oneOfType([
|
|
94
60
|
PropTypes.func,
|
|
95
61
|
CustomPropTypes.allOfType([CustomPropTypes.integer, CustomPropTypes.nonNegative]),
|
|
96
62
|
PropTypes.string,
|
|
97
63
|
PropTypes.arrayOf(PropTypes.string)
|
|
98
64
|
]),
|
|
99
|
-
name: PropTypes.string,
|
|
100
65
|
open: PropTypes.oneOfType([
|
|
101
66
|
PropTypes.func,
|
|
102
67
|
CustomPropTypes.allOfType([CustomPropTypes.integer, CustomPropTypes.nonNegative]),
|
|
103
68
|
PropTypes.string,
|
|
104
69
|
PropTypes.arrayOf(PropTypes.string)
|
|
105
|
-
]),
|
|
106
|
-
padding: PropTypes.oneOfType([
|
|
107
|
-
PropTypes.number,
|
|
108
|
-
PropTypes.shape({
|
|
109
|
-
top: PropTypes.number, bottom: PropTypes.number,
|
|
110
|
-
left: PropTypes.number, right: PropTypes.number
|
|
111
|
-
})
|
|
112
|
-
]),
|
|
113
|
-
samples: CustomPropTypes.nonNegative,
|
|
114
|
-
scale: PropTypes.oneOfType([
|
|
115
|
-
CustomPropTypes.scale,
|
|
116
|
-
PropTypes.shape({ x: CustomPropTypes.scale, y: CustomPropTypes.scale })
|
|
117
|
-
]),
|
|
118
|
-
sharedEvents: PropTypes.shape({
|
|
119
|
-
events: PropTypes.array,
|
|
120
|
-
getEventState: PropTypes.func
|
|
121
|
-
}),
|
|
122
|
-
sortKey: PropTypes.oneOfType([
|
|
123
|
-
PropTypes.func,
|
|
124
|
-
CustomPropTypes.allOfType([CustomPropTypes.integer, CustomPropTypes.nonNegative]),
|
|
125
|
-
PropTypes.string,
|
|
126
|
-
PropTypes.arrayOf(PropTypes.string)
|
|
127
|
-
]),
|
|
128
|
-
size: PropTypes.oneOfType([
|
|
129
|
-
CustomPropTypes.nonNegative,
|
|
130
|
-
PropTypes.func
|
|
131
|
-
]),
|
|
132
|
-
standalone: PropTypes.bool,
|
|
133
|
-
style: PropTypes.shape({
|
|
134
|
-
parent: PropTypes.object, data: PropTypes.object, labels: PropTypes.object
|
|
135
|
-
}),
|
|
136
|
-
theme: PropTypes.object,
|
|
137
|
-
width: CustomPropTypes.nonNegative,
|
|
138
|
-
x: PropTypes.oneOfType([
|
|
139
|
-
PropTypes.func,
|
|
140
|
-
CustomPropTypes.allOfType([CustomPropTypes.integer, CustomPropTypes.nonNegative]),
|
|
141
|
-
PropTypes.string,
|
|
142
|
-
PropTypes.arrayOf(PropTypes.string)
|
|
143
70
|
])
|
|
144
71
|
};
|
|
145
72
|
|
|
@@ -163,47 +90,19 @@ class VictoryCandlestick extends React.Component {
|
|
|
163
90
|
"dataComponent", "labelComponent", "groupComponent", "containerComponent"
|
|
164
91
|
];
|
|
165
92
|
|
|
166
|
-
|
|
167
|
-
const { dataComponent, labelComponent, groupComponent} = props;
|
|
168
|
-
|
|
169
|
-
const dataComponents = this.dataKeys.map((_dataKey, index) => {
|
|
170
|
-
const dataProps = this.getComponentProps(dataComponent, "data", index);
|
|
171
|
-
return React.cloneElement(dataComponent, dataProps);
|
|
172
|
-
});
|
|
173
|
-
|
|
174
|
-
const labelComponents = this.dataKeys.map((_dataKey, index) => {
|
|
175
|
-
const labelProps = this.getComponentProps(labelComponent, "labels", index);
|
|
176
|
-
if (labelProps.text !== undefined && labelProps.text !== null) {
|
|
177
|
-
return React.cloneElement(labelComponent, labelProps);
|
|
178
|
-
}
|
|
179
|
-
}).filter(Boolean);
|
|
180
|
-
|
|
181
|
-
const children = [...dataComponents, ...labelComponents];
|
|
182
|
-
return this.renderContainer(groupComponent, children);
|
|
183
|
-
}
|
|
184
|
-
|
|
93
|
+
// Overridden in native versions
|
|
185
94
|
shouldAnimate() {
|
|
186
95
|
return !!this.props.animate;
|
|
187
96
|
}
|
|
188
97
|
|
|
189
|
-
renderContainer(component, children) {
|
|
190
|
-
const isContainer = component.type && component.type.role === "container";
|
|
191
|
-
const parentProps = isContainer ? this.getComponentProps(component, "parent", "parent") : {};
|
|
192
|
-
return React.cloneElement(component, parentProps, children);
|
|
193
|
-
}
|
|
194
|
-
|
|
195
98
|
render() {
|
|
196
|
-
const {role} = this.constructor;
|
|
99
|
+
const { role } = this.constructor;
|
|
197
100
|
const props = Helpers.modifyProps(this.props, fallbackProps, role);
|
|
198
101
|
if (this.shouldAnimate()) {
|
|
199
|
-
return (
|
|
200
|
-
<VictoryTransition animate={props.animate} animationWhitelist={animationWhitelist}>
|
|
201
|
-
{React.createElement(this.constructor, props)}
|
|
202
|
-
</VictoryTransition>
|
|
203
|
-
);
|
|
102
|
+
return this.animateComponent(props, animationWhitelist);
|
|
204
103
|
}
|
|
205
104
|
const children = this.renderData(props);
|
|
206
|
-
return this.renderContainer(props.containerComponent, children);
|
|
105
|
+
return props.standalone ? this.renderContainer(props.containerComponent, children) : children;
|
|
207
106
|
}
|
|
208
107
|
}
|
|
209
108
|
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
/*eslint no-magic-numbers: ["error", { "ignore": [0, 1, 2] }]*/
|
|
1
2
|
import { invert, sortBy, values } from "lodash";
|
|
2
3
|
import Axis from "../../helpers/axis";
|
|
3
4
|
import Wrapper from "../../helpers/wrapper";
|
|
@@ -22,9 +23,9 @@ export default {
|
|
|
22
23
|
return childComponents.concat([defaultAxes.independent, defaultAxes.dependent]);
|
|
23
24
|
}
|
|
24
25
|
if (axisComponents.dependent.length > 1 || axisComponents.independent.length > 1) {
|
|
25
|
-
const msg =
|
|
26
|
-
|
|
27
|
-
|
|
26
|
+
const msg = "Only one VictoryAxis component of each axis type is allowed when " +
|
|
27
|
+
"using the VictoryChart wrapper. Only the first axis will be used. Please compose " +
|
|
28
|
+
"multi-axis charts manually";
|
|
28
29
|
Log.warn(msg);
|
|
29
30
|
const dataComponents = this.getDataComponents(childComponents);
|
|
30
31
|
return Collection.removeUndefined(
|
|
@@ -45,8 +46,8 @@ export default {
|
|
|
45
46
|
|
|
46
47
|
const { offset, children } = groupComponent[0].props;
|
|
47
48
|
return horizontal ?
|
|
48
|
-
{y: (offset * children.length) / 2} :
|
|
49
|
-
{x: (offset * children.length) / 2};
|
|
49
|
+
{ y: (offset * children.length) / 2 } :
|
|
50
|
+
{ x: (offset * children.length) / 2 };
|
|
50
51
|
},
|
|
51
52
|
|
|
52
53
|
getDataComponents(childComponents) {
|
|
@@ -72,7 +73,7 @@ export default {
|
|
|
72
73
|
},
|
|
73
74
|
|
|
74
75
|
getAxisOffset(props, calculatedProps) {
|
|
75
|
-
const {axisComponents, scale, origin, originSign} = calculatedProps;
|
|
76
|
+
const { axisComponents, scale, origin, originSign } = calculatedProps;
|
|
76
77
|
// make the axes line up, and cross when appropriate
|
|
77
78
|
const axisOrientations = {
|
|
78
79
|
x: Axis.getOrientation(axisComponents.x, "x", originSign.x),
|
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
import { 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 VictoryAxis from "../victory-axis/victory-axis";
|
|
8
6
|
import ChartHelpers from "./helper-methods";
|
|
9
7
|
import Axis from "../../helpers/axis";
|
|
10
8
|
import Wrapper from "../../helpers/wrapper";
|
|
9
|
+
import { BaseProps } from "../../helpers/common-props";
|
|
11
10
|
|
|
12
11
|
const fallbackProps = {
|
|
13
12
|
width: 450,
|
|
@@ -19,79 +18,26 @@ export default class VictoryChart extends React.Component {
|
|
|
19
18
|
static displayName = "VictoryChart";
|
|
20
19
|
|
|
21
20
|
static propTypes = {
|
|
22
|
-
|
|
23
|
-
children:
|
|
24
|
-
|
|
25
|
-
|
|
21
|
+
...BaseProps,
|
|
22
|
+
children: PropTypes.oneOfType([
|
|
23
|
+
PropTypes.arrayOf(PropTypes.node),
|
|
24
|
+
PropTypes.node
|
|
26
25
|
]),
|
|
27
|
-
containerComponent: PropTypes.element,
|
|
28
26
|
defaultAxes: PropTypes.shape({
|
|
29
27
|
independent: PropTypes.element,
|
|
30
28
|
dependent: PropTypes.element
|
|
31
|
-
})
|
|
32
|
-
domain: PropTypes.oneOfType([
|
|
33
|
-
CustomPropTypes.domain,
|
|
34
|
-
PropTypes.shape({
|
|
35
|
-
x: CustomPropTypes.domain,
|
|
36
|
-
y: CustomPropTypes.domain
|
|
37
|
-
})
|
|
38
|
-
]),
|
|
39
|
-
domainPadding: PropTypes.oneOfType([
|
|
40
|
-
PropTypes.shape({
|
|
41
|
-
x: PropTypes.oneOfType([ PropTypes.number, CustomPropTypes.domain ]),
|
|
42
|
-
y: PropTypes.oneOfType([ PropTypes.number, CustomPropTypes.domain ])
|
|
43
|
-
}),
|
|
44
|
-
PropTypes.number
|
|
45
|
-
]),
|
|
46
|
-
events: PropTypes.arrayOf(PropTypes.shape({
|
|
47
|
-
childName: PropTypes.oneOfType([ PropTypes.string, PropTypes.array ]),
|
|
48
|
-
target: PropTypes.string,
|
|
49
|
-
eventKey: PropTypes.oneOfType([
|
|
50
|
-
PropTypes.array,
|
|
51
|
-
PropTypes.func,
|
|
52
|
-
CustomPropTypes.allOfType([CustomPropTypes.integer, CustomPropTypes.nonNegative]),
|
|
53
|
-
PropTypes.string
|
|
54
|
-
]),
|
|
55
|
-
eventHandlers: PropTypes.object
|
|
56
|
-
})),
|
|
57
|
-
eventKey: PropTypes.oneOfType([
|
|
58
|
-
PropTypes.func,
|
|
59
|
-
CustomPropTypes.allOfType([CustomPropTypes.integer, CustomPropTypes.nonNegative]),
|
|
60
|
-
PropTypes.string
|
|
61
|
-
]),
|
|
62
|
-
groupComponent: PropTypes.element,
|
|
63
|
-
height: CustomPropTypes.nonNegative,
|
|
64
|
-
padding: PropTypes.oneOfType([
|
|
65
|
-
PropTypes.number,
|
|
66
|
-
PropTypes.shape({
|
|
67
|
-
top: PropTypes.number, bottom: PropTypes.number,
|
|
68
|
-
left: PropTypes.number, right: PropTypes.number
|
|
69
|
-
})
|
|
70
|
-
]),
|
|
71
|
-
scale: PropTypes.oneOfType([
|
|
72
|
-
CustomPropTypes.scale,
|
|
73
|
-
PropTypes.shape({ x: CustomPropTypes.scale, y: CustomPropTypes.scale })
|
|
74
|
-
]),
|
|
75
|
-
sharedEvents: PropTypes.shape({
|
|
76
|
-
events: PropTypes.array,
|
|
77
|
-
getEventState: PropTypes.func
|
|
78
|
-
}),
|
|
79
|
-
standalone: PropTypes.bool,
|
|
80
|
-
style: PropTypes.object,
|
|
81
|
-
theme: PropTypes.object,
|
|
82
|
-
width: CustomPropTypes.nonNegative,
|
|
83
|
-
modifyChildren: PropTypes.func
|
|
29
|
+
})
|
|
84
30
|
};
|
|
85
31
|
|
|
86
32
|
static defaultProps = {
|
|
87
|
-
standalone: true,
|
|
88
33
|
containerComponent: <VictoryContainer/>,
|
|
89
|
-
groupComponent: <g/>,
|
|
90
|
-
theme: VictoryTheme.grayscale,
|
|
91
34
|
defaultAxes: {
|
|
92
35
|
independent: <VictoryAxis/>,
|
|
93
36
|
dependent: <VictoryAxis dependentAxis/>
|
|
94
|
-
}
|
|
37
|
+
},
|
|
38
|
+
groupComponent: <g/>,
|
|
39
|
+
standalone: true,
|
|
40
|
+
theme: VictoryTheme.grayscale
|
|
95
41
|
};
|
|
96
42
|
|
|
97
43
|
static expectedComponents = [
|
|
@@ -126,13 +72,15 @@ export default class VictoryChart extends React.Component {
|
|
|
126
72
|
getStyles(props) {
|
|
127
73
|
const styleProps = props.style && props.style.parent;
|
|
128
74
|
return {
|
|
129
|
-
parent: defaults(
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
75
|
+
parent: defaults(
|
|
76
|
+
{},
|
|
77
|
+
styleProps,
|
|
78
|
+
{
|
|
79
|
+
height: "100%",
|
|
80
|
+
width: "100%",
|
|
81
|
+
userSelect: "none"
|
|
82
|
+
}
|
|
83
|
+
) };
|
|
136
84
|
}
|
|
137
85
|
|
|
138
86
|
getAxisProps(child, props, calculatedProps) {
|
|
@@ -235,7 +183,7 @@ export default class VictoryChart extends React.Component {
|
|
|
235
183
|
const getAnimationProps = Wrapper.getAnimationProps.bind(this);
|
|
236
184
|
|
|
237
185
|
return childComponents.map((child, index) => {
|
|
238
|
-
const style = defaults({}, child.props.style, {parent: baseStyle});
|
|
186
|
+
const style = defaults({}, child.props.style, { parent: baseStyle });
|
|
239
187
|
const childProps = this.getChildProps(child, props, calculatedProps);
|
|
240
188
|
const newProps = defaults({
|
|
241
189
|
animate: getAnimationProps(props, child, index),
|
|
@@ -275,10 +223,7 @@ export default class VictoryChart extends React.Component {
|
|
|
275
223
|
const childComponents = ChartHelpers.getChildComponents(modifiedProps,
|
|
276
224
|
modifiedProps.defaultAxes);
|
|
277
225
|
const calculatedProps = this.getCalculatedProps(modifiedProps, childComponents);
|
|
278
|
-
|
|
279
|
-
if (this.props.modifyChildren) {
|
|
280
|
-
newChildren = this.props.modifyChildren(newChildren, modifiedProps);
|
|
281
|
-
}
|
|
226
|
+
const newChildren = this.getNewChildren(modifiedProps, childComponents, calculatedProps);
|
|
282
227
|
const containerProps = this.getContainerProps(modifiedProps, calculatedProps);
|
|
283
228
|
const container = this.renderContainer(containerComponent, containerProps);
|
|
284
229
|
if (this.events) {
|
|
@@ -8,7 +8,7 @@ export default {
|
|
|
8
8
|
const { groupComponent, height, width, borderWidth, standalone, theme } = props;
|
|
9
9
|
const initialChildProps = { parent: {
|
|
10
10
|
domain, style: style.parent, scale, data, height, width, standalone, theme
|
|
11
|
-
}};
|
|
11
|
+
} };
|
|
12
12
|
|
|
13
13
|
return data.reduce((childProps, datum, index) => {
|
|
14
14
|
const eventKey = datum.eventKey || index;
|
|
@@ -35,7 +35,7 @@ export default {
|
|
|
35
35
|
},
|
|
36
36
|
|
|
37
37
|
getLabelProps(dataProps, text, calculatedStyle) {
|
|
38
|
-
const { x, index, scale, errorY} = dataProps;
|
|
38
|
+
const { x, index, scale, errorY } = dataProps;
|
|
39
39
|
const error = errorY && Array.isArray(errorY) ? errorY[0] : errorY;
|
|
40
40
|
const y = error || dataProps.y;
|
|
41
41
|
const labelStyle = this.getLabelStyle(calculatedStyle.labels, dataProps) || {};
|
|
@@ -76,7 +76,7 @@ export default {
|
|
|
76
76
|
* @return {String or Array}
|
|
77
77
|
*/
|
|
78
78
|
|
|
79
|
-
const errorNames = {x: "errorX", y: "errorY"};
|
|
79
|
+
const errorNames = { x: "errorX", y: "errorY" };
|
|
80
80
|
const errors = datum[errorNames[axis]];
|
|
81
81
|
if (errors === 0) {
|
|
82
82
|
return false;
|
|
@@ -197,7 +197,7 @@ export default {
|
|
|
197
197
|
getCalculatedValues(props) {
|
|
198
198
|
const defaultStyles = props.theme && props.theme.errorbar && props.theme.errorbar.style ?
|
|
199
199
|
props.theme.errorbar.style : {};
|
|
200
|
-
const style = Helpers.getStyles(props.style, defaultStyles
|
|
200
|
+
const style = Helpers.getStyles(props.style, defaultStyles) || {};
|
|
201
201
|
const dataWithErrors = assign(Data.getData(props), this.getErrorData(props));
|
|
202
202
|
const data = Data.addEventKeys(props, dataWithErrors);
|
|
203
203
|
const range = {
|
|
@@ -213,7 +213,7 @@ export default {
|
|
|
213
213
|
y: Scale.getBaseScale(props, "y").domain(domain.y).range(range.y)
|
|
214
214
|
};
|
|
215
215
|
|
|
216
|
-
return {domain, data, scale, style};
|
|
216
|
+
return { domain, data, scale, style };
|
|
217
217
|
},
|
|
218
218
|
|
|
219
219
|
getDataStyles(datum, style) {
|
|
@@ -232,7 +232,7 @@ export default {
|
|
|
232
232
|
labelStyle = labelStyle || {};
|
|
233
233
|
const { size, style } = dataProps;
|
|
234
234
|
const matchedStyle = pick(style, ["opacity", "fill"]);
|
|
235
|
-
const padding = labelStyle.padding || size * 0.25;
|
|
236
|
-
return defaults({}, labelStyle, matchedStyle, {padding}) || {};
|
|
235
|
+
const padding = labelStyle.padding || size * 0.25; // eslint-disable-line no-magic-numbers
|
|
236
|
+
return defaults({}, labelStyle, matchedStyle, { padding }) || {};
|
|
237
237
|
}
|
|
238
238
|
};
|