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,3 +1,4 @@
|
|
|
1
|
+
/*eslint no-magic-numbers: ["error", { "ignore": [-1, 0, 1, 2, 1000] }]*/
|
|
1
2
|
import { Selection, Collection } from "victory-core";
|
|
2
3
|
import { throttle, isFunction, defaults } from "lodash";
|
|
3
4
|
import { attachId } from "../../helpers/event-handlers.js";
|
|
@@ -45,7 +46,7 @@ const Helpers = {
|
|
|
45
46
|
},
|
|
46
47
|
|
|
47
48
|
getMinimumDomain(point, props, axis) {
|
|
48
|
-
const {minimumZoom } = props;
|
|
49
|
+
const { minimumZoom } = props;
|
|
49
50
|
const originalDomain = this.getDomain(props)[axis];
|
|
50
51
|
const [from, to] = originalDomain;
|
|
51
52
|
const defaultMin = Math.abs(from - to) / 1000;
|
|
@@ -60,6 +61,7 @@ const Helpers = {
|
|
|
60
61
|
|
|
61
62
|
getScaleFactor(evt) {
|
|
62
63
|
const sign = evt.deltaY > 0 ? 1 : -1;
|
|
64
|
+
// eslint-disable-next-line no-magic-numbers
|
|
63
65
|
const delta = Math.min(Math.abs(evt.deltaY / 300), 0.5); // TODO: Check scale factor
|
|
64
66
|
return Math.abs(1 + sign * delta);
|
|
65
67
|
},
|
|
@@ -72,7 +74,7 @@ const Helpers = {
|
|
|
72
74
|
},
|
|
73
75
|
|
|
74
76
|
getPosition(evt, props, originalDomain) {
|
|
75
|
-
const {x, y} = Selection.getSVGEventCoordinates(evt);
|
|
77
|
+
const { x, y } = Selection.getSVGEventCoordinates(evt);
|
|
76
78
|
const originalScale = {
|
|
77
79
|
x: props.scale.x.domain(originalDomain.x),
|
|
78
80
|
y: props.scale.y.domain(originalDomain.y)
|
|
@@ -123,22 +125,23 @@ const Helpers = {
|
|
|
123
125
|
return isFunction(getTimer().resumeAnimation) ?
|
|
124
126
|
() => getTimer().resumeAnimation() : undefined;
|
|
125
127
|
}
|
|
128
|
+
return undefined;
|
|
126
129
|
},
|
|
127
130
|
|
|
128
131
|
getDomain(props) {
|
|
129
|
-
const {originalDomain, domain, scale} = props;
|
|
132
|
+
const { originalDomain, domain, scale } = props;
|
|
130
133
|
const scaleDomain = { x: scale.x.domain(), y: scale.y.domain() };
|
|
131
134
|
return defaults({}, originalDomain, domain, scaleDomain);
|
|
132
135
|
},
|
|
133
136
|
|
|
134
137
|
onMouseDown(evt, targetProps) {
|
|
135
138
|
evt.preventDefault();
|
|
136
|
-
const {domain, zoomDomain} = targetProps;
|
|
139
|
+
const { domain, zoomDomain } = targetProps;
|
|
137
140
|
const originalDomain = this.getDomain(targetProps);
|
|
138
141
|
const currentDomain = defaults(
|
|
139
142
|
{}, targetProps.currentDomain || zoomDomain || originalDomain, domain
|
|
140
143
|
);
|
|
141
|
-
const {x, y} = Selection.getSVGEventCoordinates(evt);
|
|
144
|
+
const { x, y } = Selection.getSVGEventCoordinates(evt);
|
|
142
145
|
return [{
|
|
143
146
|
target: "parent",
|
|
144
147
|
mutation: () => {
|
|
@@ -155,7 +158,7 @@ const Helpers = {
|
|
|
155
158
|
return [{
|
|
156
159
|
target: "parent",
|
|
157
160
|
mutation: () => {
|
|
158
|
-
return {panning: false};
|
|
161
|
+
return { panning: false };
|
|
159
162
|
}
|
|
160
163
|
}];
|
|
161
164
|
},
|
|
@@ -164,7 +167,7 @@ const Helpers = {
|
|
|
164
167
|
return [{
|
|
165
168
|
target: "parent",
|
|
166
169
|
mutation: () => {
|
|
167
|
-
return {panning: false};
|
|
170
|
+
return { panning: false };
|
|
168
171
|
}
|
|
169
172
|
}];
|
|
170
173
|
},
|
|
@@ -172,7 +175,7 @@ const Helpers = {
|
|
|
172
175
|
onMouseMove(evt, targetProps, eventKey, ctx) { // eslint-disable-line max-params
|
|
173
176
|
if (targetProps.panning) {
|
|
174
177
|
const { scale, startX, startY, onDomainChange, dimension, domain, zoomDomain } = targetProps;
|
|
175
|
-
const {x, y} = Selection.getSVGEventCoordinates(evt);
|
|
178
|
+
const { x, y } = Selection.getSVGEventCoordinates(evt);
|
|
176
179
|
const originalDomain = this.getDomain(targetProps);
|
|
177
180
|
const lastDomain = defaults(
|
|
178
181
|
{}, targetProps.currentDomain || zoomDomain || originalDomain, domain
|
|
@@ -198,6 +201,7 @@ const Helpers = {
|
|
|
198
201
|
}
|
|
199
202
|
}];
|
|
200
203
|
}
|
|
204
|
+
return undefined;
|
|
201
205
|
},
|
|
202
206
|
|
|
203
207
|
onWheel(evt, targetProps, eventKey, ctx) { // eslint-disable-line max-params
|
|
@@ -209,7 +213,7 @@ const Helpers = {
|
|
|
209
213
|
const lastDomain = defaults(
|
|
210
214
|
{}, targetProps.currentDomain || zoomDomain || originalDomain, domain
|
|
211
215
|
);
|
|
212
|
-
const {x, y} = lastDomain;
|
|
216
|
+
const { x, y } = lastDomain;
|
|
213
217
|
const currentDomain = {
|
|
214
218
|
x: dimension === "y" ? lastDomain.x : this.scale(x, evt, targetProps, "x"),
|
|
215
219
|
y: dimension === "x" ? lastDomain.y : this.scale(y, evt, targetProps, "y")
|
|
@@ -231,6 +235,7 @@ const Helpers = {
|
|
|
231
235
|
}
|
|
232
236
|
};
|
|
233
237
|
|
|
238
|
+
export { Helpers as RawZoomHelpers }; // allow victory-native to extend these helpers
|
|
234
239
|
|
|
235
240
|
export default {
|
|
236
241
|
onMouseDown: Helpers.onMouseDown.bind(Helpers),
|
|
@@ -238,12 +243,12 @@ export default {
|
|
|
238
243
|
onMouseLeave: Helpers.onMouseLeave.bind(Helpers),
|
|
239
244
|
onMouseMove: throttle(
|
|
240
245
|
attachId(Helpers.onMouseMove.bind(Helpers)),
|
|
241
|
-
16,
|
|
242
|
-
{leading: true, trailing: false}
|
|
246
|
+
16, // eslint-disable-line no-magic-numbers
|
|
247
|
+
{ leading: true, trailing: false }
|
|
243
248
|
),
|
|
244
249
|
onWheel: throttle(
|
|
245
250
|
attachId(Helpers.onWheel.bind(Helpers)),
|
|
246
|
-
16,
|
|
247
|
-
{leading: true, trailing: false}
|
|
251
|
+
16, // eslint-disable-line no-magic-numbers
|
|
252
|
+
{ leading: true, trailing: false }
|
|
248
253
|
)
|
|
249
254
|
};
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
/*eslint no-magic-numbers: ["error", { "ignore": [-1, 0, 1, 2] }]*/
|
|
1
2
|
import { assign, defaults } from "lodash";
|
|
2
3
|
import { Helpers, Log, Data, Domain, Scale } from "victory-core";
|
|
3
4
|
|
|
@@ -6,7 +7,7 @@ export default {
|
|
|
6
7
|
getBaseProps(props, fallbackProps) {
|
|
7
8
|
props = Helpers.modifyProps(props, fallbackProps, "area");
|
|
8
9
|
const calculatedValues = this.getCalculatedValues(props);
|
|
9
|
-
const {scale, style, data, domain} = calculatedValues;
|
|
10
|
+
const { scale, style, data, domain } = calculatedValues;
|
|
10
11
|
const {
|
|
11
12
|
standalone, interpolation, events, sharedEvents, width, height, groupComponent, theme
|
|
12
13
|
} = props;
|
|
@@ -21,7 +22,7 @@ export default {
|
|
|
21
22
|
const text = this.getLabelText(props, datum, index);
|
|
22
23
|
if (text !== undefined && text !== null || events || sharedEvents) {
|
|
23
24
|
const eventKey = datum.eventKey || index;
|
|
24
|
-
childProps[eventKey] = {labels: this.getLabelProps(text, index, calculatedValues)};
|
|
25
|
+
childProps[eventKey] = { labels: this.getLabelProps(text, index, calculatedValues) };
|
|
25
26
|
}
|
|
26
27
|
return childProps;
|
|
27
28
|
}, initialChildProps);
|
|
@@ -30,7 +31,7 @@ export default {
|
|
|
30
31
|
getCalculatedValues(props) {
|
|
31
32
|
const { theme } = props;
|
|
32
33
|
const defaultStyles = theme && theme.area && theme.area.style ? theme.area.style : {};
|
|
33
|
-
const style = Helpers.getStyles(props.style, defaultStyles
|
|
34
|
+
const style = Helpers.getStyles(props.style, defaultStyles);
|
|
34
35
|
const range = {
|
|
35
36
|
x: Helpers.getRange(props, "x"),
|
|
36
37
|
y: Helpers.getRange(props, "y")
|
|
@@ -51,7 +52,7 @@ export default {
|
|
|
51
52
|
getLabelProps(text, index, calculatedProps) {
|
|
52
53
|
const { scale, data, style } = calculatedProps;
|
|
53
54
|
const datum = data[index];
|
|
54
|
-
const {x, y} = this.getLabelPosition(datum, scale);
|
|
55
|
+
const { x, y } = this.getLabelPosition(datum, scale);
|
|
55
56
|
const labelStyle = this.getLabelStyle(style) || {};
|
|
56
57
|
const sign = (datum._y1 || datum._y) < 0 ? -1 : 1;
|
|
57
58
|
return {
|
|
@@ -90,7 +91,7 @@ export default {
|
|
|
90
91
|
// use fill instead of stroke for text
|
|
91
92
|
const fill = dataStyle.stroke;
|
|
92
93
|
const padding = labelStyle.padding || 0;
|
|
93
|
-
return defaults({}, labelStyle, {opacity, fill, padding});
|
|
94
|
+
return defaults({}, labelStyle, { opacity, fill, padding });
|
|
94
95
|
},
|
|
95
96
|
|
|
96
97
|
|
|
@@ -108,7 +109,7 @@ export default {
|
|
|
108
109
|
return data.map((datum) => {
|
|
109
110
|
const _y1 = datum._y1 !== undefined ? datum._y1 : datum._y;
|
|
110
111
|
const _y0 = datum._y0 !== undefined ? datum._y0 : minY;
|
|
111
|
-
return assign({}, datum, {_y0, _y1});
|
|
112
|
+
return assign({}, datum, { _y0, _y1 });
|
|
112
113
|
});
|
|
113
114
|
}
|
|
114
115
|
};
|
|
@@ -1,10 +1,12 @@
|
|
|
1
|
-
import { partialRight
|
|
2
|
-
import
|
|
1
|
+
import { partialRight } from "lodash";
|
|
2
|
+
import PropTypes from "prop-types";
|
|
3
|
+
import React from "react";
|
|
3
4
|
import AreaHelpers from "./helper-methods";
|
|
4
5
|
import {
|
|
5
|
-
PropTypes as CustomPropTypes, Helpers,
|
|
6
|
+
PropTypes as CustomPropTypes, Helpers, VictoryLabel, VictoryContainer,
|
|
6
7
|
DefaultTransitions, Area, VictoryClipContainer, addEvents, VictoryTheme, Data, Domain
|
|
7
8
|
} from "victory-core";
|
|
9
|
+
import { BaseProps, DataProps } from "../../helpers/common-props";
|
|
8
10
|
|
|
9
11
|
const fallbackProps = {
|
|
10
12
|
width: 450,
|
|
@@ -18,94 +20,21 @@ const animationWhitelist = ["data", "domain", "height", "padding", "style", "wid
|
|
|
18
20
|
class VictoryArea extends React.Component {
|
|
19
21
|
|
|
20
22
|
static propTypes = {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
PropTypes.arrayOf(PropTypes.string),
|
|
24
|
-
PropTypes.shape({
|
|
25
|
-
x: PropTypes.arrayOf(PropTypes.string), y: PropTypes.arrayOf(PropTypes.string)
|
|
26
|
-
})
|
|
27
|
-
]),
|
|
28
|
-
containerComponent: PropTypes.element,
|
|
29
|
-
data: PropTypes.array,
|
|
30
|
-
domainPadding: PropTypes.oneOfType([
|
|
31
|
-
PropTypes.shape({
|
|
32
|
-
x: PropTypes.oneOfType([ PropTypes.number, CustomPropTypes.domain ]),
|
|
33
|
-
y: PropTypes.oneOfType([ PropTypes.number, CustomPropTypes.domain ])
|
|
34
|
-
}),
|
|
35
|
-
PropTypes.number
|
|
36
|
-
]),
|
|
37
|
-
dataComponent: PropTypes.element,
|
|
38
|
-
domain: PropTypes.oneOfType([
|
|
39
|
-
CustomPropTypes.domain,
|
|
40
|
-
PropTypes.shape({ x: CustomPropTypes.domain, y: CustomPropTypes.domain })
|
|
41
|
-
]),
|
|
42
|
-
events: PropTypes.arrayOf(PropTypes.shape({
|
|
43
|
-
target: PropTypes.oneOf(["data", "labels", "parent"]),
|
|
44
|
-
eventKey: PropTypes.oneOfType([
|
|
45
|
-
PropTypes.array,
|
|
46
|
-
CustomPropTypes.allOfType([CustomPropTypes.integer, CustomPropTypes.nonNegative]),
|
|
47
|
-
PropTypes.string
|
|
48
|
-
]),
|
|
49
|
-
eventHandlers: PropTypes.object
|
|
50
|
-
})),
|
|
51
|
-
groupComponent: PropTypes.element,
|
|
52
|
-
height: CustomPropTypes.nonNegative,
|
|
23
|
+
...BaseProps,
|
|
24
|
+
...DataProps,
|
|
53
25
|
interpolation: PropTypes.oneOf([
|
|
54
26
|
"basis", "bundle", "cardinal", "catmullRom", "linear", "monotoneX",
|
|
55
27
|
"monotoneY", "natural", "radial", "step", "stepAfter", "stepBefore"
|
|
56
28
|
]),
|
|
57
|
-
|
|
29
|
+
label: CustomPropTypes.deprecated(
|
|
58
30
|
PropTypes.string,
|
|
59
31
|
"Use `labels` instead for individual data labels"
|
|
60
|
-
)
|
|
61
|
-
labels: PropTypes.oneOfType([ PropTypes.func, PropTypes.array ]),
|
|
62
|
-
labelComponent: PropTypes.element,
|
|
63
|
-
name: PropTypes.string,
|
|
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
|
-
samples: CustomPropTypes.nonNegative,
|
|
72
|
-
scale: PropTypes.oneOfType([
|
|
73
|
-
CustomPropTypes.scale,
|
|
74
|
-
PropTypes.shape({ x: CustomPropTypes.scale, y: CustomPropTypes.scale })
|
|
75
|
-
]),
|
|
76
|
-
sharedEvents: PropTypes.shape({
|
|
77
|
-
events: PropTypes.array,
|
|
78
|
-
getEventState: PropTypes.func
|
|
79
|
-
}),
|
|
80
|
-
sortKey: PropTypes.oneOfType([
|
|
81
|
-
PropTypes.func,
|
|
82
|
-
CustomPropTypes.allOfType([CustomPropTypes.integer, CustomPropTypes.nonNegative]),
|
|
83
|
-
PropTypes.string,
|
|
84
|
-
PropTypes.arrayOf(PropTypes.string)
|
|
85
|
-
]),
|
|
86
|
-
standalone: PropTypes.bool,
|
|
87
|
-
style: PropTypes.shape({
|
|
88
|
-
parent: PropTypes.object, data: PropTypes.object, labels: PropTypes.object
|
|
89
|
-
}),
|
|
90
|
-
theme: PropTypes.object,
|
|
91
|
-
width: CustomPropTypes.nonNegative,
|
|
92
|
-
x: PropTypes.oneOfType([
|
|
93
|
-
PropTypes.func,
|
|
94
|
-
CustomPropTypes.allOfType([CustomPropTypes.integer, CustomPropTypes.nonNegative]),
|
|
95
|
-
PropTypes.string,
|
|
96
|
-
PropTypes.arrayOf(PropTypes.string)
|
|
97
|
-
]),
|
|
98
|
-
y: PropTypes.oneOfType([
|
|
99
|
-
PropTypes.func,
|
|
100
|
-
CustomPropTypes.allOfType([CustomPropTypes.integer, CustomPropTypes.nonNegative]),
|
|
101
|
-
PropTypes.string,
|
|
102
|
-
PropTypes.arrayOf(PropTypes.string)
|
|
103
|
-
])
|
|
32
|
+
)
|
|
104
33
|
};
|
|
105
34
|
|
|
106
35
|
static defaultProps = {
|
|
107
36
|
dataComponent: <Area/>,
|
|
108
|
-
labelComponent: <VictoryLabel/>,
|
|
37
|
+
labelComponent: <VictoryLabel renderInPortal/>,
|
|
109
38
|
scale: "linear",
|
|
110
39
|
samples: 50,
|
|
111
40
|
standalone: true,
|
|
@@ -125,28 +54,7 @@ class VictoryArea extends React.Component {
|
|
|
125
54
|
"dataComponent", "labelComponent", "groupComponent", "containerComponent"
|
|
126
55
|
];
|
|
127
56
|
|
|
128
|
-
|
|
129
|
-
renderData(props) {
|
|
130
|
-
const { dataComponent, labelComponent, groupComponent } = props;
|
|
131
|
-
const dataKeys = without(this.dataKeys, "all");
|
|
132
|
-
const labelComponents = dataKeys.reduce((memo, key) => {
|
|
133
|
-
const labelProps = this.getComponentProps(labelComponent, "labels", key);
|
|
134
|
-
if (labelProps && labelProps.text !== undefined && labelProps.text !== null) {
|
|
135
|
-
memo = memo.concat(React.cloneElement(labelComponent, labelProps));
|
|
136
|
-
}
|
|
137
|
-
return memo;
|
|
138
|
-
}, []);
|
|
139
|
-
const dataProps = this.getComponentProps(dataComponent, "data", "all");
|
|
140
|
-
const children = [React.cloneElement(dataComponent, dataProps), ...labelComponents];
|
|
141
|
-
return this.renderContainer(groupComponent, children);
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
renderContainer(component, children) {
|
|
145
|
-
const isContainer = component.type && component.type.role === "container";
|
|
146
|
-
const parentProps = isContainer ? this.getComponentProps(component, "parent", "parent") : {};
|
|
147
|
-
return React.cloneElement(component, parentProps, children);
|
|
148
|
-
}
|
|
149
|
-
|
|
57
|
+
// Overridden in native versions
|
|
150
58
|
shouldAnimate() {
|
|
151
59
|
return !!this.props.animate;
|
|
152
60
|
}
|
|
@@ -156,14 +64,10 @@ class VictoryArea extends React.Component {
|
|
|
156
64
|
const props = Helpers.modifyProps(this.props, fallbackProps, role);
|
|
157
65
|
|
|
158
66
|
if (this.shouldAnimate()) {
|
|
159
|
-
return (
|
|
160
|
-
<VictoryTransition animate={props.animate} animationWhitelist={animationWhitelist}>
|
|
161
|
-
{React.createElement(this.constructor, props)}
|
|
162
|
-
</VictoryTransition>
|
|
163
|
-
);
|
|
67
|
+
return this.animateComponent(props, animationWhitelist);
|
|
164
68
|
}
|
|
165
|
-
const children = this.
|
|
166
|
-
return this.renderContainer(props.containerComponent, children);
|
|
69
|
+
const children = this.renderContinuousData(props);
|
|
70
|
+
return props.standalone ? this.renderContainer(props.containerComponent, children) : children;
|
|
167
71
|
}
|
|
168
72
|
}
|
|
169
73
|
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
/*eslint no-magic-numbers: ["error", { "ignore": [-90, -1, 0, 1, 2] }]*/
|
|
1
2
|
import { includes, defaults, defaultsDeep, isFunction, range, without } from "lodash";
|
|
2
3
|
import { Helpers, Scale, Domain } from "victory-core";
|
|
3
4
|
|
|
@@ -44,12 +45,12 @@ export default {
|
|
|
44
45
|
// exposed for use by VictoryChart
|
|
45
46
|
getAxis(props, flipped) {
|
|
46
47
|
if (props.orientation) {
|
|
47
|
-
const vertical = {top: "x", bottom: "x", left: "y", right: "y"};
|
|
48
|
+
const vertical = { top: "x", bottom: "x", left: "y", right: "y" };
|
|
48
49
|
return vertical[props.orientation];
|
|
49
50
|
}
|
|
50
51
|
const axisType = props.dependentAxis ? "dependent" : "independent";
|
|
51
|
-
const flippedAxis = { dependent: "x", independent: "y"};
|
|
52
|
-
const normalAxis = { independent: "x", dependent: "y"};
|
|
52
|
+
const flippedAxis = { dependent: "x", independent: "y" };
|
|
53
|
+
const normalAxis = { independent: "x", dependent: "y" };
|
|
53
54
|
return flipped ? flippedAxis[axisType] : normalAxis[axisType];
|
|
54
55
|
},
|
|
55
56
|
|
|
@@ -80,9 +81,9 @@ export default {
|
|
|
80
81
|
getStyles(props, styleObject) {
|
|
81
82
|
const style = props.style || {};
|
|
82
83
|
styleObject = styleObject || {};
|
|
83
|
-
const parentStyleProps = { height: "
|
|
84
|
+
const parentStyleProps = { height: "100%", width: "100%" };
|
|
84
85
|
return {
|
|
85
|
-
parent: defaults(
|
|
86
|
+
parent: defaults(style.parent, styleObject.parent, parentStyleProps),
|
|
86
87
|
axis: defaults({}, style.axis, styleObject.axis),
|
|
87
88
|
axisLabel: defaults({}, style.axisLabel, styleObject.axisLabel),
|
|
88
89
|
grid: defaults({}, style.grid, styleObject.grid),
|
|
@@ -118,7 +119,7 @@ export default {
|
|
|
118
119
|
},
|
|
119
120
|
|
|
120
121
|
getGridProps(layout, style, datum) {
|
|
121
|
-
const {edge, transform} = layout;
|
|
122
|
+
const { edge, transform } = layout;
|
|
122
123
|
return {
|
|
123
124
|
x1: transform.x,
|
|
124
125
|
y1: transform.y,
|
|
@@ -198,7 +199,7 @@ export default {
|
|
|
198
199
|
const axisLabelProps = this.getAxisLabelProps(props, calculatedValues, globalTransform);
|
|
199
200
|
const initialChildProps = { parent: {
|
|
200
201
|
style: style.parent, ticks, scale, width, height, domain, standalone, theme
|
|
201
|
-
}};
|
|
202
|
+
} };
|
|
202
203
|
|
|
203
204
|
return ticks.reduce((childProps, indexedTick, index) => {
|
|
204
205
|
const tick = stringTicks ? tickValues[indexedTick - 1] : indexedTick;
|
|
@@ -254,7 +255,7 @@ export default {
|
|
|
254
255
|
},
|
|
255
256
|
|
|
256
257
|
getAxisLabelProps(props, calculatedValues, globalTransform) {
|
|
257
|
-
const {style, orientation, padding, labelPadding, isVertical} = calculatedValues;
|
|
258
|
+
const { style, orientation, padding, labelPadding, isVertical } = calculatedValues;
|
|
258
259
|
const sign = orientationSign[orientation];
|
|
259
260
|
const hPadding = padding.left + padding.right;
|
|
260
261
|
const vPadding = padding.top + padding.bottom;
|
|
@@ -326,8 +327,10 @@ export default {
|
|
|
326
327
|
}
|
|
327
328
|
const isVertical = Helpers.isVertical(props);
|
|
328
329
|
// TODO: magic numbers
|
|
330
|
+
/*eslint-disable no-magic-numbers*/
|
|
329
331
|
const fontSize = labelStyle.fontSize || 14;
|
|
330
332
|
return props.label ? (fontSize * (isVertical ? 2.3 : 1.6)) : 0;
|
|
333
|
+
/*eslint-enable no-magic-numbers*/
|
|
331
334
|
},
|
|
332
335
|
|
|
333
336
|
getOffset(props, calculatedValues) {
|
|
@@ -336,7 +339,7 @@ export default {
|
|
|
336
339
|
} = calculatedValues;
|
|
337
340
|
const xPadding = orientation === "right" ? padding.right : padding.left;
|
|
338
341
|
const yPadding = orientation === "top" ? padding.top : padding.bottom;
|
|
339
|
-
const fontSize = style.axisLabel.fontSize || 14;
|
|
342
|
+
const fontSize = style.axisLabel.fontSize || 14; // eslint-disable-line no-magic-numbers
|
|
340
343
|
const offsetX = (props.offsetX !== null) && (props.offsetX !== undefined)
|
|
341
344
|
? props.offsetX : xPadding;
|
|
342
345
|
const offsetY = (props.offsetY !== null) && (props.offsetY !== undefined)
|
|
@@ -347,7 +350,7 @@ export default {
|
|
|
347
350
|
return tickStyle.size || 0;
|
|
348
351
|
});
|
|
349
352
|
const totalPadding = fontSize + (2 * Math.max(...tickSizes)) + labelPadding;
|
|
350
|
-
const minimumPadding = 1.2 * fontSize; //
|
|
353
|
+
const minimumPadding = 1.2 * fontSize; // eslint-disable-line no-magic-numbers
|
|
351
354
|
const x = isVertical ? totalPadding : minimumPadding;
|
|
352
355
|
const y = isVertical ? minimumPadding : totalPadding;
|
|
353
356
|
return {
|
|
@@ -357,17 +360,17 @@ export default {
|
|
|
357
360
|
},
|
|
358
361
|
|
|
359
362
|
getTransform(props, calculatedValues, offset) {
|
|
360
|
-
const {orientation} = calculatedValues;
|
|
363
|
+
const { orientation } = calculatedValues;
|
|
361
364
|
return {
|
|
362
|
-
top: {x: 0, y: offset.y},
|
|
363
|
-
bottom: {x: 0, y: props.height - offset.y},
|
|
364
|
-
left: {x: offset.x, y: 0},
|
|
365
|
-
right: {x: props.width - offset.x, y: 0}
|
|
365
|
+
top: { x: 0, y: offset.y },
|
|
366
|
+
bottom: { x: 0, y: props.height - offset.y },
|
|
367
|
+
left: { x: offset.x, y: 0 },
|
|
368
|
+
right: { x: props.width - offset.x, y: 0 }
|
|
366
369
|
}[orientation];
|
|
367
370
|
},
|
|
368
371
|
|
|
369
372
|
getTickPosition(style, orientation, isVertical) {
|
|
370
|
-
const {tickStyle, labelStyle} = style;
|
|
373
|
+
const { tickStyle, labelStyle } = style;
|
|
371
374
|
const size = tickStyle.size || 0;
|
|
372
375
|
const tickPadding = tickStyle.padding || 0;
|
|
373
376
|
const labelPadding = labelStyle.padding || 0;
|
|
@@ -389,17 +392,17 @@ export default {
|
|
|
389
392
|
},
|
|
390
393
|
|
|
391
394
|
getGridEdge(props, calculatedValues) {
|
|
392
|
-
const {orientation, padding, isVertical} = calculatedValues;
|
|
395
|
+
const { orientation, padding, isVertical } = calculatedValues;
|
|
393
396
|
const sign = -orientationSign[orientation];
|
|
394
397
|
const x = isVertical ?
|
|
395
398
|
sign * (props.width - (padding.left + padding.right)) : 0;
|
|
396
399
|
const y = isVertical ?
|
|
397
400
|
0 : sign * (props.height - (padding.top + padding.bottom));
|
|
398
|
-
return {x, y};
|
|
401
|
+
return { x, y };
|
|
399
402
|
},
|
|
400
403
|
|
|
401
404
|
getGridOffset(props, calculatedValues, offset) {
|
|
402
|
-
const {padding, orientation } = calculatedValues;
|
|
405
|
+
const { padding, orientation } = calculatedValues;
|
|
403
406
|
const xPadding = orientation === "right" ? padding.right : padding.left;
|
|
404
407
|
const yPadding = orientation === "top" ? padding.top : padding.bottom;
|
|
405
408
|
return {
|
|
@@ -1,11 +1,14 @@
|
|
|
1
|
-
import
|
|
1
|
+
import PropTypes from "prop-types";
|
|
2
|
+
import React from "react";
|
|
2
3
|
import { assign, partialRight } from "lodash";
|
|
3
4
|
import {
|
|
4
|
-
PropTypes as CustomPropTypes, Helpers,
|
|
5
|
+
PropTypes as CustomPropTypes, Helpers, VictoryLabel,
|
|
5
6
|
VictoryContainer, VictoryTheme, Line, TextSize, addEvents
|
|
6
7
|
} from "victory-core";
|
|
7
8
|
import AxisHelpers from "./helper-methods";
|
|
8
9
|
import Axis from "../../helpers/axis";
|
|
10
|
+
import { BaseProps } from "../../helpers/common-props";
|
|
11
|
+
|
|
9
12
|
|
|
10
13
|
const fallbackProps = {
|
|
11
14
|
width: 450,
|
|
@@ -33,67 +36,29 @@ class VictoryAxis extends React.Component {
|
|
|
33
36
|
};
|
|
34
37
|
|
|
35
38
|
static propTypes = {
|
|
36
|
-
|
|
39
|
+
...BaseProps,
|
|
37
40
|
axisComponent: PropTypes.element,
|
|
38
41
|
axisLabelComponent: PropTypes.element,
|
|
39
|
-
containerComponent: PropTypes.element,
|
|
40
42
|
crossAxis: PropTypes.bool,
|
|
41
43
|
dependentAxis: PropTypes.bool,
|
|
42
|
-
domain: PropTypes.oneOfType([
|
|
43
|
-
CustomPropTypes.domain,
|
|
44
|
-
PropTypes.shape({ x: CustomPropTypes.domain, y: CustomPropTypes.domain })
|
|
45
|
-
]),
|
|
46
|
-
domainPadding: PropTypes.oneOfType([
|
|
47
|
-
PropTypes.shape({
|
|
48
|
-
x: PropTypes.oneOfType([ PropTypes.number, CustomPropTypes.domain ]),
|
|
49
|
-
y: PropTypes.oneOfType([ PropTypes.number, CustomPropTypes.domain ])
|
|
50
|
-
}),
|
|
51
|
-
PropTypes.number
|
|
52
|
-
]),
|
|
53
|
-
events: PropTypes.arrayOf(PropTypes.shape({
|
|
54
|
-
target: PropTypes.oneOf(["axis", "axisLabel", "grid", "ticks", "tickLabels", "parent"]),
|
|
55
|
-
eventKey: PropTypes.oneOfType([
|
|
56
|
-
PropTypes.array,
|
|
57
|
-
CustomPropTypes.allOfType([CustomPropTypes.integer, CustomPropTypes.nonNegative]),
|
|
58
|
-
PropTypes.string
|
|
59
|
-
]),
|
|
60
|
-
eventHandlers: PropTypes.object
|
|
61
|
-
})),
|
|
62
44
|
fixLabelOverlap: PropTypes.bool,
|
|
63
45
|
gridComponent: PropTypes.element,
|
|
64
46
|
groupComponent: PropTypes.element,
|
|
65
|
-
height: CustomPropTypes.nonNegative,
|
|
66
47
|
label: PropTypes.any,
|
|
67
|
-
name: PropTypes.string,
|
|
68
48
|
offsetX: PropTypes.number,
|
|
69
49
|
offsetY: PropTypes.number,
|
|
70
50
|
orientation: PropTypes.oneOf(["top", "bottom", "left", "right"]),
|
|
71
|
-
padding: PropTypes.oneOfType([
|
|
72
|
-
PropTypes.number,
|
|
73
|
-
PropTypes.shape({
|
|
74
|
-
top: PropTypes.number, bottom: PropTypes.number,
|
|
75
|
-
left: PropTypes.number, right: PropTypes.number
|
|
76
|
-
})
|
|
77
|
-
]),
|
|
78
|
-
scale: PropTypes.oneOfType([
|
|
79
|
-
CustomPropTypes.scale,
|
|
80
|
-
PropTypes.shape({ x: CustomPropTypes.scale, y: CustomPropTypes.scale })
|
|
81
|
-
]),
|
|
82
|
-
sharedEvents: PropTypes.shape({ events: PropTypes.array, getEventState: PropTypes.func }),
|
|
83
|
-
standalone: PropTypes.bool,
|
|
84
51
|
style: PropTypes.shape({
|
|
85
52
|
parent: PropTypes.object, axis: PropTypes.object, axisLabel: PropTypes.object,
|
|
86
53
|
grid: PropTypes.object, ticks: PropTypes.object, tickLabels: PropTypes.object
|
|
87
54
|
}),
|
|
88
|
-
theme: PropTypes.object,
|
|
89
55
|
tickComponent: PropTypes.element,
|
|
90
56
|
tickCount: CustomPropTypes.allOfType([
|
|
91
57
|
CustomPropTypes.integer, CustomPropTypes.greaterThanZero
|
|
92
58
|
]),
|
|
93
59
|
tickFormat: PropTypes.oneOfType([ PropTypes.func, CustomPropTypes.homogeneousArray ]),
|
|
94
60
|
tickLabelComponent: PropTypes.element,
|
|
95
|
-
tickValues: CustomPropTypes.homogeneousArray
|
|
96
|
-
width: CustomPropTypes.nonNegative
|
|
61
|
+
tickValues: CustomPropTypes.homogeneousArray
|
|
97
62
|
};
|
|
98
63
|
|
|
99
64
|
static defaultProps = {
|
|
@@ -145,7 +110,7 @@ class VictoryAxis extends React.Component {
|
|
|
145
110
|
const TickLabel = React.cloneElement(tickLabelComponent, tickLabelProps);
|
|
146
111
|
|
|
147
112
|
return React.cloneElement(
|
|
148
|
-
props.groupComponent, {key: `tick-group-${key}`}, GridComponent, TickComponent, TickLabel
|
|
113
|
+
props.groupComponent, { key: `tick-group-${key}` }, GridComponent, TickComponent, TickLabel
|
|
149
114
|
);
|
|
150
115
|
});
|
|
151
116
|
}
|
|
@@ -160,8 +125,8 @@ class VictoryAxis extends React.Component {
|
|
|
160
125
|
.map((child) => child.props);
|
|
161
126
|
const paddingToObject = (padding) =>
|
|
162
127
|
typeof (padding) === "object"
|
|
163
|
-
? assign({}, {top: 0, right: 0, bottom: 0, left: 0}, padding)
|
|
164
|
-
: {top: padding, right: padding, bottom: padding, left: padding };
|
|
128
|
+
? assign({}, { top: 0, right: 0, bottom: 0, left: 0 }, padding)
|
|
129
|
+
: { top: padding, right: padding, bottom: padding, left: padding };
|
|
165
130
|
const labelsSumSize = labels.reduce((sum, label) => {
|
|
166
131
|
const padding = paddingToObject(label.style.padding);
|
|
167
132
|
const labelSize = TextSize.approximateTextSize(label.text, {
|
|
@@ -186,12 +151,7 @@ class VictoryAxis extends React.Component {
|
|
|
186
151
|
return sorted.filter((gridAndTick, index) => index % divider === 0);
|
|
187
152
|
}
|
|
188
153
|
|
|
189
|
-
|
|
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
|
-
|
|
154
|
+
// Overridden in native versions
|
|
195
155
|
shouldAnimate() {
|
|
196
156
|
return !!this.props.animate;
|
|
197
157
|
}
|
|
@@ -199,11 +159,7 @@ class VictoryAxis extends React.Component {
|
|
|
199
159
|
render() {
|
|
200
160
|
const props = Helpers.modifyProps(this.props, fallbackProps, "axis");
|
|
201
161
|
if (this.shouldAnimate()) {
|
|
202
|
-
return (
|
|
203
|
-
<VictoryTransition animate={props.animate} animationWhitelist={animationWhitelist}>
|
|
204
|
-
{React.createElement(this.constructor, props)}
|
|
205
|
-
</VictoryTransition>
|
|
206
|
-
);
|
|
162
|
+
return this.animateComponent(props, animationWhitelist);
|
|
207
163
|
}
|
|
208
164
|
|
|
209
165
|
const gridAndTicks = this.renderGridAndTicks(props);
|
|
@@ -215,7 +171,9 @@ class VictoryAxis extends React.Component {
|
|
|
215
171
|
this.renderLine(props),
|
|
216
172
|
this.renderLabel(props)
|
|
217
173
|
];
|
|
218
|
-
return
|
|
174
|
+
return props.standalone ?
|
|
175
|
+
this.renderContainer(props.containerComponent, children) :
|
|
176
|
+
React.cloneElement(props.groupComponent, {}, children);
|
|
219
177
|
}
|
|
220
178
|
}
|
|
221
179
|
|
|
@@ -1,11 +1,13 @@
|
|
|
1
|
+
/*eslint no-magic-numbers: ["error", { "ignore": [-1, 0, 1, 2] }]*/
|
|
1
2
|
import { assign, defaults, omit } from "lodash";
|
|
2
3
|
import { Helpers, Data, Domain, Scale } from "victory-core";
|
|
3
4
|
|
|
4
5
|
export default {
|
|
5
6
|
|
|
6
7
|
getBarWidth(props) {
|
|
7
|
-
const {style, width, data} = props;
|
|
8
|
+
const { style, width, data } = props;
|
|
8
9
|
const padding = props.padding.left || props.padding;
|
|
10
|
+
// eslint-disable-next-line no-magic-numbers
|
|
9
11
|
const defaultWidth = data.length === 0 ? 8 : (width - 2 * padding) / data.length;
|
|
10
12
|
return style && style.width ? style.width : defaultWidth;
|
|
11
13
|
},
|
|
@@ -74,7 +76,7 @@ export default {
|
|
|
74
76
|
getCalculatedValues(props) {
|
|
75
77
|
const { theme, horizontal } = props;
|
|
76
78
|
const defaultStyles = theme && theme.bar && theme.bar.style ? theme.bar.style : {};
|
|
77
|
-
const style = Helpers.getStyles(props.style, defaultStyles
|
|
79
|
+
const style = Helpers.getStyles(props.style, defaultStyles);
|
|
78
80
|
const data = Data.getData(props);
|
|
79
81
|
const range = {
|
|
80
82
|
x: Helpers.getRange(props, "x"),
|
|
@@ -95,11 +97,11 @@ export default {
|
|
|
95
97
|
|
|
96
98
|
getBaseProps(props, fallbackProps) {
|
|
97
99
|
props = Helpers.modifyProps(props, fallbackProps, "bar");
|
|
98
|
-
const {style, data, scale, domain } = this.getCalculatedValues(props);
|
|
100
|
+
const { style, data, scale, domain } = this.getCalculatedValues(props);
|
|
99
101
|
const { horizontal, width, height, padding, standalone, theme } = props;
|
|
100
|
-
const initialChildProps = {parent: {
|
|
102
|
+
const initialChildProps = { parent: {
|
|
101
103
|
domain, scale, width, height, data, standalone, theme, style: style.parent
|
|
102
|
-
}};
|
|
104
|
+
} };
|
|
103
105
|
|
|
104
106
|
return data.reduce((childProps, datum, index) => {
|
|
105
107
|
const eventKey = datum.eventKey || index;
|