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,5 @@
|
|
|
1
|
+
/*eslint no-magic-numbers: ["error", { "ignore": [0, 1, 2] }]*/
|
|
2
|
+
import PropTypes from "prop-types";
|
|
1
3
|
import React from "react";
|
|
2
4
|
import { VictoryContainer, Selection } from "victory-core";
|
|
3
5
|
import BrushHelpers from "./brush-helpers";
|
|
@@ -7,32 +9,32 @@ export const brushContainerMixin = (base) => class VictoryBrushContainer extends
|
|
|
7
9
|
static displayName = "VictoryBrushContainer";
|
|
8
10
|
static propTypes = {
|
|
9
11
|
...VictoryContainer.propTypes,
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
12
|
+
dimension: PropTypes.oneOf(["x", "y"]),
|
|
13
|
+
handleComponent: PropTypes.element,
|
|
14
|
+
handleStyle: PropTypes.object,
|
|
15
|
+
handleWidth: PropTypes.number,
|
|
16
|
+
onDomainChange: PropTypes.func,
|
|
17
|
+
selectedDomain: PropTypes.shape({
|
|
18
|
+
x: PropTypes.array,
|
|
19
|
+
y: PropTypes.array
|
|
16
20
|
}),
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
selectionComponent: React.PropTypes.element,
|
|
20
|
-
handleComponent: React.PropTypes.element
|
|
21
|
+
selectionComponent: PropTypes.element,
|
|
22
|
+
selectionStyle: PropTypes.object
|
|
21
23
|
};
|
|
22
24
|
static defaultProps = {
|
|
23
25
|
...VictoryContainer.defaultProps,
|
|
24
|
-
|
|
25
|
-
stroke: "transparent",
|
|
26
|
-
fill: "black",
|
|
27
|
-
fillOpacity: 0.1
|
|
28
|
-
},
|
|
26
|
+
handleComponent: <rect/>,
|
|
29
27
|
handleStyle: {
|
|
30
28
|
stroke: "transparent",
|
|
31
29
|
fill: "transparent"
|
|
32
30
|
},
|
|
33
31
|
handleWidth: 8,
|
|
34
32
|
selectionComponent: <rect/>,
|
|
35
|
-
|
|
33
|
+
selectionStyle: {
|
|
34
|
+
stroke: "transparent",
|
|
35
|
+
fill: "black",
|
|
36
|
+
fillOpacity: 0.1
|
|
37
|
+
}
|
|
36
38
|
};
|
|
37
39
|
|
|
38
40
|
static defaultEvents = [{
|
|
@@ -48,6 +50,8 @@ export const brushContainerMixin = (base) => class VictoryBrushContainer extends
|
|
|
48
50
|
this.mouseMoveMutationId = mutations.id; // eslint-disable-line
|
|
49
51
|
return mutations.mutations;
|
|
50
52
|
}
|
|
53
|
+
|
|
54
|
+
return undefined;
|
|
51
55
|
},
|
|
52
56
|
onMouseUp: (evt, targetProps) => {
|
|
53
57
|
return BrushHelpers.onMouseUp(evt, targetProps);
|
|
@@ -59,8 +63,8 @@ export const brushContainerMixin = (base) => class VictoryBrushContainer extends
|
|
|
59
63
|
}];
|
|
60
64
|
|
|
61
65
|
getSelectBox(props, coordinates) {
|
|
62
|
-
const {x, y} = coordinates;
|
|
63
|
-
const {selectionStyle, selectionComponent} = props;
|
|
66
|
+
const { x, y } = coordinates;
|
|
67
|
+
const { selectionStyle, selectionComponent } = props;
|
|
64
68
|
const selectionComponentStyle = selectionComponent.props && selectionComponent.props.style;
|
|
65
69
|
return x[0] !== x[1] && y[0] !== y[1] ?
|
|
66
70
|
React.cloneElement(selectionComponent, {
|
|
@@ -74,25 +78,25 @@ export const brushContainerMixin = (base) => class VictoryBrushContainer extends
|
|
|
74
78
|
}
|
|
75
79
|
|
|
76
80
|
getHandles(props, coordinates) {
|
|
77
|
-
const {dimension, handleWidth, handleStyle, handleComponent} = props;
|
|
78
|
-
const {x, y} = coordinates;
|
|
81
|
+
const { dimension, handleWidth, handleStyle, handleComponent } = props;
|
|
82
|
+
const { x, y } = coordinates;
|
|
79
83
|
const width = Math.abs(x[1] - x[0]) || 1;
|
|
80
84
|
const height = Math.abs(y[1] - y[0]) || 1;
|
|
81
85
|
const handleComponentStyle = handleComponent.props && handleComponent.props.style || {};
|
|
82
86
|
const style = defaults({}, handleComponentStyle, handleStyle);
|
|
83
|
-
const yProps = { style, width, height: handleWidth, cursor: "ns-resize"};
|
|
84
|
-
const xProps = { style, width: handleWidth, height, cursor: "ew-resize"};
|
|
87
|
+
const yProps = { style, width, height: handleWidth, cursor: "ns-resize" };
|
|
88
|
+
const xProps = { style, width: handleWidth, height, cursor: "ew-resize" };
|
|
85
89
|
const handleProps = {
|
|
86
|
-
top: dimension !== "x" && assign({x: x[0], y: y[1] - (handleWidth / 2)}, yProps),
|
|
87
|
-
bottom: dimension !== "x" && assign({x: x[0], y: y[0] - (handleWidth / 2)}, yProps),
|
|
88
|
-
left: dimension !== "y" && assign({y: y[1], x: x[0] - (handleWidth / 2)}, xProps),
|
|
89
|
-
right: dimension !== "y" && assign({y: y[1], x: x[1] - (handleWidth / 2)}, xProps)
|
|
90
|
+
top: dimension !== "x" && assign({ x: x[0], y: y[1] - (handleWidth / 2) }, yProps),
|
|
91
|
+
bottom: dimension !== "x" && assign({ x: x[0], y: y[0] - (handleWidth / 2) }, yProps),
|
|
92
|
+
left: dimension !== "y" && assign({ y: y[1], x: x[0] - (handleWidth / 2) }, xProps),
|
|
93
|
+
right: dimension !== "y" && assign({ y: y[1], x: x[1] - (handleWidth / 2) }, xProps)
|
|
90
94
|
};
|
|
91
95
|
const handles = ["top", "bottom", "left", "right"].reduce((memo, curr) => {
|
|
92
96
|
memo = handleProps[curr] ?
|
|
93
97
|
memo.concat(React.cloneElement(
|
|
94
98
|
handleComponent,
|
|
95
|
-
assign({key: `handle-${curr}`}, handleProps[curr]
|
|
99
|
+
assign({ key: `handle-${curr}` }, handleProps[curr]
|
|
96
100
|
))) : memo;
|
|
97
101
|
return memo;
|
|
98
102
|
}, []);
|
|
@@ -100,7 +104,7 @@ export const brushContainerMixin = (base) => class VictoryBrushContainer extends
|
|
|
100
104
|
}
|
|
101
105
|
|
|
102
106
|
getRect(props) {
|
|
103
|
-
const {currentDomain, cachedSelectedDomain, scale} = props;
|
|
107
|
+
const { currentDomain, cachedSelectedDomain, scale } = props;
|
|
104
108
|
const selectedDomain = defaults({}, props.selectedDomain, props.domain);
|
|
105
109
|
const domain = isEqual(selectedDomain, cachedSelectedDomain) ?
|
|
106
110
|
defaults({}, currentDomain, selectedDomain) : selectedDomain;
|
|
@@ -119,7 +123,7 @@ export const brushContainerMixin = (base) => class VictoryBrushContainer extends
|
|
|
119
123
|
getChildren(props) {
|
|
120
124
|
const children = React.Children.toArray(props.children);
|
|
121
125
|
return [...children, this.getRect(props)].map((component, i) => {
|
|
122
|
-
return component ? React.cloneElement(component, {key: i}) : null;
|
|
126
|
+
return component ? React.cloneElement(component, { key: i }) : null;
|
|
123
127
|
});
|
|
124
128
|
}
|
|
125
129
|
};
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
/*eslint no-magic-numbers: ["error", { "ignore": [0, 1, 2] }]*/
|
|
2
|
+
import PropTypes from "prop-types";
|
|
3
|
+
import React from "react";
|
|
4
|
+
import { VictoryContainer, VictoryLabel, Line, Selection, Helpers } from "victory-core";
|
|
5
|
+
import { isNumber } from "lodash";
|
|
6
|
+
import CursorHelpers from "./cursor-helpers";
|
|
7
|
+
|
|
8
|
+
export const cursorContainerMixin = (base) => class VictoryCursorContainer extends base {
|
|
9
|
+
static displayName = "VictoryCursorContainer";
|
|
10
|
+
static propTypes = {
|
|
11
|
+
...VictoryContainer.propTypes,
|
|
12
|
+
cursorLabel: PropTypes.func,
|
|
13
|
+
cursorLabelComponent: PropTypes.element,
|
|
14
|
+
cursorLabelOffset: PropTypes.oneOfType([
|
|
15
|
+
PropTypes.number,
|
|
16
|
+
PropTypes.shape({
|
|
17
|
+
x: PropTypes.number,
|
|
18
|
+
y: PropTypes.number
|
|
19
|
+
})
|
|
20
|
+
]),
|
|
21
|
+
defaultCursorValue: PropTypes.oneOfType([
|
|
22
|
+
PropTypes.number,
|
|
23
|
+
PropTypes.shape({
|
|
24
|
+
x: PropTypes.number,
|
|
25
|
+
y: PropTypes.number
|
|
26
|
+
})
|
|
27
|
+
]),
|
|
28
|
+
dimension: PropTypes.oneOf(["x", "y"]),
|
|
29
|
+
onChange: PropTypes.func,
|
|
30
|
+
standalone: PropTypes.bool
|
|
31
|
+
};
|
|
32
|
+
static defaultProps = {
|
|
33
|
+
...VictoryContainer.defaultProps,
|
|
34
|
+
cursorLabelComponent: <VictoryLabel/>,
|
|
35
|
+
cursorLabelOffset: {
|
|
36
|
+
x: 5,
|
|
37
|
+
y: -10
|
|
38
|
+
},
|
|
39
|
+
cursorComponent: <Line/>
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
static defaultEvents = [{
|
|
43
|
+
target: "parent",
|
|
44
|
+
eventHandlers: {
|
|
45
|
+
onMouseLeave: () => {
|
|
46
|
+
return [];
|
|
47
|
+
},
|
|
48
|
+
onMouseMove: (evt, targetProps) => {
|
|
49
|
+
const mutations = CursorHelpers.onMouseMove(evt, targetProps);
|
|
50
|
+
|
|
51
|
+
if (mutations.id !== this.mouseMoveMutationId) { // eslint-disable-line
|
|
52
|
+
this.mouseMoveMutationId = mutations.id; // eslint-disable-line
|
|
53
|
+
return mutations.mutations;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
return [];
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}];
|
|
60
|
+
|
|
61
|
+
getCursorPosition(props) {
|
|
62
|
+
const { cursorValue, defaultCursorValue, dimension, domain } = props;
|
|
63
|
+
if (cursorValue) { return cursorValue; }
|
|
64
|
+
|
|
65
|
+
if (isNumber(defaultCursorValue)) {
|
|
66
|
+
return {
|
|
67
|
+
x: (domain.x[0] + domain.x[1]) / 2,
|
|
68
|
+
y: (domain.y[0] + domain.y[1]) / 2,
|
|
69
|
+
[dimension]: defaultCursorValue
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
return defaultCursorValue;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
getCursorLabelOffset(props) {
|
|
77
|
+
const { cursorLabelOffset } = props;
|
|
78
|
+
|
|
79
|
+
if (isNumber(cursorLabelOffset)) {
|
|
80
|
+
return {
|
|
81
|
+
x: cursorLabelOffset,
|
|
82
|
+
y: cursorLabelOffset
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
return cursorLabelOffset;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
getCursorElements(props) {
|
|
90
|
+
const {
|
|
91
|
+
scale, domain, dimension, cursorLabelComponent, cursorLabel, cursorComponent
|
|
92
|
+
} = props;
|
|
93
|
+
const cursorValue = this.getCursorPosition(props);
|
|
94
|
+
const cursorLabelOffset = this.getCursorLabelOffset(props);
|
|
95
|
+
|
|
96
|
+
if (!cursorValue) { return []; }
|
|
97
|
+
|
|
98
|
+
const newElements = [];
|
|
99
|
+
const domainCoordinates = Selection.getDomainCoordinates(scale, domain);
|
|
100
|
+
|
|
101
|
+
const cursorCoordinates = {
|
|
102
|
+
x: scale.x(cursorValue.x),
|
|
103
|
+
y: scale.y(cursorValue.y)
|
|
104
|
+
};
|
|
105
|
+
if (cursorLabel) {
|
|
106
|
+
newElements.push(React.cloneElement(cursorLabelComponent, {
|
|
107
|
+
x: cursorCoordinates.x + cursorLabelOffset.x,
|
|
108
|
+
y: cursorCoordinates.y + cursorLabelOffset.y,
|
|
109
|
+
text: Helpers.evaluateProp(cursorLabel, cursorValue, true),
|
|
110
|
+
active: true,
|
|
111
|
+
key: "cursor-label"
|
|
112
|
+
}));
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
if (dimension === "x" || dimension === undefined) {
|
|
116
|
+
newElements.push(React.cloneElement(cursorComponent, {
|
|
117
|
+
key: "x-cursor",
|
|
118
|
+
x1: cursorCoordinates.x,
|
|
119
|
+
x2: cursorCoordinates.x,
|
|
120
|
+
y1: domainCoordinates.y[0],
|
|
121
|
+
y2: domainCoordinates.y[1]
|
|
122
|
+
}));
|
|
123
|
+
}
|
|
124
|
+
if (dimension === "y" || dimension === undefined) {
|
|
125
|
+
newElements.push(React.cloneElement(cursorComponent, {
|
|
126
|
+
key: "y-cursor",
|
|
127
|
+
x1: domainCoordinates.x[0],
|
|
128
|
+
x2: domainCoordinates.x[1],
|
|
129
|
+
y1: cursorCoordinates.y,
|
|
130
|
+
y2: cursorCoordinates.y
|
|
131
|
+
}));
|
|
132
|
+
}
|
|
133
|
+
return newElements;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
// Overrides method in VictoryContainer
|
|
137
|
+
getChildren(props) {
|
|
138
|
+
return [
|
|
139
|
+
...React.Children.toArray(props.children),
|
|
140
|
+
...this.getCursorElements(props)
|
|
141
|
+
];
|
|
142
|
+
}
|
|
143
|
+
};
|
|
144
|
+
|
|
145
|
+
export default cursorContainerMixin(VictoryContainer);
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import PropTypes from "prop-types";
|
|
1
2
|
import React from "react";
|
|
2
3
|
import { VictoryContainer } from "victory-core";
|
|
3
4
|
import SelectionHelpers from "./selection-helpers";
|
|
@@ -6,21 +7,21 @@ export const selectionContainerMixin = (base) => class VictorySelectionContainer
|
|
|
6
7
|
static displayName = "VictorySelectionContainer";
|
|
7
8
|
static propTypes = {
|
|
8
9
|
...VictoryContainer.propTypes,
|
|
9
|
-
|
|
10
|
-
onSelection:
|
|
11
|
-
onSelectionCleared:
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
10
|
+
dimension: PropTypes.oneOf(["x", "y"]),
|
|
11
|
+
onSelection: PropTypes.func,
|
|
12
|
+
onSelectionCleared: PropTypes.func,
|
|
13
|
+
selectionComponent: PropTypes.element,
|
|
14
|
+
selectionStyle: PropTypes.object,
|
|
15
|
+
standalone: PropTypes.bool
|
|
15
16
|
};
|
|
16
17
|
static defaultProps = {
|
|
17
18
|
...VictoryContainer.defaultProps,
|
|
19
|
+
selectionComponent: <rect/>,
|
|
18
20
|
selectionStyle: {
|
|
19
21
|
stroke: "transparent",
|
|
20
22
|
fill: "black",
|
|
21
23
|
fillOpacity: 0.1
|
|
22
|
-
}
|
|
23
|
-
selectionComponent: <rect/>
|
|
24
|
+
}
|
|
24
25
|
};
|
|
25
26
|
|
|
26
27
|
static defaultEvents = [{
|
|
@@ -36,6 +37,8 @@ export const selectionContainerMixin = (base) => class VictorySelectionContainer
|
|
|
36
37
|
this.mouseMoveMutationId = mutations.id; // eslint-disable-line
|
|
37
38
|
return mutations.mutations;
|
|
38
39
|
}
|
|
40
|
+
|
|
41
|
+
return undefined;
|
|
39
42
|
},
|
|
40
43
|
onMouseUp: (evt, targetProps) => {
|
|
41
44
|
return SelectionHelpers.onMouseUp(evt, targetProps);
|
|
@@ -44,20 +47,20 @@ export const selectionContainerMixin = (base) => class VictorySelectionContainer
|
|
|
44
47
|
}];
|
|
45
48
|
|
|
46
49
|
getRect(props) {
|
|
47
|
-
const {x1, x2, y1, y2, selectionStyle, selectionComponent} = props;
|
|
50
|
+
const { x1, x2, y1, y2, selectionStyle, selectionComponent } = props;
|
|
48
51
|
const width = Math.abs(x2 - x1) || 1;
|
|
49
52
|
const height = Math.abs(y2 - y1) || 1;
|
|
50
53
|
const x = Math.min(x1, x2);
|
|
51
54
|
const y = Math.min(y1, y2);
|
|
52
55
|
return y2 && x2 && x1 && y1 ?
|
|
53
|
-
React.cloneElement(selectionComponent, {x, y, width, height, style: selectionStyle}) : null;
|
|
56
|
+
React.cloneElement(selectionComponent, { x, y, width, height, style: selectionStyle }) : null;
|
|
54
57
|
}
|
|
55
58
|
|
|
56
59
|
// Overrides method in VictoryContainer
|
|
57
60
|
getChildren(props) {
|
|
58
61
|
const children = React.Children.toArray(props.children);
|
|
59
62
|
return [...children, this.getRect(props)].map((component, i) => {
|
|
60
|
-
return component ? React.cloneElement(component, {key: i}) : null;
|
|
63
|
+
return component ? React.cloneElement(component, { key: i }) : null;
|
|
61
64
|
});
|
|
62
65
|
}
|
|
63
66
|
};
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
/*eslint no-magic-numbers: ["error", { "ignore": [-1, 0, 1, 2] }]*/
|
|
2
|
+
import PropTypes from "prop-types";
|
|
1
3
|
import React from "react";
|
|
2
4
|
import { VictoryContainer, VictoryTooltip, Helpers, TextSize } from "victory-core";
|
|
3
5
|
import VoronoiHelpers from "./voronoi-helpers";
|
|
@@ -7,14 +9,14 @@ export const voronoiContainerMixin = (base) => class VictoryVoronoiContainer ext
|
|
|
7
9
|
static displayName = "VictoryVoronoiContainer";
|
|
8
10
|
static propTypes = {
|
|
9
11
|
...VictoryContainer.propTypes,
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
12
|
+
dimension: PropTypes.oneOf(["x", "y"]),
|
|
13
|
+
labelComponent: PropTypes.element,
|
|
14
|
+
labels: PropTypes.func,
|
|
15
|
+
onActivated: PropTypes.func,
|
|
16
|
+
onDeactivated: PropTypes.func,
|
|
17
|
+
radius: PropTypes.number,
|
|
18
|
+
standalone: PropTypes.bool,
|
|
19
|
+
voronoiPadding: PropTypes.number
|
|
18
20
|
};
|
|
19
21
|
static defaultProps = {
|
|
20
22
|
...VictoryContainer.defaultProps,
|
|
@@ -35,6 +37,8 @@ export const voronoiContainerMixin = (base) => class VictoryVoronoiContainer ext
|
|
|
35
37
|
this.mouseMoveMutationId = mutations.id; // eslint-disable-line
|
|
36
38
|
return mutations.mutations;
|
|
37
39
|
}
|
|
40
|
+
|
|
41
|
+
return undefined;
|
|
38
42
|
}
|
|
39
43
|
}
|
|
40
44
|
}, {
|
|
@@ -63,19 +67,41 @@ export const voronoiContainerMixin = (base) => class VictoryVoronoiContainer ext
|
|
|
63
67
|
};
|
|
64
68
|
}
|
|
65
69
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
const
|
|
70
|
+
getLabelCornerRadius(props, labelProps) {
|
|
71
|
+
if (typeof labelProps.cornerRadius !== "undefined") {
|
|
72
|
+
return labelProps.cornerRadius;
|
|
73
|
+
}
|
|
74
|
+
const theme = props.theme || labelProps.theme;
|
|
75
|
+
return theme.tooltip && theme.tooltip.cornerRadius || 0;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
getFlyoutExtent(position, props, labelProps) {
|
|
79
|
+
const { text, style } = labelProps;
|
|
80
|
+
const { orientation, dx = 0, dy = 0 } = labelProps;
|
|
81
|
+
const flyoutSize = this.getFlyoutSize(props.labelComponent, text, style);
|
|
82
|
+
const cornerRadius = this.getLabelCornerRadius(props, labelProps);
|
|
83
|
+
const x = position.x + dx + 2 * cornerRadius;
|
|
84
|
+
const y = position.y + dy + 2 * cornerRadius;
|
|
85
|
+
const width = orientation === "top" || orientation === "bottom" ?
|
|
86
|
+
flyoutSize.x / 2 :
|
|
87
|
+
flyoutSize.x;
|
|
88
|
+
const horizontalSign = orientation === "left" ? -1 : 1;
|
|
89
|
+
const verticalSign = orientation === "bottom" ? 1 : -1;
|
|
90
|
+
const extent = {};
|
|
91
|
+
if (orientation === "top" || orientation === "bottom") {
|
|
92
|
+
extent.x = [x - width, x + width];
|
|
93
|
+
} else {
|
|
94
|
+
extent.x = [x, x + horizontalSign * width];
|
|
95
|
+
}
|
|
96
|
+
extent.y = [y, y + verticalSign * flyoutSize.y];
|
|
71
97
|
return {
|
|
72
98
|
x: [Math.min(...extent.x), Math.max(...extent.x)],
|
|
73
99
|
y: [Math.min(...extent.y), Math.max(...extent.y)]
|
|
74
100
|
};
|
|
75
101
|
}
|
|
76
102
|
|
|
77
|
-
getLabelPosition(props, points,
|
|
78
|
-
const { mousePosition, dimension, scale,
|
|
103
|
+
getLabelPosition(props, points, labelProps) {
|
|
104
|
+
const { mousePosition, dimension, scale, voronoiPadding } = props;
|
|
79
105
|
const dataX = points[0]._x1 !== undefined ? points[0]._x1 : points[0]._x;
|
|
80
106
|
const dataY = points[0]._y1 !== undefined ? points[0]._y1 : points[0]._y;
|
|
81
107
|
const basePosition = {
|
|
@@ -88,13 +114,12 @@ export const voronoiContainerMixin = (base) => class VictoryVoronoiContainer ext
|
|
|
88
114
|
|
|
89
115
|
const x = dimension === "y" ? mousePosition.x : basePosition.x;
|
|
90
116
|
const y = dimension === "x" ? mousePosition.y : basePosition.y;
|
|
91
|
-
const flyoutSize = this.getFlyoutSize(labelComponent, text, style);
|
|
92
117
|
const range = { x: scale.x.range(), y: scale.y.range() };
|
|
93
118
|
const extent = {
|
|
94
119
|
x: [Math.min(...range.x) + voronoiPadding, Math.max(...range.x) - voronoiPadding],
|
|
95
120
|
y: [Math.min(...range.y) + voronoiPadding, Math.max(...range.y) - voronoiPadding]
|
|
96
121
|
};
|
|
97
|
-
const flyoutExtent = this.getFlyoutExtent({x, y},
|
|
122
|
+
const flyoutExtent = this.getFlyoutExtent({ x, y }, props, labelProps);
|
|
98
123
|
const adjustments = {
|
|
99
124
|
x: [
|
|
100
125
|
flyoutExtent.x[0] < extent.x[0] ? extent.x[0] - flyoutExtent.x[0] : 0,
|
|
@@ -129,7 +154,7 @@ export const voronoiContainerMixin = (base) => class VictoryVoronoiContainer ext
|
|
|
129
154
|
}
|
|
130
155
|
|
|
131
156
|
getDefaultLabelProps(props, points) {
|
|
132
|
-
const {dimension} = props;
|
|
157
|
+
const { dimension } = props;
|
|
133
158
|
const multiPoint = dimension && points.length > 1;
|
|
134
159
|
return {
|
|
135
160
|
orientation: multiPoint ? "top" : undefined,
|
|
@@ -138,7 +163,7 @@ export const voronoiContainerMixin = (base) => class VictoryVoronoiContainer ext
|
|
|
138
163
|
}
|
|
139
164
|
|
|
140
165
|
getLabelProps(props, points) {
|
|
141
|
-
const {labels, scale, labelComponent, theme} = props;
|
|
166
|
+
const { labels, scale, labelComponent, theme } = props;
|
|
142
167
|
const text = points.reduce((memo, point) => {
|
|
143
168
|
const t = Helpers.evaluateProp(labels, point, true);
|
|
144
169
|
if (t === null || t === undefined) {
|
|
@@ -148,23 +173,23 @@ export const voronoiContainerMixin = (base) => class VictoryVoronoiContainer ext
|
|
|
148
173
|
return memo;
|
|
149
174
|
}, []);
|
|
150
175
|
const style = this.getStyle(props, points, "labels");
|
|
151
|
-
const
|
|
152
|
-
return defaults(
|
|
176
|
+
const labelProps = defaults(
|
|
153
177
|
{
|
|
154
178
|
theme, style, text, scale,
|
|
155
179
|
active: true,
|
|
156
180
|
renderInPortal: false,
|
|
157
181
|
flyoutStyle: this.getStyle(props, points, "flyout")[0],
|
|
158
|
-
datum: omit(points[0], ["childName", "style", "continuous"])
|
|
159
|
-
...labelPosition
|
|
182
|
+
datum: omit(points[0], ["childName", "style", "continuous"])
|
|
160
183
|
},
|
|
161
184
|
labelComponent.props,
|
|
162
185
|
this.getDefaultLabelProps(props, points)
|
|
163
186
|
);
|
|
187
|
+
const labelPosition = this.getLabelPosition(props, points, labelProps);
|
|
188
|
+
return { ...labelProps, ...labelPosition };
|
|
164
189
|
}
|
|
165
190
|
|
|
166
191
|
getTooltip(props) {
|
|
167
|
-
const {labels, activePoints, labelComponent} = props;
|
|
192
|
+
const { labels, activePoints, labelComponent } = props;
|
|
168
193
|
if (!labels) {
|
|
169
194
|
return null;
|
|
170
195
|
}
|
|
@@ -179,7 +204,7 @@ export const voronoiContainerMixin = (base) => class VictoryVoronoiContainer ext
|
|
|
179
204
|
getChildren(props) {
|
|
180
205
|
const children = React.Children.toArray(props.children);
|
|
181
206
|
return [...children, this.getTooltip(props)].map((component, i) => {
|
|
182
|
-
return component ? React.cloneElement(component, {key: i}) : null;
|
|
207
|
+
return component ? React.cloneElement(component, { key: i }) : null;
|
|
183
208
|
});
|
|
184
209
|
}
|
|
185
210
|
};
|
|
@@ -1,25 +1,28 @@
|
|
|
1
|
-
import
|
|
1
|
+
import PropTypes from "prop-types";
|
|
2
|
+
import React from "react";
|
|
2
3
|
import { defaults, isEqual } from "lodash";
|
|
3
4
|
import ZoomHelpers from "./zoom-helpers";
|
|
4
5
|
import { VictoryContainer, VictoryClipContainer, PropTypes as CustomPropTypes } from "victory-core";
|
|
5
6
|
|
|
6
7
|
export const zoomContainerMixin = (base) => class VictoryZoomContainer extends base {
|
|
7
8
|
static displayName = "VictoryZoomContainer";
|
|
9
|
+
|
|
8
10
|
static propTypes = {
|
|
9
11
|
...VictoryContainer.propTypes,
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
}),
|
|
12
|
+
allowZoom: PropTypes.bool,
|
|
13
|
+
clipContainerComponent: PropTypes.element.isRequired,
|
|
14
|
+
dimension: PropTypes.oneOf(["x", "y"]),
|
|
14
15
|
minimumZoom: PropTypes.shape({
|
|
15
16
|
x: PropTypes.number,
|
|
16
17
|
y: PropTypes.number
|
|
17
18
|
}),
|
|
18
19
|
onDomainChange: PropTypes.func,
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
20
|
+
zoomDomain: PropTypes.shape({
|
|
21
|
+
x: CustomPropTypes.domain,
|
|
22
|
+
y: CustomPropTypes.domain
|
|
23
|
+
})
|
|
22
24
|
};
|
|
25
|
+
|
|
23
26
|
static defaultProps = {
|
|
24
27
|
...VictoryContainer.defaultProps,
|
|
25
28
|
clipContainerComponent: <VictoryClipContainer/>,
|
|
@@ -46,6 +49,8 @@ export const zoomContainerMixin = (base) => class VictoryZoomContainer extends b
|
|
|
46
49
|
this.mouseMoveMutationId = mutations.id; // eslint-disable-line
|
|
47
50
|
return mutations.mutations;
|
|
48
51
|
}
|
|
52
|
+
|
|
53
|
+
return undefined;
|
|
49
54
|
},
|
|
50
55
|
onWheel: (evt, targetProps, eventKey, ctx) => { // eslint-disable-line max-params
|
|
51
56
|
evt.preventDefault();
|
|
@@ -55,6 +60,8 @@ export const zoomContainerMixin = (base) => class VictoryZoomContainer extends b
|
|
|
55
60
|
this.wheelMutationId = mutations.id; // eslint-disable-line
|
|
56
61
|
return mutations.mutations;
|
|
57
62
|
}
|
|
63
|
+
|
|
64
|
+
return undefined;
|
|
58
65
|
}
|
|
59
66
|
}
|
|
60
67
|
}];
|
|
@@ -110,14 +117,14 @@ export const zoomContainerMixin = (base) => class VictoryZoomContainer extends b
|
|
|
110
117
|
const childComponents = React.Children.toArray(props.children);
|
|
111
118
|
|
|
112
119
|
return childComponents.map((child) => {
|
|
113
|
-
const {currentDomain} = props;
|
|
120
|
+
const { currentDomain } = props;
|
|
114
121
|
const originalDomain = defaults({}, props.original, props.domain);
|
|
115
122
|
const zoomDomain = defaults({}, props.zoomDomain, props.domain);
|
|
116
123
|
const cachedZoomDomain = defaults({}, props.cachedZoomDomain, props.domain);
|
|
117
124
|
const domain = isEqual(zoomDomain, cachedZoomDomain) ?
|
|
118
125
|
defaults({}, currentDomain, originalDomain) : zoomDomain;
|
|
119
126
|
return React.cloneElement(
|
|
120
|
-
child, defaults({domain}, child.props)
|
|
127
|
+
child, defaults({ domain }, child.props)
|
|
121
128
|
);
|
|
122
129
|
});
|
|
123
130
|
}
|
|
@@ -6,9 +6,9 @@ import { attachId } from "../../helpers/event-handlers.js";
|
|
|
6
6
|
|
|
7
7
|
const VoronoiHelpers = {
|
|
8
8
|
withinBounds(props, point) {
|
|
9
|
-
const {width, height, voronoiPadding} = props;
|
|
9
|
+
const { width, height, voronoiPadding } = props;
|
|
10
10
|
const padding = voronoiPadding || 0;
|
|
11
|
-
const {x, y} = point;
|
|
11
|
+
const { x, y } = point;
|
|
12
12
|
return x >= padding && x <= width - padding && y >= padding && y <= height - padding;
|
|
13
13
|
},
|
|
14
14
|
|
|
@@ -54,7 +54,7 @@ const VoronoiHelpers = {
|
|
|
54
54
|
// returns an array of objects with point and data where point is an x, y coordinate, and data is
|
|
55
55
|
// an array of points belonging to that coordinate
|
|
56
56
|
mergeDatasets(props, datasets) {
|
|
57
|
-
const {scale} = props;
|
|
57
|
+
const { scale } = props;
|
|
58
58
|
const points = groupBy(datasets, (datum) => {
|
|
59
59
|
const x = scale.x(datum ._voronoiX);
|
|
60
60
|
const y = scale.y(datum ._voronoiY);
|
|
@@ -71,7 +71,7 @@ const VoronoiHelpers = {
|
|
|
71
71
|
},
|
|
72
72
|
|
|
73
73
|
getVoronoi(props, mousePosition) {
|
|
74
|
-
const {width, height, voronoiPadding} = props;
|
|
74
|
+
const { width, height, voronoiPadding } = props;
|
|
75
75
|
const padding = voronoiPadding || 0;
|
|
76
76
|
const voronoiFunction = d3Voronoi()
|
|
77
77
|
.x((d) => d.x)
|
|
@@ -84,18 +84,18 @@ const VoronoiHelpers = {
|
|
|
84
84
|
},
|
|
85
85
|
|
|
86
86
|
getActiveMutations(props, point) {
|
|
87
|
-
const {childName, continuous} = point;
|
|
87
|
+
const { childName, continuous } = point;
|
|
88
88
|
const targets = props.labels ? ["data"] : ["data", "labels"];
|
|
89
89
|
return targets.map((target) => {
|
|
90
90
|
const eventKey = continuous === true && target === "data" ? "all" : point.eventKey;
|
|
91
91
|
return {
|
|
92
|
-
childName, eventKey, target, mutation: () => ({active: true })
|
|
92
|
+
childName, eventKey, target, mutation: () => ({ active: true })
|
|
93
93
|
};
|
|
94
94
|
});
|
|
95
95
|
},
|
|
96
96
|
|
|
97
97
|
getInactiveMutations(props, point) {
|
|
98
|
-
const {childName, continuous} = point;
|
|
98
|
+
const { childName, continuous } = point;
|
|
99
99
|
const targets = props.labels ? ["data"] : ["data", "labels"];
|
|
100
100
|
return targets.map((target) => {
|
|
101
101
|
const eventKey = continuous && target === "data" ? "all" : point.eventKey;
|
|
@@ -163,6 +163,6 @@ export default {
|
|
|
163
163
|
onMouseLeave: VoronoiHelpers.onMouseLeave.bind(VoronoiHelpers),
|
|
164
164
|
onMouseMove: throttle(
|
|
165
165
|
attachId(VoronoiHelpers.onMouseMove.bind(VoronoiHelpers)),
|
|
166
|
-
32,
|
|
167
|
-
{leading: true, trailing: false})
|
|
166
|
+
32, // eslint-disable-line no-magic-numbers
|
|
167
|
+
{ leading: true, trailing: false })
|
|
168
168
|
};
|