victory-cursor-container 36.6.0 → 36.6.3

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "victory-cursor-container",
3
- "version": "36.6.0",
3
+ "version": "36.6.3",
4
4
  "description": "Interactive Cursor Component for Victory",
5
5
  "keywords": [
6
6
  "data visualization",
@@ -22,7 +22,7 @@
22
22
  "dependencies": {
23
23
  "lodash": "^4.17.19",
24
24
  "prop-types": "^15.8.1",
25
- "victory-core": "^36.6.0"
25
+ "victory-core": "^36.6.3"
26
26
  },
27
27
  "peerDependencies": {
28
28
  "react": ">=16.6.0"
@@ -48,7 +48,9 @@
48
48
  "files": [
49
49
  "src/**",
50
50
  "!src/**/*.test.*",
51
- "../../.babelrc.build.js"
51
+ "../../.babelrc.build.js",
52
+ "../../.babelrc.js",
53
+ "../../package-scripts.js"
52
54
  ],
53
55
  "output": [
54
56
  "es/**/*.js",
@@ -66,7 +68,9 @@
66
68
  "files": [
67
69
  "src/**",
68
70
  "!src/**/*.test.*",
69
- "../../.babelrc.build.js"
71
+ "../../.babelrc.build.js",
72
+ "../../.babelrc.js",
73
+ "../../package-scripts.js"
70
74
  ],
71
75
  "output": [
72
76
  "lib/**/*.js",
@@ -91,6 +95,8 @@
91
95
  "src/**",
92
96
  "!src/**/*.test.*",
93
97
  "../../.babelrc.build.js",
98
+ "../../.babelrc.js",
99
+ "../../package-scripts.js",
94
100
  "../../config/webpack.config.js",
95
101
  "../../config/webpack.config.dev.js"
96
102
  ],
@@ -111,6 +117,8 @@
111
117
  "src/**",
112
118
  "!src/**/*.test.*",
113
119
  "../../.babelrc.build.js",
120
+ "../../.babelrc.js",
121
+ "../../package-scripts.js",
114
122
  "../../config/webpack.config.js"
115
123
  ],
116
124
  "output": [
@@ -123,6 +131,14 @@
123
131
  "pnpm-lock.yaml"
124
132
  ]
125
133
  },
134
+ "check": {
135
+ "dependencies": [
136
+ "types:check",
137
+ "jest",
138
+ "format",
139
+ "lint"
140
+ ]
141
+ },
126
142
  "types:check": {
127
143
  "command": "nps types:pkg:check",
128
144
  "files": [
@@ -175,6 +191,19 @@
175
191
  "pnpm-lock.yaml"
176
192
  ]
177
193
  },
194
+ "format:fix": {
195
+ "command": "pnpm run format || nps format:pkg:fix",
196
+ "files": [
197
+ "src/**",
198
+ "*.json",
199
+ "../../.prettierignore",
200
+ "../../.prettierrc.json"
201
+ ],
202
+ "output": [],
203
+ "packageLocks": [
204
+ "pnpm-lock.yaml"
205
+ ]
206
+ },
178
207
  "lint": {
179
208
  "command": "nps lint:pkg",
180
209
  "files": [
@@ -192,19 +221,6 @@
192
221
  "pnpm-lock.yaml"
193
222
  ]
194
223
  },
195
- "format:fix": {
196
- "command": "pnpm run format || nps format:pkg:fix",
197
- "files": [
198
- "src/**",
199
- "*.json",
200
- "../../.prettierignore",
201
- "../../.prettierrc.json"
202
- ],
203
- "output": [],
204
- "packageLocks": [
205
- "pnpm-lock.yaml"
206
- ]
207
- },
208
224
  "lint:fix": {
209
225
  "command": "pnpm run lint || nps lint:pkg:fix",
210
226
  "files": [
@@ -251,6 +267,7 @@
251
267
  "build:dist": "wireit",
252
268
  "build:dist:dev": "wireit",
253
269
  "build:dist:min": "wireit",
270
+ "check": "wireit",
254
271
  "types:check": "wireit",
255
272
  "types:create": "wireit",
256
273
  "format": "wireit",
@@ -1,16 +1,16 @@
1
- import { Selection } from "victory-core";
1
+ import { Selection, SVGCoordinateType } from "victory-core";
2
2
  import { throttle, isFunction, mapValues } from "lodash";
3
3
 
4
4
  const ON_MOUSE_MOVE_THROTTLE_MS = 16;
5
5
 
6
- const CursorHelpers = {
6
+ class CursorHelpersClass {
7
7
  getDimension(props) {
8
8
  const { horizontal, cursorDimension } = props;
9
9
  if (!horizontal || !cursorDimension) {
10
10
  return cursorDimension;
11
11
  }
12
12
  return cursorDimension === "x" ? "y" : "x";
13
- },
13
+ }
14
14
 
15
15
  withinBounds(point, bounds) {
16
16
  const { x1, x2, y1, y2 } = mapValues(bounds, Number);
@@ -21,14 +21,14 @@ const CursorHelpers = {
21
21
  y >= Math.min(y1, y2) &&
22
22
  y <= Math.max(y1, y2)
23
23
  );
24
- },
24
+ }
25
25
 
26
- onMouseMove(evt, targetProps) {
26
+ private handleMouseMove = (evt, targetProps) => {
27
27
  const { onCursorChange, domain } = targetProps;
28
28
  const cursorDimension = this.getDimension(targetProps);
29
29
  const parentSVG = targetProps.parentSVG || Selection.getParentSVG(evt);
30
30
  const cursorSVGPosition = Selection.getSVGEventCoordinates(evt, parentSVG);
31
- let cursorValue = Selection.getDataCoordinates(
31
+ let cursorValue: SVGCoordinateType | null = Selection.getDataCoordinates(
32
32
  targetProps,
33
33
  targetProps.scale,
34
34
  cursorSVGPosition.x,
@@ -47,7 +47,7 @@ const CursorHelpers = {
47
47
  }
48
48
 
49
49
  if (isFunction(onCursorChange)) {
50
- if (inBounds) {
50
+ if (cursorValue) {
51
51
  const value = cursorDimension
52
52
  ? cursorValue[cursorDimension]
53
53
  : cursorValue;
@@ -64,9 +64,16 @@ const CursorHelpers = {
64
64
  mutation: () => ({ cursorValue, parentSVG }),
65
65
  },
66
66
  ];
67
- },
67
+ };
68
68
 
69
- onTouchEnd(evt, targetProps) {
69
+ onMouseMove = throttle(this.handleMouseMove, ON_MOUSE_MOVE_THROTTLE_MS, {
70
+ leading: true,
71
+ trailing: false,
72
+ });
73
+
74
+ onMouseLeave = this.handleMouseMove;
75
+
76
+ onTouchEnd = (evt, targetProps) => {
70
77
  const { onCursorChange } = targetProps;
71
78
 
72
79
  if (isFunction(targetProps.onCursorChange)) {
@@ -80,10 +87,12 @@ const CursorHelpers = {
80
87
  mutation: () => ({ cursorValue: null }),
81
88
  },
82
89
  ];
83
- },
84
- };
90
+ };
91
+ }
85
92
 
86
- export default {
93
+ export const CursorHelpers = new CursorHelpersClass();
94
+
95
+ /* {
87
96
  ...CursorHelpers,
88
97
  onMouseMove: throttle(
89
98
  CursorHelpers.onMouseMove.bind(CursorHelpers),
@@ -96,3 +105,6 @@ export default {
96
105
  onMouseLeave: CursorHelpers.onMouseMove.bind(CursorHelpers),
97
106
  onTouchEnd: CursorHelpers.onTouchEnd.bind(CursorHelpers),
98
107
  };
108
+
109
+
110
+ */
package/src/index.tsx ADDED
@@ -0,0 +1,2 @@
1
+ export * from "./cursor-helpers";
2
+ export * from "./victory-cursor-container";
@@ -5,12 +5,38 @@ import {
5
5
  VictoryLabel,
6
6
  LineSegment,
7
7
  Helpers,
8
+ VictoryContainerProps,
9
+ CoordinatesPropType,
10
+ VictoryLabelProps,
11
+ ValueOrCallback,
8
12
  } from "victory-core";
9
13
  import { defaults, assign, isObject } from "lodash";
10
- import CursorHelpers from "./cursor-helpers";
14
+ import { CursorHelpers } from "./cursor-helpers";
11
15
 
12
- export const cursorContainerMixin = (base) =>
13
- class VictoryCursorContainer extends base {
16
+ export type CursorCoordinatesPropType = CoordinatesPropType | number;
17
+
18
+ export interface VictoryCursorContainerProps extends VictoryContainerProps {
19
+ cursorComponent?: React.ReactElement;
20
+ cursorDimension?: "x" | "y";
21
+ cursorLabel?: ValueOrCallback<VictoryLabelProps["text"]>;
22
+ cursorLabelComponent?: React.ReactElement;
23
+ cursorLabelOffset?: CursorCoordinatesPropType;
24
+ defaultCursorValue?: CursorCoordinatesPropType;
25
+ disable?: boolean;
26
+ onCursorChange?: (
27
+ value: CursorCoordinatesPropType,
28
+ props: VictoryCursorContainerProps,
29
+ ) => void;
30
+ }
31
+
32
+ type ComponentClass<TProps> = { new (props: TProps): React.Component<TProps> };
33
+
34
+ export function cursorContainerMixin<
35
+ TBase extends ComponentClass<TProps>,
36
+ TProps extends VictoryCursorContainerProps,
37
+ >(Base: TBase) {
38
+ // @ts-expect-error "TS2545: A mixin class must have a constructor with a single rest parameter of type 'any[]'."
39
+ return class VictoryCursorContainer extends Base {
14
40
  static displayName = "VictoryCursorContainer";
15
41
  static propTypes = {
16
42
  ...VictoryContainer.propTypes,
@@ -134,7 +160,7 @@ export const cursorContainerMixin = (base) =>
134
160
  return [];
135
161
  }
136
162
 
137
- const newElements = [];
163
+ const newElements: React.ReactElement[] = [];
138
164
  const padding = this.getPadding(props);
139
165
  const cursorCoordinates = {
140
166
  x: horizontal ? scale.y(cursorValue.y) : scale.x(cursorValue.x),
@@ -205,5 +231,6 @@ export const cursorContainerMixin = (base) =>
205
231
  ];
206
232
  }
207
233
  };
234
+ }
208
235
 
209
- export default cursorContainerMixin(VictoryContainer);
236
+ export const VictoryCursorContainer = cursorContainerMixin(VictoryContainer);
package/src/index.d.ts DELETED
@@ -1,37 +0,0 @@
1
- import * as React from "react";
2
- import {
3
- VictoryContainerProps,
4
- CoordinatesPropType,
5
- CallbackArgs,
6
- } from "victory-core";
7
-
8
- export type CursorCoordinatesPropType = CoordinatesPropType | number;
9
-
10
- export interface VictoryCursorContainerProps extends VictoryContainerProps {
11
- cursorComponent?: React.ReactElement;
12
- cursorDimension?: "x" | "y";
13
- cursorLabel?: (point: CoordinatesPropType, args: CallbackArgs) => any | void;
14
- cursorLabelComponent?: React.ReactElement;
15
- cursorLabelOffset?: CursorCoordinatesPropType;
16
- defaultCursorValue?: CursorCoordinatesPropType;
17
- disable?: boolean;
18
- onCursorChange?: (
19
- value: CursorCoordinatesPropType,
20
- props: VictoryCursorContainerProps,
21
- ) => void;
22
- }
23
-
24
- export class VictoryCursorContainer extends React.Component<
25
- VictoryCursorContainerProps,
26
- any
27
- > {}
28
-
29
- export const CursorHelpers: {
30
- getDimension(props): any;
31
- withinBounds(point, bounds): any;
32
- onMouseMove(evt, targetProps): any;
33
- onMouseLeave(evt, targetProps): any;
34
- onTouchEnd(evt, targetProps): any;
35
- };
36
-
37
- export const cursorContainerMixin: (base: Function) => Function;
package/src/index.js DELETED
@@ -1,5 +0,0 @@
1
- export {
2
- cursorContainerMixin,
3
- default as VictoryCursorContainer,
4
- } from "./victory-cursor-container";
5
- export { default as CursorHelpers } from "./cursor-helpers";