victory-cursor-container 36.9.2-next.1 → 36.9.2

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.
@@ -1,6 +1,10 @@
1
1
  import _isObject from "lodash/isObject";
2
2
  import _defaults from "lodash/defaults";
3
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
+
4
8
  function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
5
9
 
6
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."); }
@@ -13,181 +17,204 @@ function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToAr
13
17
 
14
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; }
15
19
 
16
- 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; }
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; }
17
21
 
18
- 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; }
22
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
19
23
 
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; }
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); } }
21
25
 
22
- import React from "react";
23
- import { Helpers, VictoryLabel, LineSegment, VictoryContainer } from "victory-core";
24
- import { CursorHelpers } from "./cursor-helpers";
25
- export var VICTORY_CURSOR_CONTAINER_DEFAULT_PROPS = {
26
- cursorLabelComponent: /*#__PURE__*/React.createElement(VictoryLabel, null),
27
- cursorLabelOffset: {
28
- x: 5,
29
- y: -10
30
- },
31
- cursorComponent: /*#__PURE__*/React.createElement(LineSegment, null)
32
- };
33
- export var useVictoryCursorContainer = function (initialProps) {
34
- var props = _objectSpread(_objectSpread({}, VICTORY_CURSOR_CONTAINER_DEFAULT_PROPS), initialProps);
35
-
36
- var children = props.children;
37
-
38
- var getCursorPosition = function () {
39
- var cursorValue = props.cursorValue,
40
- defaultCursorValue = props.defaultCursorValue,
41
- domain = props.domain,
42
- cursorDimension = props.cursorDimension;
43
-
44
- if (cursorValue) {
45
- return cursorValue;
46
- }
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; }
47
27
 
48
- if (typeof defaultCursorValue === "number") {
49
- return _objectSpread({
50
- x: (domain.x[0] + domain.x[1]) / 2,
51
- y: (domain.y[0] + domain.y[1]) / 2
52
- }, cursorDimension ? _defineProperty({}, cursorDimension, defaultCursorValue) : {});
53
- }
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); }
54
29
 
55
- return defaultCursorValue;
56
- };
30
+ function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
57
31
 
58
- var getCursorLabelOffset = function () {
59
- var cursorLabelOffset = props.cursorLabelOffset;
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); }; }
60
33
 
61
- if (typeof cursorLabelOffset === "number") {
62
- return {
63
- x: cursorLabelOffset,
64
- y: cursorLabelOffset
65
- };
66
- }
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); }
67
35
 
68
- return cursorLabelOffset;
69
- };
36
+ function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
70
37
 
71
- var getPadding = function () {
72
- if (props.padding === undefined) {
73
- var child = Array.isArray(props.children) ? props.children.find(function (c) {
74
- return _isObject(c.props) && c.props.padding !== undefined;
75
- }) : props.children;
76
- return Helpers.getPadding(child === null || child === void 0 ? void 0 : child.props);
77
- }
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; } }
78
39
 
