Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More descriptive types for Hammer.js events #822

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading