import { Group as GGroup } from '@antv/g'; import EventEmitter from '@antv/event-emitter'; import { ICanvas, IContainer, IElement, IGroup, IShape } from './interface'; import { ClipCfg, ElementCfg, ElementFilterFn, ShapeAttrs, Point } from './types'; export default class Group extends EventEmitter implements IGroup { adaptedEle: GGroup; cfg: ElementCfg; attrs: ShapeAttrs; destroyed: boolean; isPaused: boolean; children: IElement[]; private canvas; constructor(cfg?: ElementCfg); getDefaultCfg(): { visible: boolean; capture: boolean; zIndex: number; children: any[]; }; /** * add a group to the canvas * @param cfg configurations for the added group * @returns the newly added group */ addGroup(cfg?: ElementCfg): any; /** * add a child to group * @param ele a shape or a group instance */ appendChild(ele: IElement): Promise; /** * @param shapeType the shape type, circle, rect, ellipse, polygon, image, marker, path, text, dom * @param cfg configurations for the added group * @returns the newly added group */ addShape(param1: any, param2: any): IShape; /** * sort the children according to the zIndex */ sort(): void; /** * get the canvas * @returns {ICanvas} the canvas */ getCanvas(): ICanvas; /** * get the parent group or canvas * @returns {IContainer} the parent group or canvas */ getParent(): IContainer; /** * get the children groups or shapes of the group * @returns {IElement[]} children groups or shapes */ getChildren(): IElement[]; /** * get the first child in the group * @returns {IElement} child group or shape */ getFirst(): IElement; /** * get the last child in the group * @returns {IElement} child group or shape */ getLast(): IElement; /** * get the number of the children of the group * @returns {number} number of the children */ getCount(): number; /** * get the child group or shape according to the index * @param {number} index * @returns {IElement} child group or shape */ getChildByIndex(index: number): IElement; /** * whether the group contains the element * @param {IElement} group or shape * @returns {boolean} contains or not */ contain(element: IElement): boolean; /** * remove the child group or shape from the group * @param {IElement} element group or shape * @param {boolean} destroy whether destroy the element in the same time */ removeChild(element: IElement, destroy?: boolean): void; /** * 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: string): 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[]; /** * the matrix of the group * @returns {number[]} the matrix */ getMatrix(): number[]; /** * apply matrix the group, same as setMatrix * @param {number[]} newMatrix */ applyMatrix(newMatrix: any): void; /** * apply matrix the group * @param {number[]} newMatrix */ setMatrix(newMatrix: number[]): void; /** * reset matrix to the unit matrix */ resetMatrix(): void; /** TODO: 待实现 */ applyToMatrix(vector: number[]): void; /** TODO: 待实现 */ invertFromMatrix(vector: number[]): void; /** * translate the group * @param {number} x the relative horizontal distance from current x * @param {number} y the relative vertical distance from current y * @return {IElement} group */ translate(x?: number, y?: number): IElement; /** * move the group to a target x and y * @param {number} toX the target x * @param {number} toY the target y * @return {IElement} group */ move(toX?: number, toY?: number): IElement; /** * move the group to a target x and y * @param {number} toX the target x * @param {number} toY the target y * @return {IElement} group */ moveTo(toX?: number, toY?: number): IElement; /** * scale the group * @param {number} ratioX ratio for horizontal * @param {number} ratioY ratio for vertical * @param {Point} center the scaling center, { x: 0, y: 0 } by default * @return {IElement} group */ scale(ratioX: number, ratioY?: number, center?: Point): IElement; /** * rotate the group at (0, 0) * @param {number} radian the radian of the rotation * @return {IElement} group */ rotate(radian: number): IElement; /** * rotate the group at (0, 0) * @param {number} radian the radian of the rotation * @return {IElement} group */ rotateAtStart(radian: number): IElement; /** * rotate the group at (x, y) * @param {number} x the rotate center x * @param {number} y the rotate center y * @param {number} radian the radian of the rotation * @return {IElement} group */ rotateAtPoint(x: number, y: number, radian: number): IElement; /** * set a clip for the group * @param {ClipCfg} clipCfg the clip configurations * @return {IShape} group */ setClip(clipCfg: ClipCfg): IShape; /** * get the clip shape of the group * @return {IShape} group */ getClip(): any; /** * get the global bounding box of the group * @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 group * @returns bbox */ getBBox(): { minX: number; maxX: number; minY: number; maxY: number; x: number; y: number; width: number; height: number; }; /** * set animate for the group * 1. animate(toAttrs: ElementAttrs, duration: number, easing?: string, callback?: () => void, delay?: number) * 2. animate(onFrame: OnFrame, duration: number, easing?: string, callback?: () => void, delay?: number) * 3. animate(toAttrs: ElementAttrs, cfg: AnimateCfg) * 4. animate(onFrame: OnFrame, cfg: AnimateCfg) * @param param1 toAttrs or onFrame * @param param2 duration or animateCfg * @param param3 ...args other configures */ animate(...args: any[]): (...args: any[]) => import("@antv/g").Animation; /** * stop all the animations on the group. the animations will be executed to the end */ stopAnimate(): void; /** * resume all the paused animation on the group */ resumeAnimate(): this; /** * pause all the animation on the group */ pauseAnimate(): this; /** * destroy and remove all the sub shapes */ clear(): void; /** * 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; /** * remove listener from the group * @param eventname the name of the event, e.g. 'click' * @param callback the listener function for the event */ off(eventname: string, callback: Function): this; /** * bind once listener to canvas * @param eventname the name of the event, e.g. 'click' * @param callback the listener function for the event */ once(eventname: string, callback: Function): this; /** * emit a event to the group * @param eventname the name of the event, e.g. 'click' * @param event the event object param for listener */ emit(eventname: string, event: object): this; /** * clone the group and its succeeds groups and shapes * @return {IGroup} the cloned group */ clone(): IGroup; /** * whether the element is a canvas, always returns false * @return {boolean} it is a canvas or not */ isCanvas(): boolean; /** * whether the element is a group, always returns true * @return {boolean} it is a group or not */ isGroup(): boolean; /** * get function * @param {string} key the key of the properties of group * @returns {any} the value of the properties of group with key */ get(key: any): any; /** * set function * @param {string} key the key of the properties of group * @param {any} value the value of the property with key */ set(name: any, value: any): void; /** * show the group */ show(): void; /** * hide the group */ hide(): void; /** * set zIndex for group and sort the parent group automatically */ setZIndex(zIndex: number): void; /** * front the group */ toFront(): void; /** * back the group */ toBack(): void; /** * get or set the attributes for the group * @param {string|ShapeAttrs} param1 the key of the attribute to get or set, or a ShapeAttrs to set all the attributes in param1 * @param {any} param2 set the value for the key param1 if param1 is a string */ attr(param1: string | ShapeAttrs, param2?: any): any | void; /** * remove the group from its parent group */ remove(destroy?: boolean): void; /** * whether the animation is paused * @return {boolean} is paused */ isAnimatePaused(): boolean; /** * destroy the canvas */ destroy(): void; }