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
|
@@ -5,234 +5,157 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.VictoryCursorContainer = void 0;
|
|
7
7
|
exports.cursorContainerMixin = cursorContainerMixin;
|
|
8
|
-
|
|
9
8
|
var _isObject2 = _interopRequireDefault(require("lodash/isObject"));
|
|
10
|
-
|
|
11
9
|
var _defaults2 = _interopRequireDefault(require("lodash/defaults"));
|
|
12
|
-
|
|
13
10
|
var _react = _interopRequireDefault(require("react"));
|
|
14
|
-
|
|
15
11
|
var _victoryCore = require("victory-core");
|
|
16
|
-
|
|
17
12
|
var _cursorHelpers = require("./cursor-helpers");
|
|
18
|
-
|
|
19
13
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
20
|
-
|
|
21
|
-
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; }
|
|
22
|
-
|
|
23
|
-
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; }
|
|
24
|
-
|
|
25
|
-
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
|
26
|
-
|
|
27
|
-
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."); }
|
|
28
|
-
|
|
29
|
-
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); }
|
|
30
|
-
|
|
31
|
-
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
|
|
32
|
-
|
|
33
|
-
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
|
|
34
|
-
|
|
35
|
-
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; }
|
|
36
|
-
|
|
37
|
-
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; }
|
|
38
|
-
|
|
39
|
-
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
40
|
-
|
|
41
|
-
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); } }
|
|
42
|
-
|
|
43
|
-
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
44
|
-
|
|
45
|
-
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); }
|
|
46
|
-
|
|
47
|
-
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
|
48
|
-
|
|
49
|
-
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); }; }
|
|
50
|
-
|
|
51
|
-
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); }
|
|
52
|
-
|
|
53
|
-
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
|
54
|
-
|
|
55
|
-
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; } }
|
|
56
|
-
|
|
57
|
-
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
|
58
|
-
|
|
59
14
|
function cursorContainerMixin(Base) {
|
|
60
|
-
var _class;
|
|
61
|
-
|
|
62
15
|
// @ts-expect-error "TS2545: A mixin class must have a constructor with a single rest parameter of type 'any[]'."
|
|
63
|
-
return
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
}, cursorDimension, defaultCursorValue);
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
return defaultCursorValue;
|
|
94
|
-
}
|
|
95
|
-
}, {
|
|
96
|
-
key: "getCursorLabelOffset",
|
|
97
|
-
value: function getCursorLabelOffset(props) {
|
|
98
|
-
var cursorLabelOffset = props.cursorLabelOffset;
|
|
99
|
-
|
|
100
|
-
if (typeof cursorLabelOffset === "number") {
|
|
101
|
-
return {
|
|
102
|
-
x: cursorLabelOffset,
|
|
103
|
-
y: cursorLabelOffset
|
|
104
|
-
};
|
|
16
|
+
return class VictoryCursorContainer extends Base {
|
|
17
|
+
static displayName = "VictoryCursorContainer";
|
|
18
|
+
static defaultProps = {
|
|
19
|
+
..._victoryCore.VictoryContainer.defaultProps,
|
|
20
|
+
cursorLabelComponent: /*#__PURE__*/_react.default.createElement(_victoryCore.VictoryLabel, null),
|
|
21
|
+
cursorLabelOffset: {
|
|
22
|
+
x: 5,
|
|
23
|
+
y: -10
|
|
24
|
+
},
|
|
25
|
+
cursorComponent: /*#__PURE__*/_react.default.createElement(_victoryCore.LineSegment, null)
|
|
26
|
+
};
|
|
27
|
+
static defaultEvents = props => {
|
|
28
|
+
return [{
|
|
29
|
+
target: "parent",
|
|
30
|
+
eventHandlers: {
|
|
31
|
+
onMouseLeave: (evt, targetProps) => {
|
|
32
|
+
return props.disable ? {} : _cursorHelpers.CursorHelpers.onMouseLeave(evt, targetProps);
|
|
33
|
+
},
|
|
34
|
+
onTouchCancel: () => {
|
|
35
|
+
return [];
|
|
36
|
+
},
|
|
37
|
+
onMouseMove: (evt, targetProps) => {
|
|
38
|
+
return props.disable ? {} : _cursorHelpers.CursorHelpers.onMouseMove(evt, targetProps);
|
|
39
|
+
},
|
|
40
|
+
onTouchMove: (evt, targetProps) => {
|
|
41
|
+
return props.disable ? {} : _cursorHelpers.CursorHelpers.onMouseMove(evt, targetProps);
|
|
42
|
+
}
|
|
105
43
|
}
|
|
106
|
-
|
|
107
|
-
|
|
44
|
+
}];
|
|
45
|
+
};
|
|
46
|
+
getCursorPosition(props) {
|
|
47
|
+
const {
|
|
48
|
+
cursorValue,
|
|
49
|
+
defaultCursorValue,
|
|
50
|
+
domain,
|
|
51
|
+
cursorDimension
|
|
52
|
+
} = props;
|
|
53
|
+
if (cursorValue) {
|
|
54
|
+
return cursorValue;
|
|
108
55
|
}
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
});
|
|
116
|
-
return _victoryCore.Helpers.getPadding(child.props);
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
return _victoryCore.Helpers.getPadding(props);
|
|
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,
|
|
60
|
+
[cursorDimension]: defaultCursorValue
|
|
61
|
+
};
|
|
120
62
|
}
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
name = props.name,
|
|
132
|
-
horizontal = props.horizontal,
|
|
133
|
-
theme = props.theme;
|
|
134
|
-
|
|
135
|
-
var cursorDimension = _cursorHelpers.CursorHelpers.getDimension(props);
|
|
136
|
-
|
|
137
|
-
var cursorValue = this.getCursorPosition(props);
|
|
138
|
-
var cursorLabelOffset = this.getCursorLabelOffset(props);
|
|
139
|
-
|
|
140
|
-
if (!cursorValue) {
|
|
141
|
-
return [];
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
var newElements = [];
|
|
145
|
-
var padding = this.getPadding(props);
|
|
146
|
-
var cursorCoordinates = {
|
|
147
|
-
x: horizontal ? scale.y(cursorValue.y) : scale.x(cursorValue.x),
|
|
148
|
-
y: horizontal ? scale.x(cursorValue.x) : scale.y(cursorValue.y)
|
|
63
|
+
return defaultCursorValue;
|
|
64
|
+
}
|
|
65
|
+
getCursorLabelOffset(props) {
|
|
66
|
+
const {
|
|
67
|
+
cursorLabelOffset
|
|
68
|
+
} = props;
|
|
69
|
+
if (typeof cursorLabelOffset === "number") {
|
|
70
|
+
return {
|
|
71
|
+
x: cursorLabelOffset,
|
|
72
|
+
y: cursorLabelOffset
|
|
149
73
|
};
|
|
150
|
-
|
|
151
|
-
if (cursorLabel) {
|
|
152
|
-
var labelProps = (0, _defaults2.default)({
|
|
153
|
-
active: true
|
|
154
|
-
}, cursorLabelComponent.props, {
|
|
155
|
-
x: cursorCoordinates.x + cursorLabelOffset.x,
|
|
156
|
-
y: cursorCoordinates.y + cursorLabelOffset.y,
|
|
157
|
-
datum: cursorValue,
|
|
158
|
-
active: true,
|
|
159
|
-
key: "".concat(name, "-cursor-label")
|
|
160
|
-
});
|
|
161
|
-
|
|
162
|
-
if (_victoryCore.Helpers.isTooltip(cursorLabelComponent)) {
|
|
163
|
-
var tooltipTheme = theme && theme.tooltip || {};
|
|
164
|
-
labelProps = (0, _defaults2.default)({}, labelProps, tooltipTheme);
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
newElements.push( /*#__PURE__*/_react.default.cloneElement(cursorLabelComponent, (0, _defaults2.default)({}, labelProps, {
|
|
168
|
-
text: _victoryCore.Helpers.evaluateProp(cursorLabel, labelProps)
|
|
169
|
-
})));
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
var cursorStyle = Object.assign({
|
|
173
|
-
stroke: "black"
|
|
174
|
-
}, cursorComponent.props.style);
|
|
175
|
-
|
|
176
|
-
if (cursorDimension === "x" || cursorDimension === undefined) {
|
|
177
|
-
newElements.push( /*#__PURE__*/_react.default.cloneElement(cursorComponent, {
|
|
178
|
-
key: "".concat(name, "-x-cursor"),
|
|
179
|
-
x1: cursorCoordinates.x,
|
|
180
|
-
x2: cursorCoordinates.x,
|
|
181
|
-
y1: padding.top,
|
|
182
|
-
y2: height - padding.bottom,
|
|
183
|
-
style: cursorStyle
|
|
184
|
-
}));
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
if (cursorDimension === "y" || cursorDimension === undefined) {
|
|
188
|
-
newElements.push( /*#__PURE__*/_react.default.cloneElement(cursorComponent, {
|
|
189
|
-
key: "".concat(name, "-y-cursor"),
|
|
190
|
-
x1: padding.left,
|
|
191
|
-
x2: width - padding.right,
|
|
192
|
-
y1: cursorCoordinates.y,
|
|
193
|
-
y2: cursorCoordinates.y,
|
|
194
|
-
style: cursorStyle
|
|
195
|
-
}));
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
return newElements;
|
|
199
|
-
} // Overrides method in VictoryContainer
|
|
200
|
-
|
|
201
|
-
}, {
|
|
202
|
-
key: "getChildren",
|
|
203
|
-
value: function getChildren(props) {
|
|
204
|
-
return [].concat(_toConsumableArray(_react.default.Children.toArray(props.children)), _toConsumableArray(this.getCursorElements(props)));
|
|
205
74
|
}
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
75
|
+
return cursorLabelOffset;
|
|
76
|
+
}
|
|
77
|
+
getPadding(props) {
|
|
78
|
+
if (props.padding === undefined) {
|
|
79
|
+
const child = props.children.find(c => {
|
|
80
|
+
return (0, _isObject2.default)(c.props) && c.props.padding !== undefined;
|
|
81
|
+
});
|
|
82
|
+
return _victoryCore.Helpers.getPadding(child.props);
|
|
83
|
+
}
|
|
84
|
+
return _victoryCore.Helpers.getPadding(props);
|
|
85
|
+
}
|
|
86
|
+
getCursorElements(props) {
|
|
87
|
+
// eslint-disable-line max-statements
|
|
88
|
+
const {
|
|
89
|
+
scale,
|
|
90
|
+
cursorLabelComponent,
|
|
91
|
+
cursorLabel,
|
|
92
|
+
cursorComponent,
|
|
93
|
+
width,
|
|
94
|
+
height,
|
|
95
|
+
name,
|
|
96
|
+
horizontal,
|
|
97
|
+
theme
|
|
98
|
+
} = props;
|
|
99
|
+
const cursorDimension = _cursorHelpers.CursorHelpers.getDimension(props);
|
|
100
|
+
const cursorValue = this.getCursorPosition(props);
|
|
101
|
+
const cursorLabelOffset = this.getCursorLabelOffset(props);
|
|
102
|
+
if (!cursorValue) {
|
|
103
|
+
return [];
|
|
104
|
+
}
|
|
105
|
+
const newElements = [];
|
|
106
|
+
const padding = this.getPadding(props);
|
|
107
|
+
const cursorCoordinates = {
|
|
108
|
+
x: horizontal ? scale.y(cursorValue.y) : scale.x(cursorValue.x),
|
|
109
|
+
y: horizontal ? scale.x(cursorValue.x) : scale.y(cursorValue.y)
|
|
110
|
+
};
|
|
111
|
+
if (cursorLabel) {
|
|
112
|
+
let labelProps = (0, _defaults2.default)({
|
|
113
|
+
active: true
|
|
114
|
+
}, cursorLabelComponent.props, {
|
|
115
|
+
x: cursorCoordinates.x + cursorLabelOffset.x,
|
|
116
|
+
y: cursorCoordinates.y + cursorLabelOffset.y,
|
|
117
|
+
datum: cursorValue,
|
|
118
|
+
active: true,
|
|
119
|
+
key: `${name}-cursor-label`
|
|
120
|
+
});
|
|
121
|
+
if (_victoryCore.Helpers.isTooltip(cursorLabelComponent)) {
|
|
122
|
+
const tooltipTheme = theme && theme.tooltip || {};
|
|
123
|
+
labelProps = (0, _defaults2.default)({}, labelProps, tooltipTheme);
|
|
231
124
|
}
|
|
125
|
+
newElements.push( /*#__PURE__*/_react.default.cloneElement(cursorLabelComponent, (0, _defaults2.default)({}, labelProps, {
|
|
126
|
+
text: _victoryCore.Helpers.evaluateProp(cursorLabel, labelProps)
|
|
127
|
+
})));
|
|
232
128
|
}
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
}
|
|
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
|
+
}));
|
|
151
|
+
}
|
|
152
|
+
return newElements;
|
|
153
|
+
}
|
|
236
154
|
|
|
237
|
-
|
|
238
|
-
|
|
155
|
+
// Overrides method in VictoryContainer
|
|
156
|
+
getChildren(props) {
|
|
157
|
+
return [..._react.default.Children.toArray(props.children), ...this.getCursorElements(props)];
|
|
158
|
+
}
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
const VictoryCursorContainer = exports.VictoryCursorContainer = cursorContainerMixin(_victoryCore.VictoryContainer);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "victory-cursor-container",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "37.0.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.0.0"
|
|
25
25
|
},
|
|
26
26
|
"peerDependencies": {
|
|
27
27
|
"react": ">=16.6.0"
|