You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

102 lines
3.0 KiB

4 months ago
import type { RuntimeContext } from '../runtime/types';
import type { IKeyboardEvent } from '../types';
import { ShortcutKey } from '../utils/shortcut';
import type { BaseBehaviorOptions } from './base-behavior';
import { BaseBehavior } from './base-behavior';
/**
* <zh/>
*
* <en/> Scroll canvas behavior options
*/
export interface ScrollCanvasOptions extends BaseBehaviorOptions {
/**
* <zh/>
*
* <en/> Whether to enable the function of scrolling the canvas
* @defaultValue true
*/
enable?: boolean | ((event: WheelEvent | IKeyboardEvent) => boolean);
/**
* <zh/> 使
*
* <en/> The way to trigger scrolling, default to scrolling with the pointer pressed
*/
trigger?: {
up: ShortcutKey;
down: ShortcutKey;
left: ShortcutKey;
right: ShortcutKey;
};
/**
* <zh/>
* -
* - `'x'` :
* - `'y'` :
*
* <en/> The allowed rolling direction
* - by default, there is no restriction
* - `'x'`: only allow horizontal scrolling
* - `'y'`: only allow vertical scrolling
*/
direction?: 'x' | 'y';
/**
* <zh/> [0, Infinity]
*
* <en/> The scrollable viewport range allows you to scroll up to one screen by default. You can set the range for each direction (top, right, bottom, left) individually, with each direction's range between [0, Infinity]
* @defaultValue 1
*/
range?: number | number[];
/**
* <zh/>
*
* <en/> Scroll sensitivity
* @defaultValue 1
*/
sensitivity?: number;
/**
* <zh/>
*
* <en/> Callback when scrolling is completed
*/
onFinish?: () => void;
/**
* <zh/>
*
* <en/> Whether to prevent the default event
* @defaultValue true
*/
preventDefault?: boolean;
}
/**
* <zh/>
*
* <en/> Scroll canvas behavior
*/
export declare class ScrollCanvas extends BaseBehavior<ScrollCanvasOptions> {
static defaultOptions: Partial<ScrollCanvasOptions>;
private shortcut;
constructor(context: RuntimeContext, options: ScrollCanvasOptions);
/**
* <zh/>
*
* <en/> Update options
* @param options - <zh/> | <en/> Options
* @internal
*/
update(options: Partial<ScrollCanvasOptions>): void;
private bindEvents;
get graphDom(): import("@antv/g").CanvasLike | null;
private onWheel;
private formatDisplacement;
private clampByDirection;
private clampByRange;
private scroll;
private validate;
/**
* <zh/>
*
* <en/> Destroy the canvas scrolling
*/
destroy(): void;
}