Skip to content

Commit

Permalink
feat(types): add Gesture
Browse files Browse the repository at this point in the history
  • Loading branch information
fjc0k committed Jul 6, 2020
1 parent 7dcd22b commit 253ba56
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 0 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@
"@antv/scale": "0.1.3",
"@antv/util": "~2.0.6",
"@babel/runtime": "^7.7.7",
"@types/hammerjs": "^2.0.36",
"hammerjs": "^2.0.8",
"type-fest": "^0.15.1"
}
Expand Down
44 changes: 44 additions & 0 deletions types/Gesture.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import Hammer from 'hammerjs';

/**
* hammerjs 的选项。
*/
type HammerOptions = typeof Hammer extends new (
el: any,
options: infer X,
) => any
? Exclude<X, undefined>
: never;

/**
* 手势参数。
*/
export interface GestureParams {
/**
* 需要绑定的手势事件,配置的属性为以事件名为 key 的回调方法。
*
* @todo 完善回调函数参数定义
*/
gesture?: Record<string, (data: any, event: any) => any>;

/**
* 传递给 hammer 的参数配置。一般不需要配置。
*
* @see http://hammerjs.github.io/api/#hammer.defaults
*/
hammerOptions?: HammerOptions;

/**
* 手势插件的配置。
*/
options?: {
/**
* 计算手势数据点,如果不需要可以关闭提高性能。
*/
useCalculate?: boolean;
/**
* 计算数据是否需要计算图表相对页面偏移的坐标。当图表宽度超出, scroll模式,计算位置需要加。
*/
useOffset?: boolean;
};
}
2 changes: 2 additions & 0 deletions types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ import {
InteractionSwipeParams,
InteractionParams,
} from './Interaction';
import { GestureParams } from './Gesture';

declare namespace F2 {
export {
Expand Down Expand Up @@ -146,6 +147,7 @@ declare namespace F2 {
InteractionPinchParams,
InteractionSwipeParams,
InteractionParams,
GestureParams,
};
}

Expand Down

0 comments on commit 253ba56

Please sign in to comment.