g6/types/index.d.ts

1161 lines
28 KiB
TypeScript
Raw Normal View History

2019-10-21 11:44:16 +08:00
/// <reference path="./g.d.ts" />
import {
deepMix,
mix,
debounce,
each,
throttle,
isNil,
isArray,
remove,
extend,
augment,
clone,
uniqueId,
isNumber,
isPlainObject,
isString,
isObject,
wrapBehavior,
upperFirst,
} from '@antv/util';
import vec2 from '@antv/util/lib/matrix/vec2';
import vec3 from '@antv/util/lib/matrix/vec3';
import mat3 from '@antv/util/lib/matrix/mat3';
import transform from '@antv/util/lib/matrix/transform';
import createDom from '@antv/util/lib/dom/create-dom';
import modifyCSS from '@antv/util/lib/dom/modify-css';
import addEventListener from '@antv/util/lib/dom/add-event-listener';
import { G } from './g';
/**
*
*/
type ElementType = 'node' | 'edge';
2019-10-30 16:25:11 +08:00
interface IMode {
type: string;
[key: string]: any;
}
2019-10-21 11:44:16 +08:00
2019-10-30 16:25:11 +08:00
interface G6Event extends MouseEvent {
item: G6.Node & G6.Edge;
target: any;
}
2019-10-21 11:44:16 +08:00
2019-10-30 16:25:11 +08:00
// tslint:disable-next-line:export-just-namespace
export = G6;
export as namespace G6;
2019-10-21 11:44:16 +08:00
2019-10-30 16:25:11 +08:00
declare namespace G6 {
interface EdgeConfig {
source: string;
target: string;
[key: string]: any;
}
2019-10-21 11:44:16 +08:00
2019-10-30 16:25:11 +08:00
interface NodeConfig {
id?: string;
[key: string]: any;
}
2019-10-21 11:44:16 +08:00
/**
2019-10-30 16:25:11 +08:00
*
2019-10-21 11:44:16 +08:00
*/
2019-10-30 16:25:11 +08:00
interface Point {
x: number;
y: number;
}
2019-10-21 11:44:16 +08:00
/**
2019-10-30 16:25:11 +08:00
*
2019-10-21 11:44:16 +08:00
*/
2019-10-30 16:25:11 +08:00
interface Rect extends Point {
width: number;
height: number;
}
2019-10-21 11:44:16 +08:00
/**
2019-10-30 16:25:11 +08:00
*
2019-10-21 11:44:16 +08:00
*/
2019-10-30 16:25:11 +08:00
interface Circle extends Point {
r: number;
}
2019-10-21 11:44:16 +08:00
/**
2019-10-30 16:25:11 +08:00
*
2019-10-21 11:44:16 +08:00
*/
2019-10-30 16:25:11 +08:00
interface Ellipse extends Point {
rx: number;
ry: number;
}
2019-10-21 11:44:16 +08:00
export class Item {
constructor(cfg: any);
isItem(): boolean;
getDefaultCfg(): any;
getKeyShapeStyle(): any;
/**
*
* @return {Array}
*/
getStates(): any;
/**
*
* @param {String} state
* @return {Boolean}
*/
hasState(state: string): boolean;
getStateStyle(state: string): any;
getOriginStyle(): any;
getCurrentStatesStyle(): any;
/**
* visible
* @internal graph 使
* @param {String} state
* @param {Boolean} enable
*/
setState(state: string, enable: boolean): void;
clearStates(states: string | string[]): void;
/**
*
* @return {G.Group}
*/
getContainer(): G.Group;
/**
* 线
* @return {G.Shape}
*/
getKeyShape(): G.Shape;
/**
*
* @return {Object}
*/
getModel<T = any>(): T;
/**
*
* @return {string}
*/
getType(): string;
getShapeCfg(model: any): any;
/**
*
* 1. item model
* 2.
*
* shape
*/
refresh(): void;
/**
* model
* @internal Graph 使 graph.update
* @param {Object} cfg
*/
update(cfg: any): void;
/**
*
*/
updateShape(): void;
/**
*
* @param {object} cfg
*/
updatePosition(cfg: any): void;
/**
* / cache
*/
clearCache(): void;
/**
*
*/
draw(): void;
/**
*
*/
getBBox(): G.Box;
/**
*
*/
toFront(): void;
/**
*
*/
toBack(): void;
/**
*
*/
show(): void;
/**
*
*/
hide(): void;
/**
*
* @param {Boolean} visible
*/
changeVisibility(visible: boolean): void;
/**
2019-11-06 15:56:01 +08:00
*
* @param {Boolean} enable
*/
enableCapture(enable: boolean): void;
isVisible(): boolean;
get(key: string): any;
set(key: string, value: any): void;
}
2019-10-30 16:25:11 +08:00
export class Edge extends Item {
setSource(source: any): void;
2019-10-21 11:44:16 +08:00
2019-10-30 16:25:11 +08:00
setTarget(target: any): void;
2019-10-21 11:44:16 +08:00
2019-10-30 16:25:11 +08:00
getSource(): any;
2019-10-21 11:44:16 +08:00
2019-10-30 16:25:11 +08:00
getTarget(): any;
}
2019-10-21 11:44:16 +08:00
2019-10-30 16:25:11 +08:00
export class Node extends Item {
/**
*
* @return {Array}
*/
getEdges(): Edge[];
2019-10-21 11:44:16 +08:00
2019-10-30 16:25:11 +08:00
/**
* target == this
* @return {Array}
*/
getInEdges(): any[];
2019-10-21 11:44:16 +08:00
2019-10-30 16:25:11 +08:00
/**
* source == this
* @return {Array}
*/
getOutEdges(): any[];
2019-10-21 11:44:16 +08:00
2019-10-30 16:25:11 +08:00
/**
*
* @param {Number} index
* @return {Object} {x,y}
*/
getLinkPointByAnchor(index: number): G6.Point;
/**
*
* @param {Object} point
* @return {Object} {x,y}
*/
getLinkPoint(point: G6.Point): G6.Point;
/**
*
* @param {Edge} edge
*/
addEdge(edge: Edge): void;
/**
*
* @param {Edge} edge
*/
removeEdge(edge: Edge): void;
clearCache(): void;
/**
*
* @return {array} anchorPoints {x,y,...cfg}
*/
getAnchorPoints(): any;
}
2019-10-21 11:44:16 +08:00
interface GraphOptions {
/**
* DOM DOM id HTML
*/
container: string | HTMLElement;
/**
* 'px'
*/
width: number;
/**
* 'px'
*/
height: number;
/**
* canvas和svg
*/
renderer?: 'canvas' | 'svg';
2019-10-30 16:25:11 +08:00
fitView?: boolean;
layout?: any;
2019-10-21 11:44:16 +08:00
/**
*
* , fitViewPadding: 20
* fitViewPadding: [20, 40, 50,20]
*
*/
fitViewPadding?: number[] | number;
/**
* false
* true
*/
groupByTypes?: boolean;
2019-10-30 16:25:11 +08:00
groupStyle?: {
default?: any;
hover?: any;
/**
*
*/
collapseStyle?: any;
};
2019-10-21 11:44:16 +08:00
/**
* setAutoPaint()
* true
*/
autoPaint?: boolean;
/**
* G6中的Mode文档
*/
modes?: {
2019-10-30 16:25:11 +08:00
default?: Array<string | IMode>;
addNode?: Array<string | IMode>;
addEdge?: Array<string | IMode>;
2019-10-21 11:44:16 +08:00
};
/**
* G6
*/
nodeStyle?: any;
/**
* G6
*/
edgeStyle?: any;
/**
* shape, size, color data
*/
defaultNode?: any;
/**
* shape, size, color data
*/
defaultEdge?: any;
2019-10-30 16:25:11 +08:00
nodeStateStyles?: any;
edgeStateStyles?: any;
2019-10-21 11:44:16 +08:00
/**
* graph plugin
*/
plugins?: any[];
/**
*
*/
animate?: boolean;
/**
* animate为true时有效
*/
animateCfg?: {
/**
*
*/
onFrame?: Function | null;
/**
*
*/
duration?: number;
/**
*
* easeLinear
*/
easing?: string;
};
/**
*
* 0.2
*/
minZoom?: number;
/**
*
* 10
*/
maxZoom?: number;
/**
*
* 1.0
*/
pixelRatio?: number;
2019-10-30 16:25:11 +08:00
groupType?: string;
/**
* Edge
*/
linkCenter?: boolean;
2019-10-21 11:44:16 +08:00
}
/**
* Graph Class
*/
export class Graph {
constructor(options: GraphOptions);
on<T = G6Event>(eventName: string, handler: (e: T) => void): void;
emit(eventName: string, params: object): void;
2019-10-21 11:44:16 +08:00
/**
*
* @param key
*/
get(key: string): any;
/**
*
* @param key
* @param val
*/
set(key: string, val: any): this;
/**
*
* @param {string|object} item id或元素实例
* @param {object} cfg
*/
update(item: any, cfg: any): void;
/**
*
* @param {string|object} item id或元素实例
* @param {object} cfg
*/
updateItem(item: any, cfg: any): void;
/**
*
* @param {string|object} item id或元素实例
* @param state
* @param enabled
*/
setItemState(item: any, state: string, enabled: boolean): void;
/**
*
* @param {string|object} item id或元素实例
* @param states
*/
2019-10-30 16:25:11 +08:00
clearItemStates(item: any, states?: string[] | string | null): void;
2019-10-21 11:44:16 +08:00
/**
*
* @param type (node | edge)
* @param {object} model
* @return {object}
*/
add(type: ElementType, model: any): void;
/**
*
* @param {string} type (node | edge | group)
* @param {object} model
* @return {object}
*/
addItem(type: ElementType | 'group', model: any): any;
/**
*
* @param {string|object} item id或元素实例
*/
remove(item: string | object): void;
/**
*
* @param {string|object} item id或元素实例
*/
removeItem(item: string | object): void;
/**
*
* @param {object} data
*/
2019-10-30 16:25:11 +08:00
data(data: { edges?: EdgeConfig[]; nodes?: NodeConfig[]; [key: string]: any }): any;
2019-10-21 11:44:16 +08:00
/**
* keyShape
*
* graph.node(node => {
* return {
* {
shape: 'rect',
label: node.id,
style: { fill: '#666' },
stateStyles: {
selected: { fill: 'blue' },
custom: { fill: 'green' }
}
}
* }
* });
* @param {function} nodeFn
*/
node(nodeFn: Function): void;
/**
*
* @param {function} edgeFn , node
*/
edge(edgeFn: Function): any;
/**
*
* @param {string|object} item id或元素实例
*/
refreshItem(item: string | object): void;
/**
*
*/
refresh(): void;
/**
*
*/
refreshPositions(): void;
/**
* data接口的数据渲染视图
*/
render(): void;
/**
*
* @param {object} data
* @param {string} groupType group类型
*/
renderCustomGroup(data: any, groupType: string): any;
/**
*
* @Param {Object} data
*/
2019-11-19 10:27:01 +08:00
read(data: { edges?: EdgeConfig[]; nodes?: NodeConfig[]; [key: string]: any }): void;
2019-10-21 11:44:16 +08:00
/**
*
* @param {object} data
* @return {object} this
*/
2019-11-19 10:27:01 +08:00
changeData(data?: { edges?: EdgeConfig[]; nodes?: NodeConfig[]; [key: string]: any }): this;
2019-10-21 11:44:16 +08:00
/**
*
*/
paint(): void;
/**
*
* @return {object} data
*/
save(): any;
/**
*
* @param {number} width
* @param {number} height
* @return {object} this
*/
changeSize(width: number, height: number): this;
/**
*
* @param {number} dx
* @param {number} dy
*/
translate(dx: number, dy: number): void;
/**
*
* @param {number} x
* @param {number} y
*/
moveTo(x: number, y: number): void;
/**
*
* @param {object} padding
*/
fitView(padding?: any): void;
/**
*
* @param {string|array} behaviors
* @param {string|array} modes
* @return {object} this
*/
addBehaviors(behaviors: string | string[], modes: string | string[]): this;
/**
*
* @param {string|array} behaviors
* @param {string|array} modes
* @return {object} this
*/
removeBehaviors(behaviors: string | string[], modes: string | string[]): this;
/**
*
* @param {string} mode
* @return {object} this
*/
setMode(mode: string): this;
/**
*
* @return {string}
*/
getCurrentMode(): string;
/**
*
* @return {number}
*/
getZoom(): number;
/**
* item实例
* @return {array} item数组
*/
2019-11-19 10:27:01 +08:00
getNodes(): G6.NodeConfig[];
2019-10-21 11:44:16 +08:00
/**
* item实例
* @return {array} item数组
*/
2019-10-30 16:25:11 +08:00
getEdges(): G6.EdgeConfig[];
2019-10-21 11:44:16 +08:00
/**
*
* @param {number} ratio
* @param {object} center center的x, y坐标为中心缩放
*/
2019-11-19 10:27:01 +08:00
zoom(ratio: number, center?: object): void;
2019-10-21 11:44:16 +08:00
/**
*
* @param {number} toRatio
* @param {object} center center的x, y坐标为中心缩放
*/
2019-11-19 10:27:01 +08:00
zoomTo(toRatio: number, center?: object): void;
2019-10-21 11:44:16 +08:00
/**
* graph animateCfg
*/
positionsAnimate(): void;
stopAnimate(): void;
isAnimating(): boolean;
/**
*
* @param {string|object} item
*/
focusItem(item: string | object): void;
/**
*
* @param {number} clientX x坐标
* @param {number} clientY y坐标
* @return {object}
*/
getPointByClient(clientX: number, clientY: number): any;
/**
*
* @param {number} x x坐标
* @param {number} y y坐标
* @return {object}
*/
getClientByPoint(x: number, y: number): any;
/**
*
* @param {number} canvasX x坐标
* @param {number} canvasY y坐标
* @return {object}
*/
getPointByCanvas(canvasX: number, canvasY: number): any;
/**
*
* @param {number} x x坐标
* @param {number} y y坐标
* @return {object}
*/
getCanvasByPoint(x: number, y: number): any;
/**
*
* @param {string|object} item
*/
showItem(item: string | object): void;
/**
*
* @param {string|object} item
*/
hideItem(item: string | object): void;
/**
* id的元素
* @param {string} id id
* @return {object}
*/
findById(id: string): any;
/**
*
* @param {string} type (node|edge)
* @param {string} fn
* @return {object}
*/
find(type: ElementType, fn: Function): any;
/**
*
* @param {string} type (node|edge)
* @param {string} fn
* @return {array}
*/
findAll(type: ElementType, fn: Function): any;
/**
*
* @param {string} type (node|edge)
* @param {string} state z状态
* @return {object}
*/
findAllByState(type: ElementType, state: string): any;
/**
* /
* @param {boolean} auto
*/
setAutoPaint(auto: boolean): void;
/**
* dataUrl
* @return {string/Object} dataURL
*/
toDataURL(): string | object;
/**
*
* @param {String} name
*/
downloadImage(name: string): void;
/**
*
* @param {object} plugin
*/
addPlugin(plugin: any): void;
/**
*
* @param {object} plugin
*/
removePlugin(plugin: any): void;
/**
*
* @param {object} cfg
* cfg type String
* cfg type
*/
updateLayout(cfg: any): void;
/**
*
*/
layout(): void;
/**
*
* @return {object} this
*/
clear(): this;
/**
*
*/
destroy(): void;
// group 相关方法
/**
*
* @param {string} groupId ID
*/
collapseGroup(groupId: string): void;
/**
*
* @param {string} groupId ID
*/
expandGroup(groupId: string): void;
2019-10-30 16:25:11 +08:00
clearItemStates(node: Node): void;
2019-10-21 11:44:16 +08:00
2019-10-30 16:25:11 +08:00
downloadImage(): void;
2019-10-21 11:44:16 +08:00
}
2019-10-30 16:25:11 +08:00
interface TreeGraphOptions extends GraphOptions {}
2019-10-21 11:44:16 +08:00
/**
* TreeGraph Class
*/
export class TreeGraph extends Graph {
constructor(config: TreeGraphOptions);
getDefaultCfg(): Partial<TreeGraphOptions>;
/**
* id
* @param {object} data
* @param {string} parent id
*/
addChild(data: any, parent: string): void;
/**
*
* @param {object} data
* @param {string} parent id
*/
updateChild(data: any, parent: string): void;
/**
*
* @param {string} id id
*/
removeChild(id: string): void;
/**
* id获取对应的源数据
* @param {string|object} id id
* @param {object} parent
* @return {object}
*/
findDataById(id: string | object, parent?: object): any;
/**
*
* @param {object} layout
*/
changeLayout(layout: object): void;
/**
* data
* @param {boolean} fitView
*/
refreshLayout(fitView: boolean): void;
/**
*
* @param {object} data
* @param {function} onFrame
*/
layoutAnimate(data: any, onFrame: Function): void;
/**
*
*/
stopLayoutAnimate(): void;
/**
*
* @return {boolean}
*/
isLayoutAnimating(): boolean;
}
/**
* Util
*/
interface Util {
deepMix: typeof deepMix;
mix: typeof mix;
debounce: typeof debounce;
each: typeof each;
throttle: typeof throttle;
mat3: typeof mat3;
vec2: typeof vec2;
vec3: typeof vec3;
transform: typeof transform;
clone: typeof clone;
upperFirst: typeof upperFirst;
isNil: typeof isNil;
isArray: typeof isArray;
createDom: typeof createDom;
modifyCSS: typeof modifyCSS;
isObject: typeof isObject;
isPlainObject: typeof isPlainObject;
isNumber: typeof isNumber;
isString: typeof isString;
uniqueId: typeof uniqueId;
addEventListener: typeof addEventListener;
wrapBehavior: typeof wrapBehavior;
extend: typeof extend;
augment: typeof augment;
remove: typeof remove;
/**
* turn padding into [top, right, bottom, right]
* @param padding
*/
formatPadding(padding: number | string | number[]): [number, number, number, number];
/**
*
* @param e
*/
cloneEvent(e: any): any;
getBBox(element: any, parent: any): G.Box;
2019-10-21 11:44:16 +08:00
/**
*
* @param cfg
*/
getLoopCfgs(cfg: any): any;
traverseTree(data: any, fn: Function): void;
2019-10-30 16:25:11 +08:00
radialLayout(data: any, layout?: any): any;
2019-10-21 11:44:16 +08:00
/**
* label 线 label
* @param {object} pathShape G path Edge keyShape
* @param {number} percent 0 - 1 线
* @param {number} refX x label
* @param {number} refY y label
* @param {boolean} rotate 线
* @return {object} x, y,
*/
getLabelPosition(
pathShape: any,
percent: number,
refX: number,
refY: number,
rotate: boolean,
): {
x: number;
y: number;
angle: number;
rotate?: number;
};
getSpline(points: any): any;
/**
*
* @param {Object} startPoint x,y
* @param {Object} endPoint , x,y
* @param {Number} percent , 0-1
* @param {Number} offset
* @return {Object} x,y
*/
getControlPoint(startPoint: Point, endPoint: Point, percent: number, offset: number): Point;
/**
*
* @param {number} value
* @param {number} min
* @param {number} max
* @return {boolean} bool
*/
isBetween(value: number, min: number, max: number): boolean;
/**
* 线
* @param {object} p0 线
* @param {object} p1 线
* @param {object} p2 线
* @param {object} p3 线
* @return {object}
*/
getLineIntersect(p0: Point, p1: Point, p2: Point, p3: Point): Point;
/**
* point and rectangular intersection point
* @param {object} rect rect
* @param {object} point point
* @return {object} rst;
*/
getRectIntersectByPoint(rect: Rect, point: Point): Point;
/**
* get point and circle inIntersect
* @param {Object} circle x,y,r
* @param {Object} point x,y
* @return {object} applied point
*/
getCircleIntersectByPoint(circle: Circle, point: Point): Point;
/**
* get point and ellipse inIntersect
* @param {Object} ellipse x,y,rx,ry
* @param {Object} point x,y
* @return {object} applied point
*/
getEllispeIntersectByPoint(ellipse: Ellipse, point: Point): Point;
/**
* coordinate matrix transformation
* @param {number} point coordinate
* @param {number} matrix matrix
* @param {number} tag could be 0 or 1
* @return {object} transformed point
*/
applyMatrix(point: Point, matrix: number, tag?: number): Point;
/**
* coordinate matrix invert transformation
* @param {number} point coordinate
* @param {number} matrix matrix
* @param {number} tag could be 0 or 1
* @return {object} transformed point
*/
invertMatrix(point: Point, matrix: number, tag?: number): Point;
/**
*
* @param {array} data
* @param {string} value
* @param {string} parentId
* @return {array}
*/
flatToTree(data: any[], value?: string, parentId?: string): any[];
/**
* group中的节点
* @param {object} data G6的数据模型
* @return {object} group中的节点
*/
getAllNodeInGroups(data: any): any;
}
export const Util: Util;
2019-10-30 16:25:11 +08:00
export const Layout: any;
2019-10-21 11:44:16 +08:00
export const G: any;
/**
* Global
*/
interface Global {
/**
*
*/
readonly version: string;
/**
*
*/
rootContainerClassName: string;
/**
*
*/
nodeContainerClassName: string;
/**
* 线
*/
edgeContainerClassName: string;
/**
*
*/
customGroupContainerClassName: string;
/**
*
*/
delegateContainerClassName: string;
defaultNode: any;
defaultEdge: any;
nodeLabel: any;
edgeLabel: any;
/**
* active selected
*/
nodeStateStyle: any;
edgeStateStyle: any;
loopPosition: any;
delegateStyle: any;
}
export const Global: Global;
/**
* Sharp
*/
interface Sharp {
// 注册 Geometry 获取图形的入口
registerFactory(factoryType: string, cfg: any): any;
// 获得 ShapeFactory
getFactory(factoryType: string): any;
2019-10-30 16:25:11 +08:00
get(key: string): any;
2019-10-21 11:44:16 +08:00
}
export const Sharp: Sharp;
export function registerNode(shapeType: string, cfg: any, extendShapeType?: string): any;
export function registerEdge(shapeType: string, cfg: any, extendShapeType?: string): any;
2019-10-30 16:25:11 +08:00
export function registerLayout(layoutType: string, cfg: any, extendLayoutType?: string): void;
2019-10-21 11:44:16 +08:00
export function registerBehavior(type: string, behavior: any): void;
/**
*
*/
export const version: string;
}