79
- return Helpers.getPadding(props);
80
- };
81
-
82
- var getCursorElements = function () {
83
- var _scale$y, _scale$x, _scale$x2, _scale$y2;
84
-
85
- // eslint-disable-line max-statements
86
- var scale = props.scale,
87
- cursorLabelComponent = props.cursorLabelComponent,
88
- cursorLabel = props.cursorLabel,
89
- cursorComponent = props.cursorComponent,
90
- width = props.width,
91
- height = props.height,
92
- name = props.name,
93
- horizontal = props.horizontal,
94
- theme = props.theme;
95
- var cursorDimension = CursorHelpers.getDimension(props);
96
- var cursorValue = getCursorPosition();
97
- var cursorLabelOffset = getCursorLabelOffset();
98
-
99
- if (!cursorValue) {
100
- return [];
101
- }
40
+ function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
102
41
 
103
- var newElements = [];
104
- var padding = getPadding();
105
- var cursorCoordinates = {
106
- x: horizontal ? scale === null || scale === void 0 ? void 0 : (_scale$y = scale.y) === null || _scale$y === void 0 ? void 0 : _scale$y.call(scale, cursorValue.y) : scale === null || scale === void 0 ? void 0 : (_scale$x = scale.x) === null || _scale$x === void 0 ? void 0 : _scale$x.call(scale, cursorValue.x),
107
- y: horizontal ? scale === null || scale === void 0 ? void 0 : (_scale$x2 = scale.x) === null || _scale$x2 === void 0 ? void 0 : _scale$x2.call(scale, cursorValue.x) : scale === null || scale === void 0 ? void 0 : (_scale$y2 = scale.y) === null || _scale$y2 === void 0 ? void 0 : _scale$y2.call(scale, cursorValue.y)
108
- };
109
-
110
- if (cursorLabel) {
111
- var labelProps = _defaults({
112
- active: true
113
- }, cursorLabelComponent.props, {
114
- x: cursorCoordinates.x || 0 + cursorLabelOffset.x,
115
- y: cursorCoordinates.y || 0 + cursorLabelOffset.y,
116
- datum: cursorValue,
117
- active: true,
118
- key: "".concat(name, "-cursor-label")
119
- });
120
-
121
- if (Helpers.isTooltip(cursorLabelComponent)) {
122
- var tooltipTheme = theme && theme.tooltip || {};
123
- labelProps = _defaults({}, labelProps, tooltipTheme);
124
- }
42
+ import React from "react";
43
+ import { VictoryContainer, Helpers, VictoryLabel, LineSegment } from "victory-core";
44
+ import { CursorHelpers } from "./cursor-helpers";
45
+ export function cursorContainerMixin(Base) {
46
+ var _class;
125
47
 
126
- newElements.push( /*#__PURE__*/React.cloneElement(cursorLabelComponent, _defaults({}, labelProps, {
127
- text: Helpers.evaluateProp(cursorLabel, labelProps)
128
- })));
129
- }
48
+ // @ts-expect-error "TS2545: A mixin class must have a constructor with a single rest parameter of type 'any[]'."
49
+ return _class = /*#__PURE__*/function (_Base) {
50
+ _inherits(VictoryCursorContainer, _Base);
130
51
 
131
- var cursorStyle = Object.assign({
132
- stroke: "black"
133
- }, cursorComponent.props.style);
134
-
135
- if (cursorDimension === "x" || cursorDimension === undefined) {
136
- newElements.push( /*#__PURE__*/React.cloneElement(cursorComponent, {
137
- key: "".concat(name, "-x-cursor"),
138
- x1: cursorCoordinates.x,
139
- x2: cursorCoordinates.x,
140
- y1: padding.top,
141
- y2: height || 0 - padding.bottom,
142
- style: cursorStyle
143
- }));
144
- }
52
+ var _super = _createSuper(VictoryCursorContainer);
145
53
 
146
- if (cursorDimension === "y" || cursorDimension === undefined) {
147
- newElements.push( /*#__PURE__*/React.cloneElement(cursorComponent, {
148
- key: "".concat(name, "-y-cursor"),
149
- x1: padding.left,
150
- x2: width || 0 - padding.right,
151
- y1: cursorCoordinates.y,
152
- y2: cursorCoordinates.y,
153
- style: cursorStyle
154
- }));
54
+ function VictoryCursorContainer() {
55
+ _classCallCheck(this, VictoryCursorContainer);
56
+
57
+ return _super.apply(this, arguments);
155
58
  }
156
59
 
157
- return newElements;
158
- };
159
-
160
- return {
161
- props: props,
162
- children: [].concat(_toConsumableArray(React.Children.toArray(children)), _toConsumableArray(getCursorElements()))
163
- };
164
- };
165
- export var VictoryCursorContainer = function (initialProps) {
166
- var _useVictoryCursorCont = useVictoryCursorContainer(initialProps),
167
- props = _useVictoryCursorCont.props,
168
- children = _useVictoryCursorCont.children;
169
-
170
- return /*#__PURE__*/React.createElement(VictoryContainer, props, children);
171
- };
172
- VictoryCursorContainer.role = "container";
173
-
174
- VictoryCursorContainer.defaultEvents = function (initialProps) {
175
- var props = _objectSpread(_objectSpread({}, VICTORY_CURSOR_CONTAINER_DEFAULT_PROPS), initialProps);
176
-
177
- var createEventHandler = function (handler, disabled) {
178
- return (// eslint-disable-next-line max-params
179
- function (event, targetProps, eventKey, context) {
180
- return disabled || props.disable ? {} : handler(event, _objectSpread(_objectSpread({}, props), targetProps), eventKey, context);
60
+ _createClass(VictoryCursorContainer, [{
61
+ key: "getCursorPosition",
62
+ value: function getCursorPosition(props) {
63
+ var cursorValue = props.cursorValue,
64
+ defaultCursorValue = props.defaultCursorValue,
65
+ domain = props.domain,
66
+ cursorDimension = props.cursorDimension;
67
+
68
+ if (cursorValue) {
69
+ return cursorValue;
70
+ }
71
+
72
+ if (typeof defaultCursorValue === "number") {
73
+ return _defineProperty({
74
+ x: (domain.x[0] + domain.x[1]) / 2,
75
+ y: (domain.y[0] + domain.y[1]) / 2
76
+ }, cursorDimension, defaultCursorValue);
77
+ }
78
+
79
+ return defaultCursorValue;
181
80
  }
182
- );
183
- };
184
-
185
- return [{
186
- target: "parent",
187
- eventHandlers: {
188
- onMouseLeave: createEventHandler(CursorHelpers.onMouseLeave),
189
- onMouseMove: createEventHandler(CursorHelpers.onMouseMove),
190
- onTouchMove: createEventHandler(CursorHelpers.onMouseMove)
191
- }
192
- }];
193
- };
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
+ };
91
+ }
92
+
93
+ return cursorLabelOffset;
94
+ }
95
+ }, {
96
+ key: "getPadding",
97
+ value: function getPadding(props) {
98
+ if (props.padding === undefined) {
99
+ var child = props.children.find(function (c) {
100
+ return _isObject(c.props) && c.props.padding !== undefined;
101
+ });
102
+ return Helpers.getPadding(child.props);
103
+ }
104
+
105
+ return Helpers.getPadding(props);
106
+ }
107
+ }, {
108
+ key: "getCursorElements",
109
+ value: function getCursorElements(props) {
110
+ // eslint-disable-line max-statements
111
+ var scale = props.scale,
112
+ cursorLabelComponent = props.cursorLabelComponent,
113
+ cursorLabel = props.cursorLabel,
114
+ cursorComponent = props.cursorComponent,
115
+ width = props.width,
116
+ height = props.height,
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)
133
+ };
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
+ }
190
+ }]);
191
+
192
+ return VictoryCursorContainer;
193
+ }(Base), _class.displayName = "VictoryCursorContainer", _class.defaultProps = _objectSpread(_objectSpread({}, VictoryContainer.defaultProps), {}, {
194
+ cursorLabelComponent: /*#__PURE__*/React.createElement(VictoryLabel, null),
195
+ cursorLabelOffset: {
196
+ x: 5,
197
+ y: -10
198
+ },
199
+ cursorComponent: /*#__PURE__*/React.createElement(LineSegment, null)
200
+ }), _class.defaultEvents = function (props) {
201
+ return [{
202
+ target: "parent",
203
+ eventHandlers: {
204
+ onMouseLeave: function (evt, targetProps) {
205
+ return props.disable ? {} : CursorHelpers.onMouseLeave(evt, targetProps);
206
+ },
207
+ onTouchCancel: function () {
208
+ return [];
209
+ },
210
+ onMouseMove: function (evt, targetProps) {
211
+ return props.disable ? {} : CursorHelpers.onMouseMove(evt, targetProps);
212
+ },
213
+ onTouchMove: function (evt, targetProps) {
214
+ return props.disable ? {} : CursorHelpers.onMouseMove(evt, targetProps);
215
+ }
216
+ }
217
+ }];
218
+ }, _class;
219
+ }
220
+ export var VictoryCursorContainer = cursorContainerMixin(VictoryContainer);
@@ -1,33 +1,33 @@
1
- /// <reference types="lodash" />
2
- import { Selection } from "victory-core";
3
- declare class CursorHelpersClass {
4
- getDimension(props: any): any;
5
- withinBounds(point: any, bounds: any): boolean;
6
- private handleMouseMove;
7
- onMouseMove: import("lodash").DebouncedFunc<(evt: any, targetProps: any) => {
8
- target: string;
9
- eventKey: string;
10
- mutation: () => {
11
- cursorValue: Selection.SVGCoordinateType | null;
12
- parentSVG: any;
13
- };
14
- }[]>;
15
- onMouseLeave: (evt: any, targetProps: any) => {
16
- target: string;
17
- eventKey: string;
18
- mutation: () => {
19
- cursorValue: Selection.SVGCoordinateType | null;
20
- parentSVG: any;
21
- };
22
- }[];
23
- onTouchEnd: (evt: any, targetProps: any) => {
24
- target: string;
25
- eventKey: string;
26
- mutation: () => {
27
- cursorValue: null;
28
- };
29
- }[];
30
- }
31
- export declare const CursorHelpers: CursorHelpersClass;
32
- export {};
1
+ /// <reference types="lodash" />
2
+ import { Selection } from "victory-core";
3
+ declare class CursorHelpersClass {
4
+ getDimension(props: any): any;
5
+ withinBounds(point: any, bounds: any): boolean;
6
+ private handleMouseMove;
7
+ onMouseMove: import("lodash").DebouncedFunc<(evt: any, targetProps: any) => {
8
+ target: string;
9
+ eventKey: string;
10
+ mutation: () => {
11
+ cursorValue: Selection.SVGCoordinateType | null;
12
+ parentSVG: any;
13
+ };
14
+ }[]>;
15
+ onMouseLeave: (evt: any, targetProps: any) => {
16
+ target: string;
17
+ eventKey: string;
18
+ mutation: () => {
19
+ cursorValue: Selection.SVGCoordinateType | null;
20
+ parentSVG: any;
21
+ };
22
+ }[];
23
+ onTouchEnd: (evt: any, targetProps: any) => {
24
+ target: string;
25
+ eventKey: string;
26
+ mutation: () => {
27
+ cursorValue: null;
28
+ };
29
+ }[];
30
+ }
31
+ export declare const CursorHelpers: CursorHelpersClass;
32
+ export {};
33
33
  //# sourceMappingURL=cursor-helpers.d.ts.map
package/lib/index.d.ts CHANGED
@@ -1,3 +1,3 @@
1
- export * from "./cursor-helpers";
2
- export * from "./victory-cursor-container";
1
+ export * from "./cursor-helpers";
2
+ export * from "./victory-cursor-container";
3
3
  //# sourceMappingURL=index.d.ts.map