g6/types/g.d.ts

263 lines
6.1 KiB
TypeScript
Raw Normal View History

export declare namespace G {
2019-10-21 11:44:16 +08:00
export type ShapeType =
| 'arc'
| 'circle'
| 'dom'
| 'ellipse'
| 'fan'
| 'image'
| 'line'
| 'marker'
| 'path'
| 'polygon'
| 'polyline'
| 'rect'
| 'text';
type Item = Shape | Group;
type Cfg = { [k in string]: any };
type Attrs = { [k in string]: any };
interface Box {
x: number;
y: number;
minX: number;
minY: number;
maxX: number;
maxY: number;
centerX: number;
centerY: number;
width: number;
height: number;
2019-10-21 11:44:16 +08:00
}
export interface Group extends Element {
new (cfg: Cfg): Group;
isGroup: true;
type: 'group';
canFill: boolean;
canStroke: boolean;
getDefaultCfg(): Cfg;
addShape(type: ShapeType, cfg: Cfg): Shape;
/**
* @param {Function|Object|undefined} param
* @param {Object} cfg
* @return {Object} rst
*/
addGroup(param: Function | Cfg | undefined, cfg: Cfg): Group;
/**
* @param {Array} padding
* @param {Attrs} attrs
* @return {Object}
*/
renderBack(padding: [number, number, number, number], attrs: Attrs): Shape;
removeChild(item: Item, destroy: boolean): this;
/**
* shape或者group
* @param {Object} items
* @return {Object} group
*/
add(items: Item[]): this;
contain(item: Item): boolean;
getChildByIndex(index: number): any;
getFirst(): Item;
getLast(): Item;
getBBox(): Box;
getCount(): number;
sort(): this;
findById(): Item;
findByClassName(className: string): Item;
2019-10-21 11:44:16 +08:00
/**
*
* @param {Function} fn
* @return {Canvas.Base}
*/
find(fn: Function | string): Item;
/**
* @param {Function} fn filter mathod
* @return {Array} all the matching shapes and groups
*/
findAll(fn: (...args: any[]) => boolean): Item[];
/**
* @Deprecated
*/
findBy: Function;
/**
* @Deprecated
*/
findAllBy: Function;
getShape(x: any, y: any): Shape;
clearTotalMatrix(): void;
clear(delayRemove?: boolean): this;
destroy(): void;
clone(): Group;
}
export interface Shape extends Element {
new (cfg: Cfg): Shape;
isPointInPath(x: number, y: number): boolean;
isShape: true;
drawInner(context: any): void;
/**
*
* @return {Boolean} [description]
*/
isHitBox(): boolean;
/**
*
* @param {Number} x x坐标
* @param {Number} y y坐标
* @return {Boolean}
*/
isHit(x: number, y: number): boolean;
/**
* 线线
*/
getHitLineWidth(): number;
/**
*
*/
clearTotalMatrix(): void;
clearBBox(): void;
getBBox(): Box;
clone(): Shape;
}
interface Element extends Attribute, Transform, Animate, AdvancedEventEmitter {
new (): Element;
init(): void;
getParent(): Element;
/**
*
* @protected
* @return {Object}
*/
getDefaultCfg(): Cfg;
set(name: string, value: any): this;
/**
* @deprecated
*/
setSilent: Function;
get(name: string): any;
show(): this;
hide(): this;
remove(destroy: boolean | undefined, delayRemove?: boolean): this;
destroy(): void;
toFront(): void;
toBack(): void;
setZIndex(zIndex: number): number;
clone(): Element;
getBBox(): any;
}
interface Attribute {
canFill: boolean;
canStroke: boolean;
initAttrs(attrs: Attrs): this;
/**
* @protected
*/
getDefaultAttrs(): any;
/**
* 4
* - name ,
* - name value
* - name value this
* - name value
*
* @param {String | Object} name
* @param {*} value
* @return {*}
*/
attr(): Attrs;
attr(name: string): any;
attr(name: string, value: any): this;
attr(attrs: Attrs): this;
clearBBox(): void;
hasFill(): boolean;
hasStroke(): boolean;
}
interface Transform {
initTransform(): void;
resetMatrix(): void;
translate(tx: number, ty: number): this;
rotate(radian: number): this;
scale(s1: number, s2: number): this;
rotateAtStart(rotate: number): this;
move(x: number, y: number): this;
transform(ts: [string, number, number?]): this;
setTransform(ts: [string, number, number?]): this;
getMatrix(): any;
setMatrix(m: any): this;
apply(v: any, root: any): this;
getTotalMatrix(): any;
clearTotalMatrix: Function;
invert(v: any): this;
resetTransform(context: any): void;
}
interface Animate {
/**
*
* @param {Object} toProps
* @param {Number} duration
* @param {String} easing
* @param {Function} callback
* @param {Number} delay
*/
animate(
toProps: { onFrame?: any; repeat?: any },
duration: number,
easing: string,
callback: Function,
delay: number,
): void;
stopAnimate(): void;
pauseAnimate(): this;
resumeAnimate(): this;
}
interface AdvancedEventEmitter extends EventEmitter {
new (): AdvancedEventEmitter;
emit(evt: string, e?: Event): void;
}
interface EventEmitter {
new (): EventEmitter;
on(evt: string, callback: Function, one: any): this;
one(evt: string, callback: Function): this;
emit(evt: string): void;
trigger(): void;
off(evt: string, callback: Function): this | undefined;
removeEvent(): this;
}
}