Skip to content

Commit b9ad73c

Browse files
committed
More descriptive types for Hammer.js events
This required adding @types/hammerjs; see https://stackoverflow.com/a/46011417/25507.
1 parent bfd207d commit b9ad73c

File tree

4 files changed

+19
-4
lines changed

4 files changed

+19
-4
lines changed

package-lock.json

+11
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@
8282
"chart.js": ">=3.2.0"
8383
},
8484
"dependencies": {
85+
"@types/hammerjs": "^2.0.45",
8586
"hammerjs": "^2.0.8"
8687
}
8788
}

types/options.d.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Chart, Color, Point } from 'chart.js';
2-
2+
import { Input as HammerInput } from 'hammerjs';
33

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

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

175175
export interface ScaleLimits {

types/tests/exports.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,10 @@ const chart = new Chart('id', {
3434
},
3535
pan: {
3636
enabled: true,
37-
mode: 'x'
37+
mode: 'x',
38+
onPanStart({ event }) {
39+
return event.distance > 2;
40+
}
3841
},
3942
zoom: {
4043
wheel: {

0 commit comments

Comments
 (0)