victory-cursor-container 37.0.2 → 37.1.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/CHANGELOG.md +8 -0
- package/dist/victory-cursor-container.js +451 -740
- package/dist/victory-cursor-container.min.js +1 -1
- package/es/victory-cursor-container.d.ts +63 -112
- package/es/victory-cursor-container.js +155 -140
- package/lib/victory-cursor-container.d.ts +63 -112
- package/lib/victory-cursor-container.js +158 -141
- package/package.json +2 -2
- package/src/victory-cursor-container.tsx +185 -164
|
@@ -3,159 +3,176 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.VictoryCursorContainer = void 0;
|
|
7
|
-
exports.cursorContainerMixin = cursorContainerMixin;
|
|
6
|
+
exports.useVictoryCursorContainer = exports.VictoryCursorContainer = exports.VICTORY_CURSOR_CONTAINER_DEFAULT_PROPS = void 0;
|
|
8
7
|
var _isObject2 = _interopRequireDefault(require("lodash/isObject"));
|
|
9
8
|
var _defaults2 = _interopRequireDefault(require("lodash/defaults"));
|
|
10
9
|
var _react = _interopRequireDefault(require("react"));
|
|
11
10
|
var _victoryCore = require("victory-core");
|
|
12
11
|
var _cursorHelpers = require("./cursor-helpers");
|
|
13
12
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
return props.disable ? {} : _cursorHelpers.CursorHelpers.onMouseMove(evt, targetProps);
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
}];
|
|
13
|
+
/* eslint-disable complexity */
|
|
14
|
+
|
|
15
|
+
const VICTORY_CURSOR_CONTAINER_DEFAULT_PROPS = exports.VICTORY_CURSOR_CONTAINER_DEFAULT_PROPS = {
|
|
16
|
+
cursorLabelComponent: /*#__PURE__*/_react.default.createElement(_victoryCore.VictoryLabel, null),
|
|
17
|
+
cursorLabelOffset: {
|
|
18
|
+
x: 5,
|
|
19
|
+
y: -10
|
|
20
|
+
},
|
|
21
|
+
cursorComponent: /*#__PURE__*/_react.default.createElement(_victoryCore.LineSegment, null)
|
|
22
|
+
};
|
|
23
|
+
const useVictoryCursorContainer = initialProps => {
|
|
24
|
+
const props = {
|
|
25
|
+
...VICTORY_CURSOR_CONTAINER_DEFAULT_PROPS,
|
|
26
|
+
...initialProps
|
|
27
|
+
};
|
|
28
|
+
const {
|
|
29
|
+
children
|
|
30
|
+
} = props;
|
|
31
|
+
const getCursorPosition = () => {
|
|
32
|
+
const {
|
|
33
|
+
cursorValue,
|
|
34
|
+
defaultCursorValue,
|
|
35
|
+
domain,
|
|
36
|
+
cursorDimension
|
|
37
|
+
} = props;
|
|
38
|
+
if (cursorValue) {
|
|
39
|
+
return cursorValue;
|
|
45
40
|
}
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
cursorDimension
|
|
52
|
-
} = props;
|
|
53
|
-
if (cursorValue) {
|
|
54
|
-
return cursorValue;
|
|
55
|
-
}
|
|
56
|
-
if (typeof defaultCursorValue === "number") {
|
|
57
|
-
return {
|
|
58
|
-
x: (domain.x[0] + domain.x[1]) / 2,
|
|
59
|
-
y: (domain.y[0] + domain.y[1]) / 2,
|
|
41
|
+
if (typeof defaultCursorValue === "number") {
|
|
42
|
+
return {
|
|
43
|
+
x: (domain.x[0] + domain.x[1]) / 2,
|
|
44
|
+
y: (domain.y[0] + domain.y[1]) / 2,
|
|
45
|
+
...(cursorDimension ? {
|
|
60
46
|
[cursorDimension]: defaultCursorValue
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
return defaultCursorValue;
|
|
47
|
+
} : {})
|
|
48
|
+
};
|
|
64
49
|
}
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
50
|
+
return defaultCursorValue;
|
|
51
|
+
};
|
|
52
|
+
const getCursorLabelOffset = () => {
|
|
53
|
+
const {
|
|
54
|
+
cursorLabelOffset
|
|
55
|
+
} = props;
|
|
56
|
+
if (typeof cursorLabelOffset === "number") {
|
|
57
|
+
return {
|
|
58
|
+
x: cursorLabelOffset,
|
|
59
|
+
y: cursorLabelOffset
|
|
60
|
+
};
|
|
76
61
|
}
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
return
|
|
83
|
-
}
|
|
84
|
-
return _victoryCore.Helpers.getPadding(props);
|
|
62
|
+
return cursorLabelOffset;
|
|
63
|
+
};
|
|
64
|
+
const getPadding = () => {
|
|
65
|
+
if (props.padding === undefined) {
|
|
66
|
+
const child = Array.isArray(props.children) ? props.children.find(c => {
|
|
67
|
+
return (0, _isObject2.default)(c.props) && c.props.padding !== undefined;
|
|
68
|
+
}) : props.children;
|
|
69
|
+
return _victoryCore.Helpers.getPadding(child?.props);
|
|
85
70
|
}
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
const cursorStyle = Object.assign({
|
|
130
|
-
stroke: "black"
|
|
131
|
-
}, cursorComponent.props.style);
|
|
132
|
-
if (cursorDimension === "x" || cursorDimension === undefined) {
|
|
133
|
-
newElements.push( /*#__PURE__*/_react.default.cloneElement(cursorComponent, {
|
|
134
|
-
key: `${name}-x-cursor`,
|
|
135
|
-
x1: cursorCoordinates.x,
|
|
136
|
-
x2: cursorCoordinates.x,
|
|
137
|
-
y1: padding.top,
|
|
138
|
-
y2: height - padding.bottom,
|
|
139
|
-
style: cursorStyle
|
|
140
|
-
}));
|
|
141
|
-
}
|
|
142
|
-
if (cursorDimension === "y" || cursorDimension === undefined) {
|
|
143
|
-
newElements.push( /*#__PURE__*/_react.default.cloneElement(cursorComponent, {
|
|
144
|
-
key: `${name}-y-cursor`,
|
|
145
|
-
x1: padding.left,
|
|
146
|
-
x2: width - padding.right,
|
|
147
|
-
y1: cursorCoordinates.y,
|
|
148
|
-
y2: cursorCoordinates.y,
|
|
149
|
-
style: cursorStyle
|
|
150
|
-
}));
|
|
71
|
+
return _victoryCore.Helpers.getPadding(props);
|
|
72
|
+
};
|
|
73
|
+
const getCursorElements = () => {
|
|
74
|
+
// eslint-disable-line max-statements
|
|
75
|
+
const {
|
|
76
|
+
scale,
|
|
77
|
+
cursorLabelComponent,
|
|
78
|
+
cursorLabel,
|
|
79
|
+
cursorComponent,
|
|
80
|
+
width,
|
|
81
|
+
height,
|
|
82
|
+
name,
|
|
83
|
+
horizontal,
|
|
84
|
+
theme
|
|
85
|
+
} = props;
|
|
86
|
+
const cursorDimension = _cursorHelpers.CursorHelpers.getDimension(props);
|
|
87
|
+
const cursorValue = getCursorPosition();
|
|
88
|
+
const cursorLabelOffset = getCursorLabelOffset();
|
|
89
|
+
if (!cursorValue) {
|
|
90
|
+
return [];
|
|
91
|
+
}
|
|
92
|
+
const newElements = [];
|
|
93
|
+
const padding = getPadding();
|
|
94
|
+
const cursorCoordinates = scale && "x" in scale && "y" in scale && typeof scale.y === "function" && typeof scale.x === "function" ? {
|
|
95
|
+
x: horizontal ? scale.y(cursorValue.y) : scale.x(cursorValue.x),
|
|
96
|
+
y: horizontal ? scale.x(cursorValue.x) : scale.y(cursorValue.y)
|
|
97
|
+
} : {
|
|
98
|
+
x: cursorValue.x,
|
|
99
|
+
y: cursorValue.y
|
|
100
|
+
};
|
|
101
|
+
if (cursorLabel) {
|
|
102
|
+
let labelProps = (0, _defaults2.default)({
|
|
103
|
+
active: true
|
|
104
|
+
}, cursorLabelComponent.props, {
|
|
105
|
+
x: cursorCoordinates.x + cursorLabelOffset.x,
|
|
106
|
+
y: cursorCoordinates.y + cursorLabelOffset.y,
|
|
107
|
+
datum: cursorValue,
|
|
108
|
+
active: true,
|
|
109
|
+
key: `${name}-cursor-label`
|
|
110
|
+
});
|
|
111
|
+
if (_victoryCore.Helpers.isTooltip(cursorLabelComponent)) {
|
|
112
|
+
const tooltipTheme = theme && theme.tooltip || {};
|
|
113
|
+
labelProps = (0, _defaults2.default)({}, labelProps, tooltipTheme);
|
|
151
114
|
}
|
|
152
|
-
|
|
115
|
+
newElements.push( /*#__PURE__*/_react.default.cloneElement(cursorLabelComponent, (0, _defaults2.default)({}, labelProps, {
|
|
116
|
+
text: _victoryCore.Helpers.evaluateProp(cursorLabel, labelProps)
|
|
117
|
+
})));
|
|
153
118
|
}
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
119
|
+
const cursorStyle = Object.assign({
|
|
120
|
+
stroke: "black"
|
|
121
|
+
}, cursorComponent.props.style);
|
|
122
|
+
if (cursorDimension === "x" || cursorDimension === undefined) {
|
|
123
|
+
newElements.push( /*#__PURE__*/_react.default.cloneElement(cursorComponent, {
|
|
124
|
+
key: `${name}-x-cursor`,
|
|
125
|
+
x1: cursorCoordinates.x,
|
|
126
|
+
x2: cursorCoordinates.x,
|
|
127
|
+
y1: padding.top,
|
|
128
|
+
y2: (typeof height === "number" ? height : 0) - padding.bottom,
|
|
129
|
+
style: cursorStyle
|
|
130
|
+
}));
|
|
131
|
+
}
|
|
132
|
+
if (cursorDimension === "y" || cursorDimension === undefined) {
|
|
133
|
+
newElements.push( /*#__PURE__*/_react.default.cloneElement(cursorComponent, {
|
|
134
|
+
key: `${name}-y-cursor`,
|
|
135
|
+
x1: padding.left,
|
|
136
|
+
x2: (typeof width === "number" ? width : 0) - padding.right,
|
|
137
|
+
y1: cursorCoordinates.y,
|
|
138
|
+
y2: cursorCoordinates.y,
|
|
139
|
+
style: cursorStyle
|
|
140
|
+
}));
|
|
158
141
|
}
|
|
142
|
+
return newElements;
|
|
143
|
+
};
|
|
144
|
+
return {
|
|
145
|
+
props,
|
|
146
|
+
children: [..._react.default.Children.toArray(children), ...getCursorElements()]
|
|
159
147
|
};
|
|
160
|
-
}
|
|
161
|
-
|
|
148
|
+
};
|
|
149
|
+
exports.useVictoryCursorContainer = useVictoryCursorContainer;
|
|
150
|
+
const VictoryCursorContainer = initialProps => {
|
|
151
|
+
const {
|
|
152
|
+
props,
|
|
153
|
+
children
|
|
154
|
+
} = useVictoryCursorContainer(initialProps);
|
|
155
|
+
return /*#__PURE__*/_react.default.createElement(_victoryCore.VictoryContainer, props, children);
|
|
156
|
+
};
|
|
157
|
+
exports.VictoryCursorContainer = VictoryCursorContainer;
|
|
158
|
+
VictoryCursorContainer.role = "container";
|
|
159
|
+
VictoryCursorContainer.defaultEvents = initialProps => {
|
|
160
|
+
const props = {
|
|
161
|
+
...VICTORY_CURSOR_CONTAINER_DEFAULT_PROPS,
|
|
162
|
+
...initialProps
|
|
163
|
+
};
|
|
164
|
+
const createEventHandler = (handler, disabled) =>
|
|
165
|
+
// eslint-disable-next-line max-params
|
|
166
|
+
(event, targetProps, eventKey, context) => disabled || props.disable ? {} : handler(event, {
|
|
167
|
+
...props,
|
|
168
|
+
...targetProps
|
|
169
|
+
}, eventKey, context);
|
|
170
|
+
return [{
|
|
171
|
+
target: "parent",
|
|
172
|
+
eventHandlers: {
|
|
173
|
+
onMouseLeave: createEventHandler(_cursorHelpers.CursorHelpers.onMouseLeave),
|
|
174
|
+
onMouseMove: createEventHandler(_cursorHelpers.CursorHelpers.onMouseMove),
|
|
175
|
+
onTouchMove: createEventHandler(_cursorHelpers.CursorHelpers.onMouseMove)
|
|
176
|
+
}
|
|
177
|
+
}];
|
|
178
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "victory-cursor-container",
|
|
3
|
-
"version": "37.0
|
|
3
|
+
"version": "37.1.0",
|
|
4
4
|
"description": "Interactive Cursor Component for Victory",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"data visualization",
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
"license": "MIT",
|
|
22
22
|
"dependencies": {
|
|
23
23
|
"lodash": "^4.17.19",
|
|
24
|
-
"victory-core": "
|
|
24
|
+
"victory-core": "37.1.0"
|
|
25
25
|
},
|
|
26
26
|
"peerDependencies": {
|
|
27
27
|
"react": ">=16.6.0"
|