Skip to content

Commit

Permalink
More descriptive types for Hammer.js events
Browse files Browse the repository at this point in the history
This required adding @types/hammerjs; see https://stackoverflow.com/a/46011417/25507.
  • Loading branch information
joshkel committed Jul 29, 2024
1 parent bfd207d commit b9ad73c
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 4 deletions.
11 changes: 11 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@
"chart.js": ">=3.2.0"
},
"dependencies": {
"@types/hammerjs": "^2.0.45",
"hammerjs": "^2.0.8"
}
}
6 changes: 3 additions & 3 deletions types/options.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Chart, Color, Point } from 'chart.js';

import { Input as HammerInput } from 'hammerjs';

type Mode = 'x' | 'y' | 'xy';
type Key = 'ctrl' | 'alt' | 'shift' | 'meta';
Expand Down Expand Up @@ -167,9 +167,9 @@ export interface PanOptions {
* Function called when pan fails because modifier key was not detected.
* event is the a hammer event that failed - see https://hammerjs.github.io/api#event-object
*/
onPanRejected?: (context: { chart: Chart, event: Event }) => void;
onPanRejected?: (context: { chart: Chart, event: HammerInput }) => void;

onPanStart?: (context: { chart: Chart, event: Event, point: Point }) => boolean | undefined;
onPanStart?: (context: { chart: Chart, event: HammerInput, point: Point }) => boolean | undefined;
}

export interface ScaleLimits {
Expand Down
5 changes: 4 additions & 1 deletion types/tests/exports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,10 @@ const chart = new Chart('id', {
},
pan: {
enabled: true,
mode: 'x'
mode: 'x',
onPanStart({ event }) {
return event.distance > 2;
}
},
zoom: {
wheel: {
Expand Down

0 comments on commit b9ad73c

Please sign in to comment.