victory-cursor-container 36.9.2 → 37.0.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 +6 -0
- package/dist/victory-cursor-container.js +1481 -2078
- package/dist/victory-cursor-container.min.js +1 -1
- package/es/cursor-helpers.js +78 -110
- package/es/victory-cursor-container.js +138 -205
- package/lib/cursor-helpers.js +79 -118
- package/lib/index.js +0 -4
- package/lib/victory-cursor-container.js +138 -215
- package/package.json +2 -2
|
@@ -1,220 +1,153 @@
|
|
|
1
1
|
import _isObject from "lodash/isObject";
|
|
2
2
|
import _defaults from "lodash/defaults";
|
|
3
|
-
|
|
4
|
-
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
5
|
-
|
|
6
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
7
|
-
|
|
8
|
-
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
|
9
|
-
|
|
10
|
-
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
11
|
-
|
|
12
|
-
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
13
|
-
|
|
14
|
-
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
|
|
15
|
-
|
|
16
|
-
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
|
|
17
|
-
|
|
18
|
-
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
|
|
19
|
-
|
|
20
|
-
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
21
|
-
|
|
22
|
-
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
23
|
-
|
|
24
|
-
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
|
|
25
|
-
|
|
26
|
-
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
27
|
-
|
|
28
|
-
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
|
|
29
|
-
|
|
30
|
-
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
|
31
|
-
|
|
32
|
-
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
|
|
33
|
-
|
|
34
|
-
function _possibleConstructorReturn(self, call) { if (call && (typeof call === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
|
|
35
|
-
|
|
36
|
-
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
|
37
|
-
|
|
38
|
-
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
|
|
39
|
-
|
|
40
|
-
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
|
41
|
-
|
|
42
3
|
import React from "react";
|
|
43
4
|
import { VictoryContainer, Helpers, VictoryLabel, LineSegment } from "victory-core";
|
|
44
5
|
import { CursorHelpers } from "./cursor-helpers";
|
|
45
6
|
export function cursorContainerMixin(Base) {
|
|
46
|
-
var _class;
|
|
47
|
-
|
|
48
7
|
// @ts-expect-error "TS2545: A mixin class must have a constructor with a single rest parameter of type 'any[]'."
|
|
49
|
-
return
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
}, cursorDimension, defaultCursorValue);
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
return defaultCursorValue;
|
|
80
|
-
}
|
|
81
|
-
}, {
|
|
82
|
-
key: "getCursorLabelOffset",
|
|
83
|
-
value: function getCursorLabelOffset(props) {
|
|
84
|
-
var cursorLabelOffset = props.cursorLabelOffset;
|
|
85
|
-
|
|
86
|
-
if (typeof cursorLabelOffset === "number") {
|
|
87
|
-
return {
|
|
88
|
-
x: cursorLabelOffset,
|
|
89
|
-
y: cursorLabelOffset
|
|
90
|
-
};
|
|
8
|
+
return class VictoryCursorContainer extends Base {
|
|
9
|
+
static displayName = "VictoryCursorContainer";
|
|
10
|
+
static defaultProps = {
|
|
11
|
+
...VictoryContainer.defaultProps,
|
|
12
|
+
cursorLabelComponent: /*#__PURE__*/React.createElement(VictoryLabel, null),
|
|
13
|
+
cursorLabelOffset: {
|
|
14
|
+
x: 5,
|
|
15
|
+
y: -10
|
|
16
|
+
},
|
|
17
|
+
cursorComponent: /*#__PURE__*/React.createElement(LineSegment, null)
|
|
18
|
+
};
|
|
19
|
+
static defaultEvents = props => {
|
|
20
|
+
return [{
|
|
21
|
+
target: "parent",
|
|
22
|
+
eventHandlers: {
|
|
23
|
+
onMouseLeave: (evt, targetProps) => {
|
|
24
|
+
return props.disable ? {} : CursorHelpers.onMouseLeave(evt, targetProps);
|
|
25
|
+
},
|
|
26
|
+
onTouchCancel: () => {
|
|
27
|
+
return [];
|
|
28
|
+
},
|
|
29
|
+
onMouseMove: (evt, targetProps) => {
|
|
30
|
+
return props.disable ? {} : CursorHelpers.onMouseMove(evt, targetProps);
|
|
31
|
+
},
|
|
32
|
+
onTouchMove: (evt, targetProps) => {
|
|
33
|
+
return props.disable ? {} : CursorHelpers.onMouseMove(evt, targetProps);
|
|
34
|
+
}
|
|
91
35
|
}
|
|
92
|
-
|
|
93
|
-
|
|
36
|
+
}];
|
|
37
|
+
};
|
|
38
|
+
getCursorPosition(props) {
|
|
39
|
+
const {
|
|
40
|
+
cursorValue,
|
|
41
|
+
defaultCursorValue,
|
|
42
|
+
domain,
|
|
43
|
+
cursorDimension
|
|
44
|
+
} = props;
|
|
45
|
+
if (cursorValue) {
|
|
46
|
+
return cursorValue;
|
|
94
47
|
}
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
});
|
|
102
|
-
return Helpers.getPadding(child.props);
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
return Helpers.getPadding(props);
|
|
48
|
+
if (typeof defaultCursorValue === "number") {
|
|
49
|
+
return {
|
|
50
|
+
x: (domain.x[0] + domain.x[1]) / 2,
|
|
51
|
+
y: (domain.y[0] + domain.y[1]) / 2,
|
|
52
|
+
[cursorDimension]: defaultCursorValue
|
|
53
|
+
};
|
|
106
54
|
}
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
name = props.name,
|
|
118
|
-
horizontal = props.horizontal,
|
|
119
|
-
theme = props.theme;
|
|
120
|
-
var cursorDimension = CursorHelpers.getDimension(props);
|
|
121
|
-
var cursorValue = this.getCursorPosition(props);
|
|
122
|
-
var cursorLabelOffset = this.getCursorLabelOffset(props);
|
|
123
|
-
|
|
124
|
-
if (!cursorValue) {
|
|
125
|
-
return [];
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
var newElements = [];
|
|
129
|
-
var padding = this.getPadding(props);
|
|
130
|
-
var cursorCoordinates = {
|
|
131
|
-
x: horizontal ? scale.y(cursorValue.y) : scale.x(cursorValue.x),
|
|
132
|
-
y: horizontal ? scale.x(cursorValue.x) : scale.y(cursorValue.y)
|
|
55
|
+
return defaultCursorValue;
|
|
56
|
+
}
|
|
57
|
+
getCursorLabelOffset(props) {
|
|
58
|
+
const {
|
|
59
|
+
cursorLabelOffset
|
|
60
|
+
} = props;
|
|
61
|
+
if (typeof cursorLabelOffset === "number") {
|
|
62
|
+
return {
|
|
63
|
+
x: cursorLabelOffset,
|
|
64
|
+
y: cursorLabelOffset
|
|
133
65
|
};
|
|
134
|
-
|
|
135
|
-
if (cursorLabel) {
|
|
136
|
-
var labelProps = _defaults({
|
|
137
|
-
active: true
|
|
138
|
-
}, cursorLabelComponent.props, {
|
|
139
|
-
x: cursorCoordinates.x + cursorLabelOffset.x,
|
|
140
|
-
y: cursorCoordinates.y + cursorLabelOffset.y,
|
|
141
|
-
datum: cursorValue,
|
|
142
|
-
active: true,
|
|
143
|
-
key: "".concat(name, "-cursor-label")
|
|
144
|
-
});
|
|
145
|
-
|
|
146
|
-
if (Helpers.isTooltip(cursorLabelComponent)) {
|
|
147
|
-
var tooltipTheme = theme && theme.tooltip || {};
|
|
148
|
-
labelProps = _defaults({}, labelProps, tooltipTheme);
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
newElements.push( /*#__PURE__*/React.cloneElement(cursorLabelComponent, _defaults({}, labelProps, {
|
|
152
|
-
text: Helpers.evaluateProp(cursorLabel, labelProps)
|
|
153
|
-
})));
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
var cursorStyle = Object.assign({
|
|
157
|
-
stroke: "black"
|
|
158
|
-
}, cursorComponent.props.style);
|
|
159
|
-
|
|
160
|
-
if (cursorDimension === "x" || cursorDimension === undefined) {
|
|
161
|
-
newElements.push( /*#__PURE__*/React.cloneElement(cursorComponent, {
|
|
162
|
-
key: "".concat(name, "-x-cursor"),
|
|
163
|
-
x1: cursorCoordinates.x,
|
|
164
|
-
x2: cursorCoordinates.x,
|
|
165
|
-
y1: padding.top,
|
|
166
|
-
y2: height - padding.bottom,
|
|
167
|
-
style: cursorStyle
|
|
168
|
-
}));
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
if (cursorDimension === "y" || cursorDimension === undefined) {
|
|
172
|
-
newElements.push( /*#__PURE__*/React.cloneElement(cursorComponent, {
|
|
173
|
-
key: "".concat(name, "-y-cursor"),
|
|
174
|
-
x1: padding.left,
|
|
175
|
-
x2: width - padding.right,
|
|
176
|
-
y1: cursorCoordinates.y,
|
|
177
|
-
y2: cursorCoordinates.y,
|
|
178
|
-
style: cursorStyle
|
|
179
|
-
}));
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
return newElements;
|
|
183
|
-
} // Overrides method in VictoryContainer
|
|
184
|
-
|
|
185
|
-
}, {
|
|
186
|
-
key: "getChildren",
|
|
187
|
-
value: function getChildren(props) {
|
|
188
|
-
return [].concat(_toConsumableArray(React.Children.toArray(props.children)), _toConsumableArray(this.getCursorElements(props)));
|
|
189
66
|
}
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
67
|
+
return cursorLabelOffset;
|
|
68
|
+
}
|
|
69
|
+
getPadding(props) {
|
|
70
|
+
if (props.padding === undefined) {
|
|
71
|
+
const child = props.children.find(c => {
|
|
72
|
+
return _isObject(c.props) && c.props.padding !== undefined;
|
|
73
|
+
});
|
|
74
|
+
return Helpers.getPadding(child.props);
|
|
75
|
+
}
|
|
76
|
+
return Helpers.getPadding(props);
|
|
77
|
+
}
|
|
78
|
+
getCursorElements(props) {
|
|
79
|
+
// eslint-disable-line max-statements
|
|
80
|
+
const {
|
|
81
|
+
scale,
|
|
82
|
+
cursorLabelComponent,
|
|
83
|
+
cursorLabel,
|
|
84
|
+
cursorComponent,
|
|
85
|
+
width,
|
|
86
|
+
height,
|
|
87
|
+
name,
|
|
88
|
+
horizontal,
|
|
89
|
+
theme
|
|
90
|
+
} = props;
|
|
91
|
+
const cursorDimension = CursorHelpers.getDimension(props);
|
|
92
|
+
const cursorValue = this.getCursorPosition(props);
|
|
93
|
+
const cursorLabelOffset = this.getCursorLabelOffset(props);
|
|
94
|
+
if (!cursorValue) {
|
|
95
|
+
return [];
|
|
96
|
+
}
|
|
97
|
+
const newElements = [];
|
|
98
|
+
const padding = this.getPadding(props);
|
|
99
|
+
const cursorCoordinates = {
|
|
100
|
+
x: horizontal ? scale.y(cursorValue.y) : scale.x(cursorValue.x),
|
|
101
|
+
y: horizontal ? scale.x(cursorValue.x) : scale.y(cursorValue.y)
|
|
102
|
+
};
|
|
103
|
+
if (cursorLabel) {
|
|
104
|
+
let labelProps = _defaults({
|
|
105
|
+
active: true
|
|
106
|
+
}, cursorLabelComponent.props, {
|
|
107
|
+
x: cursorCoordinates.x + cursorLabelOffset.x,
|
|
108
|
+
y: cursorCoordinates.y + cursorLabelOffset.y,
|
|
109
|
+
datum: cursorValue,
|
|
110
|
+
active: true,
|
|
111
|
+
key: `${name}-cursor-label`
|
|
112
|
+
});
|
|
113
|
+
if (Helpers.isTooltip(cursorLabelComponent)) {
|
|
114
|
+
const tooltipTheme = theme && theme.tooltip || {};
|
|
115
|
+
labelProps = _defaults({}, labelProps, tooltipTheme);
|
|
215
116
|
}
|
|
117
|
+
newElements.push( /*#__PURE__*/React.cloneElement(cursorLabelComponent, _defaults({}, labelProps, {
|
|
118
|
+
text: Helpers.evaluateProp(cursorLabel, labelProps)
|
|
119
|
+
})));
|
|
120
|
+
}
|
|
121
|
+
const cursorStyle = Object.assign({
|
|
122
|
+
stroke: "black"
|
|
123
|
+
}, cursorComponent.props.style);
|
|
124
|
+
if (cursorDimension === "x" || cursorDimension === undefined) {
|
|
125
|
+
newElements.push( /*#__PURE__*/React.cloneElement(cursorComponent, {
|
|
126
|
+
key: `${name}-x-cursor`,
|
|
127
|
+
x1: cursorCoordinates.x,
|
|
128
|
+
x2: cursorCoordinates.x,
|
|
129
|
+
y1: padding.top,
|
|
130
|
+
y2: height - padding.bottom,
|
|
131
|
+
style: cursorStyle
|
|
132
|
+
}));
|
|
216
133
|
}
|
|
217
|
-
|
|
218
|
-
|
|
134
|
+
if (cursorDimension === "y" || cursorDimension === undefined) {
|
|
135
|
+
newElements.push( /*#__PURE__*/React.cloneElement(cursorComponent, {
|
|
136
|
+
key: `${name}-y-cursor`,
|
|
137
|
+
x1: padding.left,
|
|
138
|
+
x2: width - padding.right,
|
|
139
|
+
y1: cursorCoordinates.y,
|
|
140
|
+
y2: cursorCoordinates.y,
|
|
141
|
+
style: cursorStyle
|
|
142
|
+
}));
|
|
143
|
+
}
|
|
144
|
+
return newElements;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
// Overrides method in VictoryContainer
|
|
148
|
+
getChildren(props) {
|
|
149
|
+
return [...React.Children.toArray(props.children), ...this.getCursorElements(props)];
|
|
150
|
+
}
|
|
151
|
+
};
|
|
219
152
|
}
|
|
220
|
-
export
|
|
153
|
+
export const VictoryCursorContainer = cursorContainerMixin(VictoryContainer);
|
package/lib/cursor-helpers.js
CHANGED
|
@@ -4,129 +4,92 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.CursorHelpers = void 0;
|
|
7
|
-
|
|
8
7
|
var _throttle2 = _interopRequireDefault(require("lodash/throttle"));
|
|
9
|
-
|
|
10
8
|
var _victoryCore = require("victory-core");
|
|
11
|
-
|
|
12
9
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
var _this = this;
|
|
25
|
-
|
|
26
|
-
_classCallCheck(this, CursorHelpersClass);
|
|
27
|
-
|
|
28
|
-
this.handleMouseMove = function (evt, targetProps) {
|
|
29
|
-
var onCursorChange = targetProps.onCursorChange,
|
|
30
|
-
domain = targetProps.domain;
|
|
31
|
-
|
|
32
|
-
var cursorDimension = _this.getDimension(targetProps);
|
|
33
|
-
|
|
34
|
-
var parentSVG = targetProps.parentSVG || _victoryCore.Selection.getParentSVG(evt);
|
|
35
|
-
|
|
36
|
-
var cursorSVGPosition = _victoryCore.Selection.getSVGEventCoordinates(evt, parentSVG);
|
|
37
|
-
|
|
38
|
-
var cursorValue = _victoryCore.Selection.getDataCoordinates(targetProps, targetProps.scale, cursorSVGPosition.x, cursorSVGPosition.y);
|
|
39
|
-
|
|
40
|
-
var inBounds = _this.withinBounds(cursorValue, {
|
|
41
|
-
x1: domain.x[0],
|
|
42
|
-
x2: domain.x[1],
|
|
43
|
-
y1: domain.y[0],
|
|
44
|
-
y2: domain.y[1]
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
if (!inBounds) {
|
|
48
|
-
cursorValue = null;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
if (_victoryCore.Helpers.isFunction(onCursorChange)) {
|
|
52
|
-
if (cursorValue) {
|
|
53
|
-
var value = cursorDimension ? cursorValue[cursorDimension] : cursorValue;
|
|
54
|
-
onCursorChange(value, targetProps);
|
|
55
|
-
} else if (cursorValue !== targetProps.cursorValue) {
|
|
56
|
-
onCursorChange(targetProps.defaultCursorValue || null, targetProps);
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
return [{
|
|
61
|
-
target: "parent",
|
|
62
|
-
eventKey: "parent",
|
|
63
|
-
mutation: function () {
|
|
64
|
-
return {
|
|
65
|
-
cursorValue: cursorValue,
|
|
66
|
-
parentSVG: parentSVG
|
|
67
|
-
};
|
|
68
|
-
}
|
|
69
|
-
}];
|
|
70
|
-
};
|
|
71
|
-
|
|
72
|
-
this.onMouseMove = (0, _throttle2.default)(this.handleMouseMove, ON_MOUSE_MOVE_THROTTLE_MS, {
|
|
73
|
-
leading: true,
|
|
74
|
-
trailing: false
|
|
75
|
-
});
|
|
76
|
-
this.onMouseLeave = this.handleMouseMove;
|
|
77
|
-
|
|
78
|
-
this.onTouchEnd = function (evt, targetProps) {
|
|
79
|
-
var onCursorChange = targetProps.onCursorChange;
|
|
80
|
-
|
|
81
|
-
if (_victoryCore.Helpers.isFunction(targetProps.onCursorChange)) {
|
|
82
|
-
onCursorChange(null, targetProps);
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
return [{
|
|
86
|
-
target: "parent",
|
|
87
|
-
eventKey: "parent",
|
|
88
|
-
mutation: function () {
|
|
89
|
-
return {
|
|
90
|
-
cursorValue: null
|
|
91
|
-
};
|
|
92
|
-
}
|
|
93
|
-
}];
|
|
94
|
-
};
|
|
10
|
+
const ON_MOUSE_MOVE_THROTTLE_MS = 16;
|
|
11
|
+
class CursorHelpersClass {
|
|
12
|
+
getDimension(props) {
|
|
13
|
+
const {
|
|
14
|
+
horizontal,
|
|
15
|
+
cursorDimension
|
|
16
|
+
} = props;
|
|
17
|
+
if (!horizontal || !cursorDimension) {
|
|
18
|
+
return cursorDimension;
|
|
19
|
+
}
|
|
20
|
+
return cursorDimension === "x" ? "y" : "x";
|
|
95
21
|
}
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
22
|
+
withinBounds(point, bounds) {
|
|
23
|
+
const {
|
|
24
|
+
x1,
|
|
25
|
+
x2,
|
|
26
|
+
y1,
|
|
27
|
+
y2
|
|
28
|
+
} = _victoryCore.Helpers.mapValues(bounds, Number);
|
|
29
|
+
const {
|
|
30
|
+
x,
|
|
31
|
+
y
|
|
32
|
+
} = _victoryCore.Helpers.mapValues(point, Number);
|
|
33
|
+
return x >= Math.min(x1, x2) && x <= Math.max(x1, x2) && y >= Math.min(y1, y2) && y <= Math.max(y1, y2);
|
|
34
|
+
}
|
|
35
|
+
handleMouseMove = (evt, targetProps) => {
|
|
36
|
+
const {
|
|
37
|
+
onCursorChange,
|
|
38
|
+
domain
|
|
39
|
+
} = targetProps;
|
|
40
|
+
const cursorDimension = this.getDimension(targetProps);
|
|
41
|
+
const parentSVG = targetProps.parentSVG || _victoryCore.Selection.getParentSVG(evt);
|
|
42
|
+
const cursorSVGPosition = _victoryCore.Selection.getSVGEventCoordinates(evt, parentSVG);
|
|
43
|
+
let cursorValue = _victoryCore.Selection.getDataCoordinates(targetProps, targetProps.scale, cursorSVGPosition.x, cursorSVGPosition.y);
|
|
44
|
+
const inBounds = this.withinBounds(cursorValue, {
|
|
45
|
+
x1: domain.x[0],
|
|
46
|
+
x2: domain.x[1],
|
|
47
|
+
y1: domain.y[0],
|
|
48
|
+
y2: domain.y[1]
|
|
49
|
+
});
|
|
50
|
+
if (!inBounds) {
|
|
51
|
+
cursorValue = null;
|
|
52
|
+
}
|
|
53
|
+
if (_victoryCore.Helpers.isFunction(onCursorChange)) {
|
|
54
|
+
if (cursorValue) {
|
|
55
|
+
const value = cursorDimension ? cursorValue[cursorDimension] : cursorValue;
|
|
56
|
+
onCursorChange(value, targetProps);
|
|
57
|
+
} else if (cursorValue !== targetProps.cursorValue) {
|
|
58
|
+
onCursorChange(targetProps.defaultCursorValue || null, targetProps);
|
|
105
59
|
}
|
|
106
|
-
|
|
107
|
-
return cursorDimension === "x" ? "y" : "x";
|
|
108
60
|
}
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
61
|
+
return [{
|
|
62
|
+
target: "parent",
|
|
63
|
+
eventKey: "parent",
|
|
64
|
+
mutation: () => ({
|
|
65
|
+
cursorValue,
|
|
66
|
+
parentSVG
|
|
67
|
+
})
|
|
68
|
+
}];
|
|
69
|
+
};
|
|
70
|
+
onMouseMove = (0, _throttle2.default)(this.handleMouseMove, ON_MOUSE_MOVE_THROTTLE_MS, {
|
|
71
|
+
leading: true,
|
|
72
|
+
trailing: false
|
|
73
|
+
});
|
|
74
|
+
onMouseLeave = this.handleMouseMove;
|
|
75
|
+
onTouchEnd = (evt, targetProps) => {
|
|
76
|
+
const {
|
|
77
|
+
onCursorChange
|
|
78
|
+
} = targetProps;
|
|
79
|
+
if (_victoryCore.Helpers.isFunction(targetProps.onCursorChange)) {
|
|
80
|
+
onCursorChange(null, targetProps);
|
|
123
81
|
}
|
|
124
|
-
|
|
82
|
+
return [{
|
|
83
|
+
target: "parent",
|
|
84
|
+
eventKey: "parent",
|
|
85
|
+
mutation: () => ({
|
|
86
|
+
cursorValue: null
|
|
87
|
+
})
|
|
88
|
+
}];
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
const CursorHelpers = exports.CursorHelpers = new CursorHelpersClass();
|
|
125
92
|
|
|
126
|
-
return CursorHelpersClass;
|
|
127
|
-
}();
|
|
128
|
-
|
|
129
|
-
var CursorHelpers = new CursorHelpersClass();
|
|
130
93
|
/* {
|
|
131
94
|
...CursorHelpers,
|
|
132
95
|
onMouseMove: throttle(
|
|
@@ -142,6 +105,4 @@ var CursorHelpers = new CursorHelpersClass();
|
|
|
142
105
|
};
|
|
143
106
|
|
|
144
107
|
|
|
145
|
-
*/
|
|
146
|
-
|
|
147
|
-
exports.CursorHelpers = CursorHelpers;
|
|
108
|
+
*/
|
package/lib/index.js
CHANGED
|
@@ -3,9 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
|
|
7
6
|
var _cursorHelpers = require("./cursor-helpers");
|
|
8
|
-
|
|
9
7
|
Object.keys(_cursorHelpers).forEach(function (key) {
|
|
10
8
|
if (key === "default" || key === "__esModule") return;
|
|
11
9
|
if (key in exports && exports[key] === _cursorHelpers[key]) return;
|
|
@@ -16,9 +14,7 @@ Object.keys(_cursorHelpers).forEach(function (key) {
|
|
|
16
14
|
}
|
|
17
15
|
});
|
|
18
16
|
});
|
|
19
|
-
|
|
20
17
|
var _victoryCursorContainer = require("./victory-cursor-container");
|
|
21
|
-
|
|
22
18
|
Object.keys(_victoryCursorContainer).forEach(function (key) {
|
|
23
19
|
if (key === "default" || key === "__esModule") return;
|
|
24
20
|
if (key in exports && exports[key] === _victoryCursorContainer[key]) return;
|