victory-cursor-container 36.9.1 → 36.9.2-next.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.
@@ -1,122 +1,89 @@
1
1
  import _mapValues from "lodash/mapValues";
2
- import _isFunction from "lodash/isFunction";
3
2
  import _throttle from "lodash/throttle";
4
-
5
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
6
-
7
- 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); } }
8
-
9
- function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
10
-
11
- import { Selection } from "victory-core";
12
- var ON_MOUSE_MOVE_THROTTLE_MS = 16;
13
-
14
- var CursorHelpersClass = /*#__PURE__*/function () {
15
- function CursorHelpersClass() {
16
- var _this = this;
17
-
18
- _classCallCheck(this, CursorHelpersClass);
19
-
20
- this.handleMouseMove = function (evt, targetProps) {
21
- var onCursorChange = targetProps.onCursorChange,
22
- domain = targetProps.domain;
23
-
24
- var cursorDimension = _this.getDimension(targetProps);
25
-
26
- var parentSVG = targetProps.parentSVG || Selection.getParentSVG(evt);
27
- var cursorSVGPosition = Selection.getSVGEventCoordinates(evt, parentSVG);
28
- var cursorValue = Selection.getDataCoordinates(targetProps, targetProps.scale, cursorSVGPosition.x, cursorSVGPosition.y);
29
-
30
- var inBounds = _this.withinBounds(cursorValue, {
31
- x1: domain.x[0],
32
- x2: domain.x[1],
33
- y1: domain.y[0],
34
- y2: domain.y[1]
35
- });
36
-
37
- if (!inBounds) {
38
- cursorValue = null;
39
- }
40
-
41
- if (_isFunction(onCursorChange)) {
42
- if (cursorValue) {
43
- var value = cursorDimension ? cursorValue[cursorDimension] : cursorValue;
44
- onCursorChange(value, targetProps);
45
- } else if (cursorValue !== targetProps.cursorValue) {
46
- onCursorChange(targetProps.defaultCursorValue || null, targetProps);
47
- }
48
- }
49
-
50
- return [{
51
- target: "parent",
52
- eventKey: "parent",
53
- mutation: function () {
54
- return {
55
- cursorValue: cursorValue,
56
- parentSVG: parentSVG
57
- };
58
- }
59
- }];
60
- };
61
-
62
- this.onMouseMove = _throttle(this.handleMouseMove, ON_MOUSE_MOVE_THROTTLE_MS, {
63
- leading: true,
64
- trailing: false
65
- });
66
- this.onMouseLeave = this.handleMouseMove;
67
-
68
- this.onTouchEnd = function (evt, targetProps) {
69
- var onCursorChange = targetProps.onCursorChange;
70
-
71
- if (_isFunction(targetProps.onCursorChange)) {
72
- onCursorChange(null, targetProps);
73
- }
74
-
75
- return [{
76
- target: "parent",
77
- eventKey: "parent",
78
- mutation: function () {
79
- return {
80
- cursorValue: null
81
- };
82
- }
83
- }];
84
- };
3
+ import { Helpers, Selection } from "victory-core";
4
+ const ON_MOUSE_MOVE_THROTTLE_MS = 16;
5
+ class CursorHelpersClass {
6
+ getDimension(props) {
7
+ const {
8
+ horizontal,
9
+ cursorDimension
10
+ } = props;
11
+ if (!horizontal || !cursorDimension) {
12
+ return cursorDimension;
13
+ }
14
+ return cursorDimension === "x" ? "y" : "x";
85
15
  }
86
-
87
- _createClass(CursorHelpersClass, [{
88
- key: "getDimension",
89
- value: function getDimension(props) {
90
- var horizontal = props.horizontal,
91
- cursorDimension = props.cursorDimension;
92
-
93
- if (!horizontal || !cursorDimension) {
94
- return cursorDimension;
16
+ withinBounds(point, bounds) {
17
+ const {
18
+ x1,
19
+ x2,
20
+ y1,
21
+ y2
22
+ } = _mapValues(bounds, Number);
23
+ const {
24
+ x,
25
+ y
26
+ } = _mapValues(point, Number);
27
+ return x >= Math.min(x1, x2) && x <= Math.max(x1, x2) && y >= Math.min(y1, y2) && y <= Math.max(y1, y2);
28
+ }
29
+ handleMouseMove = (evt, targetProps) => {
30
+ const {
31
+ onCursorChange,
32
+ domain
33
+ } = targetProps;
34
+ const cursorDimension = this.getDimension(targetProps);
35
+ const parentSVG = targetProps.parentSVG || Selection.getParentSVG(evt);
36
+ const cursorSVGPosition = Selection.getSVGEventCoordinates(evt, parentSVG);
37
+ let cursorValue = Selection.getDataCoordinates(targetProps, targetProps.scale, cursorSVGPosition.x, cursorSVGPosition.y);
38
+ const inBounds = this.withinBounds(cursorValue, {
39
+ x1: domain.x[0],
40
+ x2: domain.x[1],
41
+ y1: domain.y[0],
42
+ y2: domain.y[1]
43
+ });
44
+ if (!inBounds) {
45
+ cursorValue = null;
46
+ }
47
+ if (Helpers.isFunction(onCursorChange)) {
48
+ if (cursorValue) {
49
+ const value = cursorDimension ? cursorValue[cursorDimension] : cursorValue;
50
+ onCursorChange(value, targetProps);
51
+ } else if (cursorValue !== targetProps.cursorValue) {
52
+ onCursorChange(targetProps.defaultCursorValue || null, targetProps);
95
53
  }
96
-
97
- return cursorDimension === "x" ? "y" : "x";
98
54
  }
99
- }, {
100
- key: "withinBounds",
101
- value: function withinBounds(point, bounds) {
102
- var _mapValues2 = _mapValues(bounds, Number),
103
- x1 = _mapValues2.x1,
104
- x2 = _mapValues2.x2,
105
- y1 = _mapValues2.y1,
106
- y2 = _mapValues2.y2;
107
-
108
- var _mapValues3 = _mapValues(point, Number),
109
- x = _mapValues3.x,
110
- y = _mapValues3.y;
111
-
112
- return x >= Math.min(x1, x2) && x <= Math.max(x1, x2) && y >= Math.min(y1, y2) && y <= Math.max(y1, y2);
55
+ return [{
56
+ target: "parent",
57
+ eventKey: "parent",
58
+ mutation: () => ({
59
+ cursorValue,
60
+ parentSVG
61
+ })
62
+ }];
63
+ };
64
+ onMouseMove = _throttle(this.handleMouseMove, ON_MOUSE_MOVE_THROTTLE_MS, {
65
+ leading: true,
66
+ trailing: false
67
+ });
68
+ onMouseLeave = this.handleMouseMove;
69
+ onTouchEnd = (evt, targetProps) => {
70
+ const {
71
+ onCursorChange
72
+ } = targetProps;
73
+ if (Helpers.isFunction(targetProps.onCursorChange)) {
74
+ onCursorChange(null, targetProps);
113
75
  }
114
- }]);
115
-
116
- return CursorHelpersClass;
117
- }();
76
+ return [{
77
+ target: "parent",
78
+ eventKey: "parent",
79
+ mutation: () => ({
80
+ cursorValue: null
81
+ })
82
+ }];
83
+ };
84
+ }
85
+ export const CursorHelpers = new CursorHelpersClass();
118
86
 
119
- export var CursorHelpers = new CursorHelpersClass();
120
87
  /* {
121
88
  ...CursorHelpers,
122
89
  onMouseMove: throttle(
package/es/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
@@ -1,134 +1,134 @@
1
- import React from "react";
2
- import { VictoryContainer, VictoryContainerProps, CoordinatesPropType, VictoryLabelProps, ValueOrAccessor } from "victory-core";
3
- export declare type CursorCoordinatesPropType = CoordinatesPropType | number;
4
- export interface VictoryCursorContainerProps extends VictoryContainerProps {
5
- cursorComponent?: React.ReactElement;
6
- cursorDimension?: "x" | "y";
7
- cursorLabel?: ValueOrAccessor<VictoryLabelProps["text"]>;
8
- cursorLabelComponent?: React.ReactElement;
9
- cursorLabelOffset?: CursorCoordinatesPropType;
10
- defaultCursorValue?: CursorCoordinatesPropType;
11
- disable?: boolean;
12
- onCursorChange?: (value: CursorCoordinatesPropType, props: VictoryCursorContainerProps) => void;
13
- }
14
- declare type ComponentClass<TProps> = {
15
- new (props: TProps): React.Component<TProps>;
16
- };
17
- export declare function cursorContainerMixin<TBase extends ComponentClass<TProps>, TProps extends VictoryCursorContainerProps>(Base: TBase): {
18
- new (props: TProps): {
19
- getCursorPosition(props: any): any;
20
- getCursorLabelOffset(props: any): any;
21
- getPadding(props: any): {
22
- top: any;
23
- bottom: any;
24
- left: any;
25
- right: any;
26
- };
27
- getCursorElements(props: any): React.ReactElement<any, string | React.JSXElementConstructor<any>>[];
28
- getChildren(props: any): (string | number | React.ReactElement<any, string | React.JSXElementConstructor<any>> | React.ReactFragment)[];
29
- context: unknown;
30
- setState<K extends never>(state: {} | ((prevState: Readonly<{}>, props: Readonly<TProps>) => {} | Pick<{}, K> | null) | Pick<{}, K> | null, callback?: (() => void) | undefined): void;
31
- forceUpdate(callback?: (() => void) | undefined): void;
32
- render(): React.ReactNode;
33
- readonly props: Readonly<TProps>;
34
- state: Readonly<{}>;
35
- refs: {
36
- [key: string]: React.ReactInstance;
37
- };
38
- componentDidMount?(): void;
39
- shouldComponentUpdate?(nextProps: Readonly<TProps>, nextState: Readonly<{}>, nextContext: any): boolean;
40
- componentWillUnmount?(): void;
41
- componentDidCatch?(error: Error, errorInfo: React.ErrorInfo): void;
42
- getSnapshotBeforeUpdate?(prevProps: Readonly<TProps>, prevState: Readonly<{}>): any;
43
- componentDidUpdate?(prevProps: Readonly<TProps>, prevState: Readonly<{}>, snapshot?: any): void;
44
- componentWillMount?(): void;
45
- UNSAFE_componentWillMount?(): void;
46
- componentWillReceiveProps?(nextProps: Readonly<TProps>, nextContext: any): void;
47
- UNSAFE_componentWillReceiveProps?(nextProps: Readonly<TProps>, nextContext: any): void;
48
- componentWillUpdate?(nextProps: Readonly<TProps>, nextState: Readonly<{}>, nextContext: any): void;
49
- UNSAFE_componentWillUpdate?(nextProps: Readonly<TProps>, nextState: Readonly<{}>, nextContext: any): void;
50
- };
51
- displayName: string;
52
- defaultProps: {
53
- cursorLabelComponent: JSX.Element;
54
- cursorLabelOffset: {
55
- x: number;
56
- y: number;
57
- };
58
- cursorComponent: JSX.Element;
59
- className: string;
60
- portalComponent: JSX.Element;
61
- portalZIndex: number;
62
- responsive: boolean;
63
- role: string;
64
- };
65
- defaultEvents: (props: any) => {
66
- target: string;
67
- eventHandlers: {
68
- onMouseLeave: (evt: any, targetProps: any) => {};
69
- onTouchCancel: () => never[];
70
- onMouseMove: (evt: any, targetProps: any) => {} | undefined;
71
- onTouchMove: (evt: any, targetProps: any) => {} | undefined;
72
- };
73
- }[];
74
- } & TBase;
75
- export declare const VictoryCursorContainer: {
76
- new (props: VictoryCursorContainerProps): {
77
- getCursorPosition(props: any): any;
78
- getCursorLabelOffset(props: any): any;
79
- getPadding(props: any): {
80
- top: any;
81
- bottom: any;
82
- left: any;
83
- right: any;
84
- };
85
- getCursorElements(props: any): React.ReactElement<any, string | React.JSXElementConstructor<any>>[];
86
- getChildren(props: any): (string | number | React.ReactElement<any, string | React.JSXElementConstructor<any>> | React.ReactFragment)[];
87
- context: unknown;
88
- setState<K extends never>(state: {} | ((prevState: Readonly<{}>, props: Readonly<VictoryCursorContainerProps>) => {} | Pick<{}, K> | null) | Pick<{}, K> | null, callback?: (() => void) | undefined): void;
89
- forceUpdate(callback?: (() => void) | undefined): void;
90
- render(): React.ReactNode;
91
- readonly props: Readonly<VictoryCursorContainerProps>;
92
- state: Readonly<{}>;
93
- refs: {
94
- [key: string]: React.ReactInstance;
95
- };
96
- componentDidMount?(): void;
97
- shouldComponentUpdate?(nextProps: Readonly<VictoryCursorContainerProps>, nextState: Readonly<{}>, nextContext: any): boolean;
98
- componentWillUnmount?(): void;
99
- componentDidCatch?(error: Error, errorInfo: React.ErrorInfo): void;
100
- getSnapshotBeforeUpdate?(prevProps: Readonly<VictoryCursorContainerProps>, prevState: Readonly<{}>): any;
101
- componentDidUpdate?(prevProps: Readonly<VictoryCursorContainerProps>, prevState: Readonly<{}>, snapshot?: any): void;
102
- componentWillMount?(): void;
103
- UNSAFE_componentWillMount?(): void;
104
- componentWillReceiveProps?(nextProps: Readonly<VictoryCursorContainerProps>, nextContext: any): void;
105
- UNSAFE_componentWillReceiveProps?(nextProps: Readonly<VictoryCursorContainerProps>, nextContext: any): void;
106
- componentWillUpdate?(nextProps: Readonly<VictoryCursorContainerProps>, nextState: Readonly<{}>, nextContext: any): void;
107
- UNSAFE_componentWillUpdate?(nextProps: Readonly<VictoryCursorContainerProps>, nextState: Readonly<{}>, nextContext: any): void;
108
- };
109
- displayName: string;
110
- defaultProps: {
111
- cursorLabelComponent: JSX.Element;
112
- cursorLabelOffset: {
113
- x: number;
114
- y: number;
115
- };
116
- cursorComponent: JSX.Element;
117
- className: string;
118
- portalComponent: JSX.Element;
119
- portalZIndex: number;
120
- responsive: boolean;
121
- role: string;
122
- };
123
- defaultEvents: (props: any) => {
124
- target: string;
125
- eventHandlers: {
126
- onMouseLeave: (evt: any, targetProps: any) => {};
127
- onTouchCancel: () => never[];
128
- onMouseMove: (evt: any, targetProps: any) => {} | undefined;
129
- onTouchMove: (evt: any, targetProps: any) => {} | undefined;
130
- };
131
- }[];
132
- } & typeof VictoryContainer;
133
- export {};
1
+ import React from "react";
2
+ import { VictoryContainer, VictoryContainerProps, CoordinatesPropType, VictoryLabelProps, ValueOrAccessor } from "victory-core";
3
+ export declare type CursorCoordinatesPropType = CoordinatesPropType | number;
4
+ export interface VictoryCursorContainerProps extends VictoryContainerProps {
5
+ cursorComponent?: React.ReactElement;
6
+ cursorDimension?: "x" | "y";
7
+ cursorLabel?: ValueOrAccessor<VictoryLabelProps["text"]>;
8
+ cursorLabelComponent?: React.ReactElement;
9
+ cursorLabelOffset?: CursorCoordinatesPropType;
10
+ defaultCursorValue?: CursorCoordinatesPropType;
11
+ disable?: boolean;
12
+ onCursorChange?: (value: CursorCoordinatesPropType, props: VictoryCursorContainerProps) => void;
13
+ }
14
+ declare type ComponentClass<TProps> = {
15
+ new (props: TProps): React.Component<TProps>;
16
+ };
17
+ export declare function cursorContainerMixin<TBase extends ComponentClass<TProps>, TProps extends VictoryCursorContainerProps>(Base: TBase): {
18
+ new (props: TProps): {
19
+ getCursorPosition(props: any): any;
20
+ getCursorLabelOffset(props: any): any;
21
+ getPadding(props: any): {
22
+ top: any;
23
+ bottom: any;
24
+ left: any;
25
+ right: any;
26
+ };
27
+ getCursorElements(props: any): React.ReactElement<any, string | React.JSXElementConstructor<any>>[];
28
+ getChildren(props: any): (string | number | React.ReactElement<any, string | React.JSXElementConstructor<any>> | React.ReactFragment)[];
29
+ context: unknown;
30
+ setState<K extends never>(state: {} | ((prevState: Readonly<{}>, props: Readonly<TProps>) => {} | Pick<{}, K> | null) | Pick<{}, K> | null, callback?: (() => void) | undefined): void;
31
+ forceUpdate(callback?: (() => void) | undefined): void;
32
+ render(): React.ReactNode;
33
+ readonly props: Readonly<TProps>;
34
+ state: Readonly<{}>;
35
+ refs: {
36
+ [key: string]: React.ReactInstance;
37
+ };
38
+ componentDidMount?(): void;
39
+ shouldComponentUpdate?(nextProps: Readonly<TProps>, nextState: Readonly<{}>, nextContext: any): boolean;
40
+ componentWillUnmount?(): void;
41
+ componentDidCatch?(error: Error, errorInfo: React.ErrorInfo): void;
42
+ getSnapshotBeforeUpdate?(prevProps: Readonly<TProps>, prevState: Readonly<{}>): any;
43
+ componentDidUpdate?(prevProps: Readonly<TProps>, prevState: Readonly<{}>, snapshot?: any): void;
44
+ componentWillMount?(): void;
45
+ UNSAFE_componentWillMount?(): void;
46
+ componentWillReceiveProps?(nextProps: Readonly<TProps>, nextContext: any): void;
47
+ UNSAFE_componentWillReceiveProps?(nextProps: Readonly<TProps>, nextContext: any): void;
48
+ componentWillUpdate?(nextProps: Readonly<TProps>, nextState: Readonly<{}>, nextContext: any): void;
49
+ UNSAFE_componentWillUpdate?(nextProps: Readonly<TProps>, nextState: Readonly<{}>, nextContext: any): void;
50
+ };
51
+ displayName: string;
52
+ defaultProps: {
53
+ cursorLabelComponent: JSX.Element;
54
+ cursorLabelOffset: {
55
+ x: number;
56
+ y: number;
57
+ };
58
+ cursorComponent: JSX.Element;
59
+ className: string;
60
+ portalComponent: JSX.Element;
61
+ portalZIndex: number;
62
+ responsive: boolean;
63
+ role: string;
64
+ };
65
+ defaultEvents: (props: any) => {
66
+ target: string;
67
+ eventHandlers: {
68
+ onMouseLeave: (evt: any, targetProps: any) => {};
69
+ onTouchCancel: () => never[];
70
+ onMouseMove: (evt: any, targetProps: any) => {} | undefined;
71
+ onTouchMove: (evt: any, targetProps: any) => {} | undefined;
72
+ };
73
+ }[];
74
+ } & TBase;
75
+ export declare const VictoryCursorContainer: {
76
+ new (props: VictoryCursorContainerProps): {
77
+ getCursorPosition(props: any): any;
78
+ getCursorLabelOffset(props: any): any;
79
+ getPadding(props: any): {
80
+ top: any;
81
+ bottom: any;
82
+ left: any;
83
+ right: any;
84
+ };
85
+ getCursorElements(props: any): React.ReactElement<any, string | React.JSXElementConstructor<any>>[];
86
+ getChildren(props: any): (string | number | React.ReactElement<any, string | React.JSXElementConstructor<any>> | React.ReactFragment)[];
87
+ context: unknown;
88
+ setState<K extends never>(state: {} | ((prevState: Readonly<{}>, props: Readonly<VictoryCursorContainerProps>) => {} | Pick<{}, K> | null) | Pick<{}, K> | null, callback?: (() => void) | undefined): void;
89
+ forceUpdate(callback?: (() => void) | undefined): void;
90
+ render(): React.ReactNode;
91
+ readonly props: Readonly<VictoryCursorContainerProps>;
92
+ state: Readonly<{}>;
93
+ refs: {
94
+ [key: string]: React.ReactInstance;
95
+ };
96
+ componentDidMount?(): void;
97
+ shouldComponentUpdate?(nextProps: Readonly<VictoryCursorContainerProps>, nextState: Readonly<{}>, nextContext: any): boolean;
98
+ componentWillUnmount?(): void;
99
+ componentDidCatch?(error: Error, errorInfo: React.ErrorInfo): void;
100
+ getSnapshotBeforeUpdate?(prevProps: Readonly<VictoryCursorContainerProps>, prevState: Readonly<{}>): any;
101
+ componentDidUpdate?(prevProps: Readonly<VictoryCursorContainerProps>, prevState: Readonly<{}>, snapshot?: any): void;
102
+ componentWillMount?(): void;
103
+ UNSAFE_componentWillMount?(): void;
104
+ componentWillReceiveProps?(nextProps: Readonly<VictoryCursorContainerProps>, nextContext: any): void;
105
+ UNSAFE_componentWillReceiveProps?(nextProps: Readonly<VictoryCursorContainerProps>, nextContext: any): void;
106
+ componentWillUpdate?(nextProps: Readonly<VictoryCursorContainerProps>, nextState: Readonly<{}>, nextContext: any): void;
107
+ UNSAFE_componentWillUpdate?(nextProps: Readonly<VictoryCursorContainerProps>, nextState: Readonly<{}>, nextContext: any): void;
108
+ };
109
+ displayName: string;
110
+ defaultProps: {
111
+ cursorLabelComponent: JSX.Element;
112
+ cursorLabelOffset: {
113
+ x: number;
114
+ y: number;
115
+ };
116
+ cursorComponent: JSX.Element;
117
+ className: string;
118
+ portalComponent: JSX.Element;
119
+ portalZIndex: number;
120
+ responsive: boolean;
121
+ role: string;
122
+ };
123
+ defaultEvents: (props: any) => {
124
+ target: string;
125
+ eventHandlers: {
126
+ onMouseLeave: (evt: any, targetProps: any) => {};
127
+ onTouchCancel: () => never[];
128
+ onMouseMove: (evt: any, targetProps: any) => {} | undefined;
129
+ onTouchMove: (evt: any, targetProps: any) => {} | undefined;
130
+ };
131
+ }[];
132
+ } & typeof VictoryContainer;
133
+ export {};
134
134
  //# sourceMappingURL=victory-cursor-container.d.ts.map