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.

190 lines
6.7 KiB

4 months ago
import type { RectStyleProps } from '@antv/g';
import type { Graph } from '../runtime/graph';
import type { RuntimeContext } from '../runtime/types';
import type { ElementType, ID, IPointerEvent, Point, State } from '../types';
import type { ShortcutKey } from '../utils/shortcut';
import type { BaseBehaviorOptions } from './base-behavior';
import { BaseBehavior } from './base-behavior';
/**
* <zh/>
*
* <en/> Brush select options
*/
export interface BrushSelectOptions extends BaseBehaviorOptions {
/**
* <zh/>
*
* <en/> Whether to enable animation.
* @defaultValue false
*/
animation?: boolean;
/**
* <zh/>
*
* <en/> Whether to enable Brush select element function.
* @defaultValue true
*/
enable?: boolean | ((event: IPointerEvent) => boolean);
/**
* <zh/>
*
* <en/> Enable Elements type.
* @defaultValue ['node', 'combo', 'edge']
*/
enableElements?: ElementType[];
/**
* <zh/>
*
* <en/> Press this shortcut key to apply brush select with mouse click.
* @remarks
* <zh/> `trigger` `['drag']` `drag-canvas`
*
* <en/> Note that setting `trigger` to `['drag']` will cause the `drag-canvas` behavior to fail. The two cannot be configured at the same time.
* @defaultValue ['shift']
*/
trigger?: ShortcutKey;
/**
* <zh/>
*
* <en/> The state to switch to when selected.
* @defaultValue 'selected'
*/
state?: State;
/**
* <zh/>
* - `'union'` state
* - `'intersect'` state
* - `'diff'` state
* - `'default'` state
*
* <en/> Brush select mode
* - `'union'`: Keep the current state of the selected elements and add the specified state.
* - `'intersect'`: If the selected elements already have the specified state, keep it; otherwise, clearBrush it.
* - `'diff'`: Perform a negation operation on the specified state of the selected elements.
* - `'default'`: Clear the current state of the selected elements and add the specified state.
* @defaultValue 'default'
*/
mode?: 'union' | 'intersect' | 'diff' | 'default';
/**
* <zh/> , `default`
*
* <en/> Whether to brush select immediately, only valid when the brush select mode is `default`
* @defaultValue false
*/
immediately?: boolean;
/**
* <zh/>
*
* <en/> Timely screening.
*/
style?: RectStyleProps;
/**
* <zh/>
*
* <en/> Callback when brush select elements.
* @param states -
* @returns
*/
onSelect?: (states: Record<ID, State | State[]>) => Record<ID, State | State[]>;
}
/**
* <zh/>
*
* <en/> Brush select elements
*/
export declare class BrushSelect extends BaseBehavior<BrushSelectOptions> {
static defaultOptions: Partial<BrushSelectOptions>;
private startPoint?;
private endPoint?;
private rectShape?;
private shortcut?;
constructor(context: RuntimeContext, options: BrushSelectOptions);
/**
* Triggered when the pointer is pressed
* @param event - Pointer event
* @internal
*/
protected onPointerDown(event: IPointerEvent): void;
/**
* Triggered when the pointer is moved
* @param event - Pointer event
* @internal
*/
protected onPointerMove(event: IPointerEvent): void;
/**
* Triggered when the pointer is released
* @param event - Pointer event
* @internal
*/
protected onPointerUp(event: IPointerEvent): void;
/**
* <zh/>
*
* <en/> Clear state
* @internal
*/
protected clearStates(): void;
/**
* <zh/>
*
* <en/> Clear the state of all elements on the canvas
* @internal
*/
protected clearElementsStates(): void;
/**
* <zh/>
*
* <en/> Update the state of the selected elements
* @param points - <zh/> | <en/> The vertex of the selection area
* @internal
*/
protected updateElementsStates(points: Point[]): void;
/**
* <zh/> combo combo
*
* <en/> Find the elements displayed in the specified area on the canvas. A node is selected if the center of its bbox is inside the rect; An edge is selected if both end nodes are inside the rect ;A combo is selected if the center of its bbox is inside the rect.
* @param graph - <zh/> | <en/> Graph instance
* @param points - <zh/> | <en/> The vertex of the selection area
* @param itemTypes - <zh/> | <en/> Element type
* @returns <zh/> ID | <en/> Selected element ID array
* @internal
*/
protected selector(graph: Graph, points: Point[], itemTypes: ElementType[]): ID[];
private clearBrush;
/**
* <zh/> trigger
*
* <en/> Is the current key consistent with the trigger configuration
* @returns <zh/> | <en/> Is consistent
* @internal
*/
protected isKeydown(): boolean;
/**
* <zh/>
*
* <en/> Verify whether brush select is enabled
* @param event - <zh/> | <en/> Event
* @returns <zh/> | <en/> Whether to enable
* @internal
*/
protected validate(event: IPointerEvent): boolean;
private bindEvents;
private unbindEvents;
/**
* <zh/>
*
* <en/> Update configuration
* @param options - <zh/> | <en/> Options
* @internal
*/
update(options: Partial<BrushSelectOptions>): void;
/**
* <zh/>
*
* <en/> Destroy
* @internal
*/
destroy(): void;
}
export declare const getCursorPoint: (event: IPointerEvent, graph: Graph) => Point;