import { Canvas as GCanvas, CanvasConfig, Group as GGroup } from '@antv/g'; import EventEmitter from '@antv/event-emitter'; import { ICanvas, IElement } from './interface'; import { AnimateCfg, Cursor, ElementCfg, OnFrame, Point, ElementFilterFn } from './types'; import { IGroup } from '.'; export default class Canvas extends EventEmitter implements ICanvas { destroyed: boolean; renderer: 'svg' | 'canvas' | 'webgl' | any; rendererType: 'svg' | 'canvas' | 'webgl'; adaptedEle: GGroup; canvasEle: GCanvas; isPaused: boolean; isReady: boolean; private children; private rootGroup; constructor(cfg: CanvasConfig); /** * add a group to the root group of the canvas * @param cfg configurations for the added group * @returns the newly added group */ addGroup(cfg?: ElementCfg): IGroup; /** * add a child to the root group of the canvas * @param ele a shape or a group instance */ appendChild(ele: IElement): Promise; /** * get the children groups or shapes of the canvas's root group * @returns children elements */ getChildren(): IElement[]; /** * get the root group of the canvas * @returns {IGroup} the root group */ getGroup(): IGroup; getMatrix(): number[]; /** * get the canmera * @returns the canmera */ getCamera(): import("@antv/g").Camera; /** * get function * @param {string} key the key of the properties of canvas * @returns {any} the value of the properties of canvas with key. if the key is 'el', returns the DOM node of the canvas */ get(key: string): any; /** * set function * @param {string} key the key of the properties of canvas * @param {any} value the value of the property with key */ set(key: string, value: any): void; /** * get the global bounding box of the root group of the canvas * @returns bbox */ getCanvasBBox(): { minX: number; maxX: number; minY: number; maxY: number; x: number; y: number; width: number; height: number; }; /** * get the local bounding box of the root group of the canvas * @returns bbox */ getBBox(): { minX: number; maxX: number; minY: number; maxY: number; x: number; y: number; width: number; height: number; }; /** * bind listener to canvas * @param eventname the name of the event, e.g. 'click' * @param callback the listener function for the event * @param once only listen once */ on(eventname: string, callback: Function, once?: boolean): this; /** * bind once listener to the root group of the canvas * @param eventname the name of the event, e.g. 'click' * @param callback the listener function for the event * @param once only listen once */ once(eventname: string, callback: Function): this; /** * remove listener from the root group of the canvas * @param eventname the name of the event, e.g. 'click' * @param callback the listener function for the event */ off(eventname: string, callback: Function): this; /** * emit a event to the root group of the canvas * @param eventname the name of the event, e.g. 'click' * @param event the event object param for listener */ emit(eventname: string, event: object): this; /** * if the object is a canvas * @returns {boolean} return true to distinguish from shape and group */ isCanvas(): boolean; /** * if the object is a group * @returns {boolean} return true to distinguish from shape and group */ isGroup(): boolean; /** * change the size of the canvas * @param {number} width new width for canvas * @param {number} height new height for canvas */ changeSize(width: number, height: number): void; /** * get the renderer of the canvas * @returns {Renderer} current renderer */ getRenderer(): 'svg' | 'canvas' | 'webgl'; /** * the parent of the canvas is null * @returns null */ getParent(): any; /** * get the cursor of the canvas * @return {Cursor} */ getCursor(): Cursor; /** * set the cursor for the canvas * @param {Cursor} cursor */ setCursor(cursor: Cursor): void; /** TOOD: 是否需要实现 */ draw(): void; /** * set up the animate for the canvas * @param onFrame will be called in each frame * @param animateCfg the configuration of the animation */ animate(onFrame: OnFrame, animateCfg?: AnimateCfg): void; /** * stop all the animations on the canvas. the animations will be executed to the end */ stopAnimate(): void; /** * resume all the paused animation on the canvas */ resumeAnimate(): this; /** * pause all the animation on the canvas */ pauseAnimate(): this; /** * transform canvas DOM coordinate to drawing coordinate * @param {number} canvasX x in canvas DOM coordinate * @param {number} canvasY y in canvas DOM coordinate */ getPointByCanvas(canvasX: number, canvasY: number): Point; /** * transform drawing coordinate to canvas DOM coordinate * @param {number} x x in drawing coordinate * @param {number} y y in drawing coordinate */ getCanvasByPoint(x: number, y: number): Point; /** * transform client coordinate to drawing coordinate * @param {number} clientX x in client coordinate * @param {number} clientY y in client coordinate */ getPointByClient(clientX: number, clientY: number): Point; /** * transform drawing coordinate to client coordinate * @param {number} clientX x in drawing coordinate * @param {number} clientY y in drawing coordinate */ getClientByPoint(pointX: number, pointY: number): Point; /** * find a child according to the fun * @param {ElementFilterFn} fn matching function * @return {Element | null} the matched child element */ find(fn: ElementFilterFn): IElement | null; /** * find a child by id * @param {string} id id of the child shape or group * @return {Element | null} the matched child element */ findById(id: any): IElement | null; /** * find a child by className or name * @param {string} name name of the child shape or group * @return {Element | null} the matched child element */ findByClassName(name: string): IElement; /** * find all the matched child according to the fun * @param {ElementFilterFn} fn matching function * @return {Element | null} the matched child element */ findAll(fn: ElementFilterFn): IElement[]; /** * find all the matched child by name * @param {string} name the name of the child shape or group * @return {Element | null} the matched child element */ findAllByName(name: string): IElement[]; /** * clear the canvas */ clear(): void; /** * destroy the canvas */ destroy(): void; }