victory-cursor-container 30.6.1 → 31.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +11 -11
- package/dist/victory-cursor-container.js +1046 -805
- package/dist/victory-cursor-container.min.js +1 -1
- package/package.json +2 -2
- package/src/cursor-helpers.js +20 -13
- package/src/victory-cursor-container.js +153 -137
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "victory-cursor-container",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "31.2.0",
|
|
4
4
|
"description": "Interactive Cursor Component for Victory",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"data visualization",
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
"dependencies": {
|
|
22
22
|
"lodash": "^4.17.5",
|
|
23
23
|
"prop-types": "^15.5.8",
|
|
24
|
-
"victory-core": "^
|
|
24
|
+
"victory-core": "^31.2.0"
|
|
25
25
|
},
|
|
26
26
|
"scripts": {
|
|
27
27
|
"version": "nps build-libs && nps build-dists"
|
package/src/cursor-helpers.js
CHANGED
|
@@ -5,10 +5,12 @@ const CursorHelpers = {
|
|
|
5
5
|
withinBounds(point, bounds) {
|
|
6
6
|
const { x1, x2, y1, y2 } = mapValues(bounds, Number);
|
|
7
7
|
const { x, y } = mapValues(point, Number);
|
|
8
|
-
return
|
|
8
|
+
return (
|
|
9
|
+
x >= Math.min(x1, x2) &&
|
|
9
10
|
x <= Math.max(x1, x2) &&
|
|
10
11
|
y >= Math.min(y1, y2) &&
|
|
11
|
-
y <= Math.max(y1, y2)
|
|
12
|
+
y <= Math.max(y1, y2)
|
|
13
|
+
);
|
|
12
14
|
},
|
|
13
15
|
|
|
14
16
|
onMouseMove(evt, targetProps) {
|
|
@@ -42,11 +44,13 @@ const CursorHelpers = {
|
|
|
42
44
|
}
|
|
43
45
|
}
|
|
44
46
|
|
|
45
|
-
return [
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
47
|
+
return [
|
|
48
|
+
{
|
|
49
|
+
target: "parent",
|
|
50
|
+
eventKey: "parent",
|
|
51
|
+
mutation: () => ({ cursorValue, parentSVG })
|
|
52
|
+
}
|
|
53
|
+
];
|
|
50
54
|
},
|
|
51
55
|
|
|
52
56
|
onTouchEnd(evt, targetProps) {
|
|
@@ -56,11 +60,13 @@ const CursorHelpers = {
|
|
|
56
60
|
onCursorChange(null, targetProps);
|
|
57
61
|
}
|
|
58
62
|
|
|
59
|
-
return [
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
63
|
+
return [
|
|
64
|
+
{
|
|
65
|
+
target: "parent",
|
|
66
|
+
eventKey: "parent",
|
|
67
|
+
mutation: () => ({ cursorValue: null })
|
|
68
|
+
}
|
|
69
|
+
];
|
|
64
70
|
}
|
|
65
71
|
};
|
|
66
72
|
|
|
@@ -68,6 +74,7 @@ export default {
|
|
|
68
74
|
onMouseMove: throttle(
|
|
69
75
|
CursorHelpers.onMouseMove.bind(CursorHelpers),
|
|
70
76
|
32, // eslint-disable-line no-magic-numbers
|
|
71
|
-
{ leading: true, trailing: false }
|
|
77
|
+
{ leading: true, trailing: false }
|
|
78
|
+
),
|
|
72
79
|
onTouchEnd: CursorHelpers.onTouchEnd.bind(CursorHelpers)
|
|
73
80
|
};
|
|
@@ -4,160 +4,176 @@ import { VictoryContainer, VictoryLabel, LineSegment, Helpers } from "victory-co
|
|
|
4
4
|
import { defaults, assign, isObject } from "lodash";
|
|
5
5
|
import CursorHelpers from "./cursor-helpers";
|
|
6
6
|
|
|
7
|
-
export const cursorContainerMixin = (base) =>
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
PropTypes.
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
PropTypes.
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
7
|
+
export const cursorContainerMixin = (base) =>
|
|
8
|
+
class VictoryCursorContainer extends base {
|
|
9
|
+
static displayName = "VictoryCursorContainer";
|
|
10
|
+
static propTypes = {
|
|
11
|
+
...VictoryContainer.propTypes,
|
|
12
|
+
cursorDimension: PropTypes.oneOf(["x", "y"]),
|
|
13
|
+
cursorLabel: PropTypes.func,
|
|
14
|
+
cursorLabelComponent: PropTypes.element,
|
|
15
|
+
cursorLabelOffset: PropTypes.oneOfType([
|
|
16
|
+
PropTypes.number,
|
|
17
|
+
PropTypes.shape({
|
|
18
|
+
x: PropTypes.number,
|
|
19
|
+
y: PropTypes.number
|
|
20
|
+
})
|
|
21
|
+
]),
|
|
22
|
+
defaultCursorValue: PropTypes.oneOfType([
|
|
23
|
+
PropTypes.number,
|
|
24
|
+
PropTypes.shape({
|
|
25
|
+
x: PropTypes.number,
|
|
26
|
+
y: PropTypes.number
|
|
27
|
+
})
|
|
28
|
+
]),
|
|
29
|
+
disable: PropTypes.bool,
|
|
30
|
+
onCursorChange: PropTypes.func
|
|
31
|
+
};
|
|
32
|
+
static defaultProps = {
|
|
33
|
+
...VictoryContainer.defaultProps,
|
|
34
|
+
cursorLabelComponent: <VictoryLabel />,
|
|
35
|
+
cursorLabelOffset: {
|
|
36
|
+
x: 5,
|
|
37
|
+
y: -10
|
|
38
|
+
},
|
|
39
|
+
cursorComponent: <LineSegment />
|
|
40
|
+
};
|
|
40
41
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
42
|
+
static defaultEvents = (props) => {
|
|
43
|
+
return [
|
|
44
|
+
{
|
|
45
|
+
target: "parent",
|
|
46
|
+
eventHandlers: {
|
|
47
|
+
onMouseLeave: () => {
|
|
48
|
+
return [];
|
|
49
|
+
},
|
|
50
|
+
onTouchCancel: () => {
|
|
51
|
+
return [];
|
|
52
|
+
},
|
|
53
|
+
onMouseMove: (evt, targetProps) => {
|
|
54
|
+
return props.disable ? {} : CursorHelpers.onMouseMove(evt, targetProps);
|
|
55
|
+
},
|
|
56
|
+
onTouchMove: (evt, targetProps) => {
|
|
57
|
+
return props.disable ? {} : CursorHelpers.onMouseMove(evt, targetProps);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
56
60
|
}
|
|
61
|
+
];
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
getCursorPosition(props) {
|
|
65
|
+
const { cursorValue, defaultCursorValue, cursorDimension, domain } = props;
|
|
66
|
+
if (cursorValue) {
|
|
67
|
+
return cursorValue;
|
|
57
68
|
}
|
|
58
|
-
}];
|
|
59
|
-
};
|
|
60
69
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
70
|
+
if (typeof defaultCursorValue === "number") {
|
|
71
|
+
return {
|
|
72
|
+
x: (domain.x[0] + domain.x[1]) / 2,
|
|
73
|
+
y: (domain.y[0] + domain.y[1]) / 2,
|
|
74
|
+
[cursorDimension]: defaultCursorValue
|
|
75
|
+
};
|
|
76
|
+
}
|
|
64
77
|
|
|
65
|
-
|
|
66
|
-
return {
|
|
67
|
-
x: (domain.x[0] + domain.x[1]) / 2,
|
|
68
|
-
y: (domain.y[0] + domain.y[1]) / 2,
|
|
69
|
-
[cursorDimension]: defaultCursorValue
|
|
70
|
-
};
|
|
78
|
+
return defaultCursorValue;
|
|
71
79
|
}
|
|
72
80
|
|
|
73
|
-
|
|
74
|
-
|
|
81
|
+
getCursorLabelOffset(props) {
|
|
82
|
+
const { cursorLabelOffset } = props;
|
|
75
83
|
|
|
76
|
-
|
|
77
|
-
|
|
84
|
+
if (typeof cursorLabelOffset === "number") {
|
|
85
|
+
return {
|
|
86
|
+
x: cursorLabelOffset,
|
|
87
|
+
y: cursorLabelOffset
|
|
88
|
+
};
|
|
89
|
+
}
|
|
78
90
|
|
|
79
|
-
|
|
80
|
-
return {
|
|
81
|
-
x: cursorLabelOffset,
|
|
82
|
-
y: cursorLabelOffset
|
|
83
|
-
};
|
|
91
|
+
return cursorLabelOffset;
|
|
84
92
|
}
|
|
85
93
|
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
} else {
|
|
96
|
-
return Helpers.getPadding(props);
|
|
94
|
+
getPadding(props) {
|
|
95
|
+
if (props.padding === undefined) {
|
|
96
|
+
const child = props.children.find((c) => {
|
|
97
|
+
return isObject(c.props) && c.props.padding !== undefined;
|
|
98
|
+
});
|
|
99
|
+
return Helpers.getPadding(child.props);
|
|
100
|
+
} else {
|
|
101
|
+
return Helpers.getPadding(props);
|
|
102
|
+
}
|
|
97
103
|
}
|
|
98
|
-
}
|
|
99
104
|
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
105
|
+
getCursorElements(props) {
|
|
106
|
+
// eslint-disable-line max-statements
|
|
107
|
+
const {
|
|
108
|
+
scale,
|
|
109
|
+
cursorDimension,
|
|
110
|
+
cursorLabelComponent,
|
|
111
|
+
cursorLabel,
|
|
112
|
+
cursorComponent,
|
|
113
|
+
width,
|
|
114
|
+
height,
|
|
115
|
+
name
|
|
116
|
+
} = props;
|
|
117
|
+
const cursorValue = this.getCursorPosition(props);
|
|
118
|
+
const cursorLabelOffset = this.getCursorLabelOffset(props);
|
|
107
119
|
|
|
108
|
-
|
|
120
|
+
if (!cursorValue) {
|
|
121
|
+
return [];
|
|
122
|
+
}
|
|
109
123
|
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
));
|
|
131
|
-
}
|
|
124
|
+
const newElements = [];
|
|
125
|
+
const padding = this.getPadding(props);
|
|
126
|
+
const cursorCoordinates = {
|
|
127
|
+
x: scale.x(cursorValue.x),
|
|
128
|
+
y: scale.y(cursorValue.y)
|
|
129
|
+
};
|
|
130
|
+
if (cursorLabel) {
|
|
131
|
+
newElements.push(
|
|
132
|
+
React.cloneElement(
|
|
133
|
+
cursorLabelComponent,
|
|
134
|
+
defaults({ active: true }, cursorLabelComponent.props, {
|
|
135
|
+
x: cursorCoordinates.x + cursorLabelOffset.x,
|
|
136
|
+
y: cursorCoordinates.y + cursorLabelOffset.y,
|
|
137
|
+
text: Helpers.evaluateProp(cursorLabel, cursorValue, true),
|
|
138
|
+
active: true,
|
|
139
|
+
key: `${name}-cursor-label`
|
|
140
|
+
})
|
|
141
|
+
)
|
|
142
|
+
);
|
|
143
|
+
}
|
|
132
144
|
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
145
|
+
const cursorStyle = assign({ stroke: "black" }, cursorComponent.props.style);
|
|
146
|
+
if (cursorDimension === "x" || cursorDimension === undefined) {
|
|
147
|
+
newElements.push(
|
|
148
|
+
React.cloneElement(cursorComponent, {
|
|
149
|
+
key: `${name}-x-cursor`,
|
|
150
|
+
x1: cursorCoordinates.x,
|
|
151
|
+
x2: cursorCoordinates.x,
|
|
152
|
+
y1: padding.top,
|
|
153
|
+
y2: height - padding.bottom,
|
|
154
|
+
style: cursorStyle
|
|
155
|
+
})
|
|
156
|
+
);
|
|
157
|
+
}
|
|
158
|
+
if (cursorDimension === "y" || cursorDimension === undefined) {
|
|
159
|
+
newElements.push(
|
|
160
|
+
React.cloneElement(cursorComponent, {
|
|
161
|
+
key: `${name}-y-cursor`,
|
|
162
|
+
x1: padding.left,
|
|
163
|
+
x2: width - padding.right,
|
|
164
|
+
y1: cursorCoordinates.y,
|
|
165
|
+
y2: cursorCoordinates.y,
|
|
166
|
+
style: cursorStyle
|
|
167
|
+
})
|
|
168
|
+
);
|
|
169
|
+
}
|
|
170
|
+
return newElements;
|
|
153
171
|
}
|
|
154
|
-
return newElements;
|
|
155
|
-
}
|
|
156
172
|
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
};
|
|
173
|
+
// Overrides method in VictoryContainer
|
|
174
|
+
getChildren(props) {
|
|
175
|
+
return [...React.Children.toArray(props.children), ...this.getCursorElements(props)];
|
|
176
|
+
}
|
|
177
|
+
};
|
|
162
178
|
|
|
163
179
|
export default cursorContainerMixin(VictoryContainer);
|