mirror of
https://gitee.com/antv/g6.git
synced 2024-12-02 11:48:29 +08:00
fix: update types file struct
This commit is contained in:
parent
f286e0e3d9
commit
1bd3fef378
3
.gitignore
vendored
3
.gitignore
vendored
@ -74,3 +74,6 @@ lib
|
||||
# cache
|
||||
*.cache
|
||||
public
|
||||
|
||||
esm
|
||||
|
||||
|
20
esm/behavior/index.d.ts
vendored
20
esm/behavior/index.d.ts
vendored
@ -1,20 +0,0 @@
|
||||
import { IModel, IModelCfg, IModelStyle } from '../interface';
|
||||
import { IGraph } from '../interface/graph';
|
||||
interface IBehavior {
|
||||
getDefaultCfg?: () => IModelCfg;
|
||||
getEvents: () => {
|
||||
[key: string]: string;
|
||||
};
|
||||
shouldBegin: (cfg?: IModel) => boolean;
|
||||
}
|
||||
export default class Behavior {
|
||||
private _events;
|
||||
registerBehavior(type: string, behavior: IBehavior): void;
|
||||
bind(graph: IGraph): void;
|
||||
/**
|
||||
*
|
||||
* @param cfg 默认的配置项
|
||||
*/
|
||||
getDefaultCfg(cfg: IModelCfg): IModelStyle;
|
||||
}
|
||||
export {};
|
@ -1,36 +0,0 @@
|
||||
import each from '@antv/util/lib/each';
|
||||
import wrapBehavior from '@antv/util/lib/wrap-behavior';
|
||||
var Behavior = /** @class */ (function () {
|
||||
function Behavior() {
|
||||
}
|
||||
Behavior.prototype.registerBehavior = function (type, behavior) {
|
||||
if (!behavior) {
|
||||
throw new Error("please specify handler for this behavior: " + type);
|
||||
}
|
||||
var getEvents = behavior.getEvents;
|
||||
var events = getEvents();
|
||||
var eventsToBind = {};
|
||||
if (events) {
|
||||
each(events, function (handle, event) {
|
||||
eventsToBind[event] = wrapBehavior(events, handle);
|
||||
});
|
||||
this._events = eventsToBind;
|
||||
}
|
||||
};
|
||||
Behavior.prototype.bind = function (graph) {
|
||||
var events = this._events;
|
||||
each(events, function (handler, event) {
|
||||
graph.on(event, handler);
|
||||
});
|
||||
};
|
||||
/**
|
||||
*
|
||||
* @param cfg 默认的配置项
|
||||
*/
|
||||
Behavior.prototype.getDefaultCfg = function (cfg) {
|
||||
return {};
|
||||
};
|
||||
return Behavior;
|
||||
}());
|
||||
export default Behavior;
|
||||
//# sourceMappingURL=index.js.map
|
@ -1 +0,0 @@
|
||||
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/behavior/index.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,qBAAqB,CAAA;AACtC,OAAO,YAAY,MAAM,8BAA8B,CAAA;AAUvD;IAAA;IAmCA,CAAC;IAjCQ,mCAAgB,GAAvB,UAAwB,IAAY,EAAE,QAAmB;QACvD,IAAG,CAAC,QAAQ,EAAE;YACZ,MAAM,IAAI,KAAK,CAAC,+CAA6C,IAAM,CAAC,CAAA;SACrE;QAEO,IAAA,8BAAS,CAAa;QAE9B,IAAM,MAAM,GAAG,SAAS,EAAE,CAAA;QAC1B,IAAM,YAAY,GAAG,EAAE,CAAA;QACvB,IAAG,MAAM,EAAE;YACT,IAAI,CAAC,MAAM,EAAE,UAAC,MAAM,EAAE,KAAK;gBACzB,YAAY,CAAC,KAAK,CAAC,GAAG,YAAY,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;YACpD,CAAC,CAAC,CAAA;YACF,IAAI,CAAC,OAAO,GAAG,YAAY,CAAA;SAC5B;IACH,CAAC;IAEM,uBAAI,GAAX,UAAY,KAAa;QACvB,IAAM,MAAM,GAAG,IAAI,CAAC,OAAO,CAAA;QAC3B,IAAI,CAAC,MAAM,EAAE,UAAC,OAAO,EAAE,KAAK;YAC1B,KAAK,CAAC,EAAE,CAAC,KAAK,EAAE,OAAO,CAAC,CAAA;QAC1B,CAAC,CAAC,CAAA;IACJ,CAAC;IAED;;;OAGG;IACI,gCAAa,GAApB,UAAqB,GAAc;QACjC,OAAO,EAAE,CAAA;IACX,CAAC;IAGH,eAAC;AAAD,CAAC,AAnCD,IAmCC"}
|
9
esm/global.d.ts
vendored
9
esm/global.d.ts
vendored
@ -1,9 +0,0 @@
|
||||
declare const _default: {
|
||||
version: string;
|
||||
rootContainerClassName: string;
|
||||
nodeContainerClassName: string;
|
||||
edgeContainerClassName: string;
|
||||
customGroupContainerClassName: string;
|
||||
delegateContainerClassName: string;
|
||||
};
|
||||
export default _default;
|
@ -1,9 +0,0 @@
|
||||
export default {
|
||||
version: '3.3.0',
|
||||
rootContainerClassName: 'root-container',
|
||||
nodeContainerClassName: 'node-container',
|
||||
edgeContainerClassName: 'edge-container',
|
||||
customGroupContainerClassName: 'custom-group-container',
|
||||
delegateContainerClassName: 'delegate-container'
|
||||
};
|
||||
//# sourceMappingURL=global.js.map
|
@ -1 +0,0 @@
|
||||
{"version":3,"file":"global.js","sourceRoot":"","sources":["../src/global.ts"],"names":[],"mappings":"AAAA,eAAe;IACb,OAAO,EAAE,OAAO;IAChB,sBAAsB,EAAE,gBAAgB;IACxC,sBAAsB,EAAE,gBAAgB;IACxC,sBAAsB,EAAE,gBAAgB;IACxC,6BAA6B,EAAE,wBAAwB;IACvD,0BAA0B,EAAE,oBAAoB;CACjD,CAAA"}
|
5
esm/index.d.ts
vendored
5
esm/index.d.ts
vendored
@ -1,5 +0,0 @@
|
||||
export default class G6 {
|
||||
private version;
|
||||
private constructor();
|
||||
getVersion(): void;
|
||||
}
|
10
esm/index.js
10
esm/index.js
@ -1,10 +0,0 @@
|
||||
var G6 = /** @class */ (function () {
|
||||
function G6() {
|
||||
}
|
||||
G6.prototype.getVersion = function () {
|
||||
console.log(this.version);
|
||||
};
|
||||
return G6;
|
||||
}());
|
||||
export default G6;
|
||||
//# sourceMappingURL=index.js.map
|
@ -1 +0,0 @@
|
||||
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;IAGE;IAEA,CAAC;IAEM,uBAAU,GAAjB;QACE,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,OAAO,CAAC,CAAA;IAC3B,CAAC;IACH,SAAC;AAAD,CAAC,AAVD,IAUC"}
|
25
esm/interface/event.d.ts
vendored
25
esm/interface/event.d.ts
vendored
@ -1,25 +0,0 @@
|
||||
export declare enum G6Event {
|
||||
CLICK = "click",
|
||||
MOUSEDOWN = "mousedown",
|
||||
MOUDEUP = "mouseup",
|
||||
DBLCLICK = "dblclick",
|
||||
CONTEXTMENU = "contextmenu",
|
||||
MOUSEENTER = "mouseenter",
|
||||
MOUSEOUT = "mouseout",
|
||||
MOUSEOVER = "mouseover",
|
||||
MOUSEMOVE = "mousemove",
|
||||
MOUSELEAVE = "mouseleave",
|
||||
DRAGSTART = "dragstart",
|
||||
DRAGEND = "dragend",
|
||||
DRAG = "drag",
|
||||
DRAGENTER = "dragenter",
|
||||
DRAGLEAVE = "dragleave",
|
||||
DDROP = "drop",
|
||||
NODE_CLICK = "node:click",
|
||||
EDGE_CLICK = "edge:click",
|
||||
NODE_CONTEXTMENU = "node:contextmenu",
|
||||
EDGE_CONTEXTMENU = "edge:contextmenu",
|
||||
NODE_DBLCLICK = "node:dblclick",
|
||||
EDGE_DBLCLICK = "edge:dblclick"
|
||||
}
|
||||
export declare type IEvent = Record<G6Event, string>;
|
@ -1,26 +0,0 @@
|
||||
export var G6Event;
|
||||
(function (G6Event) {
|
||||
G6Event["CLICK"] = "click";
|
||||
G6Event["MOUSEDOWN"] = "mousedown";
|
||||
G6Event["MOUDEUP"] = "mouseup";
|
||||
G6Event["DBLCLICK"] = "dblclick";
|
||||
G6Event["CONTEXTMENU"] = "contextmenu";
|
||||
G6Event["MOUSEENTER"] = "mouseenter";
|
||||
G6Event["MOUSEOUT"] = "mouseout";
|
||||
G6Event["MOUSEOVER"] = "mouseover";
|
||||
G6Event["MOUSEMOVE"] = "mousemove";
|
||||
G6Event["MOUSELEAVE"] = "mouseleave";
|
||||
G6Event["DRAGSTART"] = "dragstart";
|
||||
G6Event["DRAGEND"] = "dragend";
|
||||
G6Event["DRAG"] = "drag";
|
||||
G6Event["DRAGENTER"] = "dragenter";
|
||||
G6Event["DRAGLEAVE"] = "dragleave";
|
||||
G6Event["DDROP"] = "drop";
|
||||
G6Event["NODE_CLICK"] = "node:click";
|
||||
G6Event["EDGE_CLICK"] = "edge:click";
|
||||
G6Event["NODE_CONTEXTMENU"] = "node:contextmenu";
|
||||
G6Event["EDGE_CONTEXTMENU"] = "edge:contextmenu";
|
||||
G6Event["NODE_DBLCLICK"] = "node:dblclick";
|
||||
G6Event["EDGE_DBLCLICK"] = "edge:dblclick";
|
||||
})(G6Event || (G6Event = {}));
|
||||
//# sourceMappingURL=event.js.map
|
@ -1 +0,0 @@
|
||||
{"version":3,"file":"event.js","sourceRoot":"","sources":["../../src/interface/event.ts"],"names":[],"mappings":"AAAA,MAAM,CAAN,IAAY,OAuBX;AAvBD,WAAY,OAAO;IACjB,0BAAe,CAAA;IACf,kCAAuB,CAAA;IACvB,8BAAmB,CAAA;IACnB,gCAAqB,CAAA;IACrB,sCAA2B,CAAA;IAC3B,oCAAyB,CAAA;IACzB,gCAAqB,CAAA;IACrB,kCAAuB,CAAA;IACvB,kCAAuB,CAAA;IACvB,oCAAyB,CAAA;IACzB,kCAAuB,CAAA;IACvB,8BAAmB,CAAA;IACnB,wBAAa,CAAA;IACb,kCAAuB,CAAA;IACvB,kCAAuB,CAAA;IACvB,yBAAc,CAAA;IACd,oCAAyB,CAAA;IACzB,oCAAyB,CAAA;IACzB,gDAAqC,CAAA;IACrC,gDAAqC,CAAA;IACrC,0CAA+B,CAAA;IAC/B,0CAA+B,CAAA;AACjC,CAAC,EAvBW,OAAO,KAAP,OAAO,QAuBlB"}
|
3
esm/interface/graph.d.ts
vendored
3
esm/interface/graph.d.ts
vendored
@ -1,3 +0,0 @@
|
||||
export interface IGraph {
|
||||
on: (event: any, handler: any) => void;
|
||||
}
|
@ -1 +0,0 @@
|
||||
//# sourceMappingURL=graph.js.map
|
@ -1 +0,0 @@
|
||||
{"version":3,"file":"graph.js","sourceRoot":"","sources":["../../src/interface/graph.ts"],"names":[],"mappings":""}
|
17
esm/interface/index.d.ts
vendored
17
esm/interface/index.d.ts
vendored
@ -1,17 +0,0 @@
|
||||
export interface IModel {
|
||||
id?: string;
|
||||
label?: string;
|
||||
source?: string;
|
||||
target?: string;
|
||||
}
|
||||
export declare type IModelStyle = Partial<{
|
||||
fill: string;
|
||||
stroke: string;
|
||||
strokeWidth: number;
|
||||
}>;
|
||||
export interface IModelCfg {
|
||||
style: IModelStyle;
|
||||
stateStyles: {
|
||||
[key: string]: IModelStyle;
|
||||
};
|
||||
}
|
@ -1 +0,0 @@
|
||||
//# sourceMappingURL=index.js.map
|
@ -1 +0,0 @@
|
||||
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/interface/index.ts"],"names":[],"mappings":""}
|
@ -4,7 +4,7 @@
|
||||
"description": "A Graph Visualization Framework in JavaScript",
|
||||
"main": "lib/index.js",
|
||||
"module": "esm/index.js",
|
||||
"types": "lib/index.d.ts",
|
||||
"types": "types/index.d.ts",
|
||||
"browser": "dist/g6.min.js",
|
||||
"files": [
|
||||
"package.json",
|
||||
|
@ -1,17 +1,22 @@
|
||||
import { IBehavior } from '../interface/behavior'
|
||||
import clone from '@antv/util/lib/clone'
|
||||
import { IBehaviorOpation } from '../../types';
|
||||
import BehaviorOption from './behaviorOption'
|
||||
|
||||
export default class Behavior {
|
||||
private static types = {}
|
||||
public static registerBehavior<T, U>(type: string, behavior: IBehavior<U>) {
|
||||
public static registerBehavior<T, U>(type: string, behavior: IBehaviorOpation<U>) {
|
||||
if(!behavior) {
|
||||
throw new Error(`please specify handler for this behavior: ${type}`)
|
||||
}
|
||||
// TODO 将传进来的Behavior和默认的合并
|
||||
|
||||
const instance = new BehaviorOption()
|
||||
Object.assign(instance, behavior)
|
||||
this.types[type] = instance
|
||||
const _proptype = clone(BehaviorOption.prototype)
|
||||
|
||||
Object.assign(_proptype, behavior)
|
||||
|
||||
const base = function() {}
|
||||
base.prototype = _proptype
|
||||
|
||||
this.types[type] = base
|
||||
}
|
||||
|
||||
public static hasBehavior(type: string) {
|
||||
|
@ -1,6 +1,6 @@
|
||||
import each from '@antv/util/lib/each'
|
||||
import wrapBehavior from '@antv/util/lib/wrap-behavior'
|
||||
import { G6Event } from '../interface/behavior'
|
||||
import { G6Event } from '../../types';
|
||||
import { IGraph } from '../interface/graph'
|
||||
|
||||
export default class BehaviorOption {
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { G6Event, IG6GraphEvent } from "../interface/behavior";
|
||||
import { G6Event, IG6GraphEvent } from "../../types";
|
||||
import { cloneEvent } from '../util/base'
|
||||
const abs = Math.abs
|
||||
const DRAG_OFFSET = 10
|
||||
|
@ -1,66 +1,9 @@
|
||||
|
||||
import GraphEvent from '@antv/g-base/lib/event/graph-event';
|
||||
import { IGraph } from './graph';
|
||||
import { IG6GraphEvent } from "../../types";
|
||||
import { IItem } from './item';
|
||||
import { IModelConfig } from "./model";
|
||||
|
||||
export enum G6Event {
|
||||
CLICK = 'click',
|
||||
MOUSEDOWN = 'mousedown',
|
||||
MOUDEUP = 'mouseup',
|
||||
DBLCLICK = 'dblclick',
|
||||
CONTEXTMENU = 'contextmenu',
|
||||
MOUSEENTER = 'mouseenter',
|
||||
MOUSEOUT = 'mouseout',
|
||||
MOUSEOVER = 'mouseover',
|
||||
MOUSEMOVE = 'mousemove',
|
||||
MOUSELEAVE = 'mouseleave',
|
||||
DRAGSTART = 'dragstart',
|
||||
DRAGEND = 'dragend',
|
||||
DRAG = 'drag',
|
||||
DRAGENTER = 'dragenter',
|
||||
DRAGLEAVE = 'dragleave',
|
||||
DDROP = 'drop',
|
||||
NODE_CLICK = 'node:click',
|
||||
EDGE_CLICK = 'edge:click',
|
||||
NODE_CONTEXTMENU = 'node:contextmenu',
|
||||
EDGE_CONTEXTMENU = 'edge:contextmenu',
|
||||
NODE_DBLCLICK = 'node:dblclick',
|
||||
EDGE_DBLCLICK = 'edge:dblclick',
|
||||
CANVAS_MOUSEDOWN = 'canvas:mousedown',
|
||||
CANVAS_MOUSEMOVE = 'canvas:mousemove',
|
||||
CANVAS_MOUSEUP = 'canvas:mouseup',
|
||||
CANVAS_CLICK = 'canvas:click',
|
||||
CANVAS_MOSUELEAVE = 'canvas:mouseleave',
|
||||
KEYUP = 'keyup',
|
||||
KEYDOWN = 'keydown'
|
||||
}
|
||||
|
||||
type GetEvents = 'getEvents';
|
||||
type ShouldBegin = 'shouldBegin';
|
||||
type ShouldUpdate = 'shouldUpdate';
|
||||
type ShouldEnd = 'shouldEnd'
|
||||
type Bind = 'bind'
|
||||
type Unbind = 'unbind'
|
||||
|
||||
type DefaultBehaviorType = IG6GraphEvent | string | number | object
|
||||
|
||||
export type IBehavior<U> = {
|
||||
[T in keyof U]:
|
||||
T extends GetEvents ? () => { [key in G6Event]?: string } :
|
||||
T extends ShouldBegin ? (cfg?: IModelConfig) => boolean :
|
||||
T extends ShouldEnd ? (cfg?: IModelConfig) => boolean :
|
||||
T extends ShouldUpdate ? (cfg?: IModelConfig) => boolean :
|
||||
T extends Bind ? (graph: IGraph) => void :
|
||||
T extends Unbind ? (graph: IGraph) => void :
|
||||
(...args: DefaultBehaviorType[]) => unknown;
|
||||
}
|
||||
|
||||
export type IEvent = Record<G6Event, string>
|
||||
|
||||
export interface IG6GraphEvent extends GraphEvent {
|
||||
item: IItem;
|
||||
}
|
||||
|
||||
export class G6GraphEvent extends GraphEvent implements IG6GraphEvent {
|
||||
public item: IItem
|
||||
|
@ -1,20 +1,7 @@
|
||||
import { G6Event } from './behavior'
|
||||
import { IEdgeConfig, IGroupConfig, INodeConfig } from './model'
|
||||
import { G6Event } from '../../types'
|
||||
|
||||
export interface IGraph {
|
||||
on: (event: G6Event, handler: () => void) => void;
|
||||
off: (event: G6Event, handler: () => void) => void;
|
||||
}
|
||||
|
||||
export interface IGraphData {
|
||||
nodes?: INodeConfig[];
|
||||
edges?: IEdgeConfig[];
|
||||
groups?: IGroupConfig[];
|
||||
}
|
||||
|
||||
export interface ITreeGraphData {
|
||||
id: string;
|
||||
label?: string;
|
||||
x?: number;
|
||||
y?: number;
|
||||
children?: ITreeGraphData[];
|
||||
}
|
||||
|
@ -1,9 +1,7 @@
|
||||
import Group from "@antv/g-canvas/lib/group";
|
||||
import ShapeBase from "@antv/g-canvas/lib/shape/base";
|
||||
import { BBox } from "@antv/g-canvas/lib/types";
|
||||
import { IPoint } from "./math";
|
||||
import { IModelConfig, INodeConfig } from "./model";
|
||||
import { IShapeStyle } from './shape'
|
||||
import { IModelConfig, INodeConfig, IPoint, IShapeStyle } from '../../types'
|
||||
|
||||
// item 的配置项
|
||||
interface IItemConfig {
|
||||
|
@ -1,8 +0,0 @@
|
||||
export interface IPoint {
|
||||
x: number;
|
||||
y: number;
|
||||
}
|
||||
|
||||
export type IMatrix = number[];
|
||||
|
||||
export type IPadding = number | string | number[];
|
@ -1,66 +0,0 @@
|
||||
import { IEdge, INode } from './item'
|
||||
import { IPoint } from './math';
|
||||
import { IShapeStyle } from './shape'
|
||||
|
||||
type IModelStyle = Partial<{
|
||||
style: {
|
||||
[key: string]: IShapeStyle
|
||||
};
|
||||
stateStyles: {
|
||||
[key: string]: IShapeStyle;
|
||||
};
|
||||
// loop edge config
|
||||
loopCfg: {
|
||||
dist?: number;
|
||||
position?: string;
|
||||
// 如果逆时针画,交换起点和终点
|
||||
clockwise?: boolean;
|
||||
};
|
||||
}>
|
||||
interface IModelStyle1 {
|
||||
style?: {
|
||||
[key: string]: IShapeStyle
|
||||
};
|
||||
stateStyles?: {
|
||||
[key: string]: IShapeStyle;
|
||||
};
|
||||
// loop edge config
|
||||
loopCfg?: {
|
||||
dist?: number;
|
||||
position?: string;
|
||||
// 如果逆时针画,交换起点和终点
|
||||
clockwise?: boolean;
|
||||
}
|
||||
}
|
||||
|
||||
export type IModelConfig = INodeConfig | IEdgeConfig
|
||||
|
||||
export interface INodeConfig extends IModelStyle {
|
||||
id: string;
|
||||
label?: string;
|
||||
groupId?: string;
|
||||
description?: string;
|
||||
x?: number;
|
||||
y?: number;
|
||||
}
|
||||
|
||||
export interface IEdgeConfig extends IModelStyle {
|
||||
source: string;
|
||||
target: string;
|
||||
label?: string;
|
||||
sourceNode?: INode;
|
||||
targetNode?: INode;
|
||||
startPoint?: IPoint;
|
||||
endPoint?: IPoint;
|
||||
controlPoints?: IPoint[];
|
||||
}
|
||||
|
||||
export interface IGroupConfig {
|
||||
id: string;
|
||||
parentId?: string;
|
||||
[key: string]: string | IModelStyle;
|
||||
}
|
||||
|
||||
export interface IGroupNodeIds {
|
||||
[key: string]: string[];
|
||||
}
|
@ -1,31 +0,0 @@
|
||||
import { IPoint } from './math'
|
||||
|
||||
export type IShapeStyle = Partial<{
|
||||
x: number;
|
||||
y: number;
|
||||
r: number;
|
||||
stroke: string | null;
|
||||
strokeOpacity: number;
|
||||
fill: string | null;
|
||||
fillOpacity: number;
|
||||
lineWidth: number;
|
||||
path: string | object[];
|
||||
points: object[];
|
||||
matrix: number[];
|
||||
opacity: number;
|
||||
[key: string]: string | number | object | object[]
|
||||
}>
|
||||
|
||||
export interface IRect extends IPoint {
|
||||
width: number;
|
||||
height: number;
|
||||
}
|
||||
|
||||
export interface ICircle extends IPoint {
|
||||
r: number;
|
||||
}
|
||||
|
||||
export interface IEllipse extends IPoint {
|
||||
rx: number;
|
||||
ry: number;
|
||||
}
|
@ -3,8 +3,8 @@ import isArray from '@antv/util/lib/is-array'
|
||||
import isNil from '@antv/util/lib/is-nil'
|
||||
import isNumber from "@antv/util/lib/is-number";
|
||||
import isString from '@antv/util/lib/is-string'
|
||||
import { G6GraphEvent, IG6GraphEvent } from '../interface/behavior';
|
||||
import { IPadding } from "../interface/math";
|
||||
import { IG6GraphEvent, IPadding } from "../../types";
|
||||
import { G6GraphEvent } from '../interface/behavior';
|
||||
|
||||
/**
|
||||
* turn padding into [top, right, bottom, right]
|
||||
|
@ -1,14 +1,11 @@
|
||||
import Group from "@antv/g-canvas/lib/group";
|
||||
import { Path } from "@antv/g-canvas/lib/shape";
|
||||
import ShapeBase from "@antv/g-canvas/lib/shape/base";
|
||||
import { BBox } from "@antv/g-canvas/lib/types";
|
||||
import { vec2 } from "@antv/matrix-util";
|
||||
import each from '@antv/util/lib/each'
|
||||
import { IEdgeConfig, IPoint, ITreeGraphData } from "../../types";
|
||||
import Global from '../global'
|
||||
import { ITreeGraphData } from "../interface/graph";
|
||||
import { INode } from "../interface/item";
|
||||
import { IPoint } from "../interface/math";
|
||||
import { IEdgeConfig } from "../interface/model";
|
||||
import { applyMatrix } from "./math";
|
||||
|
||||
const PI: number = Math.PI
|
||||
|
@ -1,6 +1,5 @@
|
||||
import groupBy, { ObjectType } from '@antv/util/lib/group-by'
|
||||
import { IGraphData } from '../../src/interface/graph'
|
||||
import { IGroupConfig, IGroupNodeIds } from '../interface/model';
|
||||
import { IGraphData, IGroupConfig, IGroupNodeIds } from '../../types';
|
||||
|
||||
export const getAllNodeInGroups = (data: IGraphData): IGroupNodeIds => {
|
||||
const groupById: ObjectType<IGroupConfig> = groupBy(data.groups, 'id');
|
||||
|
@ -1,7 +1,5 @@
|
||||
import { mat3, vec3 } from '@antv/matrix-util'
|
||||
import { IGraphData } from '../interface/graph'
|
||||
import { IMatrix, IPoint } from '../interface/math'
|
||||
import { ICircle, IEllipse, IRect } from '../interface/shape'
|
||||
import { ICircle, IEllipse, IGraphData, IMatrix, IPoint, IRect } from '../../types'
|
||||
|
||||
/**
|
||||
* 是否在区间内
|
||||
|
@ -1,6 +1,6 @@
|
||||
import { vec2 } from '@antv/matrix-util'
|
||||
import { catmullRom2Bezier } from '@antv/path-util'
|
||||
import { IPoint } from '../interface/math'
|
||||
import { IPoint } from '../../types'
|
||||
|
||||
/**
|
||||
* 替换字符串中的字段
|
||||
|
@ -1,4 +1,6 @@
|
||||
import '../../../src/behavior'
|
||||
import Behavior from '../../../src/behavior/behavior'
|
||||
import { IBehavior } from '../../../types';
|
||||
|
||||
describe('Behavior', () => {
|
||||
it('register signle behavior', () => {
|
||||
@ -19,13 +21,14 @@ describe('Behavior', () => {
|
||||
expect(Behavior.hasBehavior('first-behavior')).toBe(true)
|
||||
expect(Behavior.hasBehavior('test')).toBe(false)
|
||||
const BehaviorInstance = Behavior.getBehavior('first-behavior')
|
||||
|
||||
const instance = new BehaviorInstance()
|
||||
const events = instance.getEvents()
|
||||
expect(Object.keys(events)).toEqual(['click'])
|
||||
expect(instance.shouldBegin()).toEqual(false);
|
||||
})
|
||||
|
||||
it.only('register multiple behavior', () => {
|
||||
it('register multiple behavior', () => {
|
||||
Behavior.registerBehavior('first', {
|
||||
getEvents() {
|
||||
return {
|
||||
@ -60,8 +63,10 @@ describe('Behavior', () => {
|
||||
}
|
||||
})
|
||||
|
||||
const firstInstance = Behavior.getBehavior('first')
|
||||
const secondBehavior = Behavior.getBehavior('second')
|
||||
const FirstInstance = Behavior.getBehavior('first')
|
||||
const SecondBehavior = Behavior.getBehavior('second')
|
||||
const firstInstance = new FirstInstance()
|
||||
const secondBehavior = new SecondBehavior()
|
||||
expect(firstInstance).not.toBe(undefined);
|
||||
expect(secondBehavior).not.toBe(undefined);
|
||||
expect(Behavior.getBehavior('three')).toBe(undefined);
|
||||
@ -69,20 +74,31 @@ describe('Behavior', () => {
|
||||
expect(Behavior.hasBehavior('three')).toBe(false);
|
||||
|
||||
const config1 = firstInstance.getDefaultCfg();
|
||||
console.log('config1.style', config1)
|
||||
expect(config1.style).toBe(undefined);
|
||||
|
||||
const events1 = firstInstance.getEvents()
|
||||
console.log(events1, Object.keys(events1), events1)
|
||||
expect(Object.keys(events1).length).toEqual(3);
|
||||
expect(Object.keys(events1)).toEqual(['click', 'edge:click', 'contextmenu'])
|
||||
|
||||
const config = secondBehavior.getDefaultCfg();
|
||||
expect(config.style.fill).toEqual('red');
|
||||
expect(config.style.fill).not.toEqual('blue');
|
||||
console.log('config.style', config.style)
|
||||
|
||||
const drag = secondBehavior.onDrag()
|
||||
expect(drag).toEqual('drag')
|
||||
})
|
||||
})
|
||||
|
||||
describe('Default Behavior', () => {
|
||||
it('drag-canvas', () => {
|
||||
const DragCanvas = Behavior.getBehavior('drag-canvas')
|
||||
expect(DragCanvas).not.toBe(undefined)
|
||||
|
||||
const dragCanvas: IBehavior = new DragCanvas()
|
||||
const config = dragCanvas.getDefaultCfg()
|
||||
expect(config).toEqual({ direction: 'both' })
|
||||
|
||||
const events = dragCanvas.getEvents()
|
||||
const keys = Object.keys(events)
|
||||
expect(keys.length).toBe(7)
|
||||
})
|
||||
})
|
0
global.d.ts → types/global.d.ts
vendored
0
global.d.ts → types/global.d.ts
vendored
189
types/index.ts
Normal file
189
types/index.ts
Normal file
@ -0,0 +1,189 @@
|
||||
import GraphEvent from '@antv/g-base/lib/event/graph-event';
|
||||
import { IGraph } from '../src/interface/graph';
|
||||
import { IItem, INode } from '../src/interface/item'
|
||||
|
||||
export interface IPoint {
|
||||
x: number;
|
||||
y: number;
|
||||
}
|
||||
|
||||
export type IMatrix = number[];
|
||||
|
||||
export type IPadding = number | string | number[];
|
||||
|
||||
export type IShapeStyle = Partial<{
|
||||
x: number;
|
||||
y: number;
|
||||
r: number;
|
||||
stroke: string | null;
|
||||
strokeOpacity: number;
|
||||
fill: string | null;
|
||||
fillOpacity: number;
|
||||
lineWidth: number;
|
||||
path: string | object[];
|
||||
points: object[];
|
||||
matrix: number[];
|
||||
opacity: number;
|
||||
[key: string]: string | number | object | object[]
|
||||
}>
|
||||
|
||||
export interface IRect extends IPoint {
|
||||
width: number;
|
||||
height: number;
|
||||
}
|
||||
|
||||
export interface ICircle extends IPoint {
|
||||
r: number;
|
||||
}
|
||||
|
||||
export interface IEllipse extends IPoint {
|
||||
rx: number;
|
||||
ry: number;
|
||||
}
|
||||
|
||||
type IModelStyle = Partial<{
|
||||
style: {
|
||||
[key: string]: IShapeStyle
|
||||
};
|
||||
stateStyles: {
|
||||
[key: string]: IShapeStyle;
|
||||
};
|
||||
// loop edge config
|
||||
loopCfg: {
|
||||
dist?: number;
|
||||
position?: string;
|
||||
// 如果逆时针画,交换起点和终点
|
||||
clockwise?: boolean;
|
||||
};
|
||||
}>
|
||||
interface IModelStyle1 {
|
||||
style?: {
|
||||
[key: string]: IShapeStyle
|
||||
};
|
||||
stateStyles?: {
|
||||
[key: string]: IShapeStyle;
|
||||
};
|
||||
// loop edge config
|
||||
loopCfg?: {
|
||||
dist?: number;
|
||||
position?: string;
|
||||
// 如果逆时针画,交换起点和终点
|
||||
clockwise?: boolean;
|
||||
}
|
||||
}
|
||||
|
||||
export type IModelConfig = INodeConfig | IEdgeConfig
|
||||
|
||||
export interface INodeConfig extends IModelStyle {
|
||||
id: string;
|
||||
label?: string;
|
||||
groupId?: string;
|
||||
description?: string;
|
||||
x?: number;
|
||||
y?: number;
|
||||
}
|
||||
|
||||
export interface IEdgeConfig extends IModelStyle {
|
||||
source: string;
|
||||
target: string;
|
||||
label?: string;
|
||||
sourceNode?: INode;
|
||||
targetNode?: INode;
|
||||
startPoint?: IPoint;
|
||||
endPoint?: IPoint;
|
||||
controlPoints?: IPoint[];
|
||||
}
|
||||
|
||||
export interface IGroupConfig {
|
||||
id: string;
|
||||
parentId?: string;
|
||||
[key: string]: string | IModelStyle;
|
||||
}
|
||||
|
||||
export interface IGroupNodeIds {
|
||||
[key: string]: string[];
|
||||
}
|
||||
|
||||
export interface IGraphData {
|
||||
nodes?: INodeConfig[];
|
||||
edges?: IEdgeConfig[];
|
||||
groups?: IGroupConfig[];
|
||||
}
|
||||
|
||||
export interface ITreeGraphData {
|
||||
id: string;
|
||||
label?: string;
|
||||
x?: number;
|
||||
y?: number;
|
||||
children?: ITreeGraphData[];
|
||||
}
|
||||
|
||||
// Behavior type file
|
||||
export enum G6Event {
|
||||
CLICK = 'click',
|
||||
MOUSEDOWN = 'mousedown',
|
||||
MOUDEUP = 'mouseup',
|
||||
DBLCLICK = 'dblclick',
|
||||
CONTEXTMENU = 'contextmenu',
|
||||
MOUSEENTER = 'mouseenter',
|
||||
MOUSEOUT = 'mouseout',
|
||||
MOUSEOVER = 'mouseover',
|
||||
MOUSEMOVE = 'mousemove',
|
||||
MOUSELEAVE = 'mouseleave',
|
||||
DRAGSTART = 'dragstart',
|
||||
DRAGEND = 'dragend',
|
||||
DRAG = 'drag',
|
||||
DRAGENTER = 'dragenter',
|
||||
DRAGLEAVE = 'dragleave',
|
||||
DDROP = 'drop',
|
||||
NODE_CLICK = 'node:click',
|
||||
EDGE_CLICK = 'edge:click',
|
||||
NODE_CONTEXTMENU = 'node:contextmenu',
|
||||
EDGE_CONTEXTMENU = 'edge:contextmenu',
|
||||
NODE_DBLCLICK = 'node:dblclick',
|
||||
EDGE_DBLCLICK = 'edge:dblclick',
|
||||
CANVAS_MOUSEDOWN = 'canvas:mousedown',
|
||||
CANVAS_MOUSEMOVE = 'canvas:mousemove',
|
||||
CANVAS_MOUSEUP = 'canvas:mouseup',
|
||||
CANVAS_CLICK = 'canvas:click',
|
||||
CANVAS_MOSUELEAVE = 'canvas:mouseleave',
|
||||
KEYUP = 'keyup',
|
||||
KEYDOWN = 'keydown'
|
||||
}
|
||||
|
||||
type GetEvents = 'getEvents';
|
||||
type ShouldBegin = 'shouldBegin';
|
||||
type ShouldUpdate = 'shouldUpdate';
|
||||
type ShouldEnd = 'shouldEnd'
|
||||
type Bind = 'bind'
|
||||
type Unbind = 'unbind'
|
||||
|
||||
export type DefaultBehaviorType = IG6GraphEvent | string | number | object
|
||||
|
||||
export type IBehaviorOpation<U> = {
|
||||
[T in keyof U]:
|
||||
T extends GetEvents ? () => { [key in G6Event]?: string } :
|
||||
T extends ShouldBegin ? (cfg?: IModelConfig) => boolean :
|
||||
T extends ShouldEnd ? (cfg?: IModelConfig) => boolean :
|
||||
T extends ShouldUpdate ? (cfg?: IModelConfig) => boolean :
|
||||
T extends Bind ? (graph: IGraph) => void :
|
||||
T extends Unbind ? (graph: IGraph) => void :
|
||||
(...args: DefaultBehaviorType[]) => unknown;
|
||||
}
|
||||
|
||||
export type IEvent = Record<G6Event, string>
|
||||
|
||||
export interface IG6GraphEvent extends GraphEvent {
|
||||
item: IItem;
|
||||
}
|
||||
|
||||
export interface IBehavior {
|
||||
constructor: (cfg?: object) => void;
|
||||
getEvents: () => { [key in G6Event]?: string };
|
||||
shouldBegin: () => boolean;
|
||||
shouldUpdate: () => boolean;
|
||||
shouldEnd: () => boolean;
|
||||
bind: (graph: IGraph) => void;
|
||||
unbind: (graph: IGraph) => void;
|
||||
[key: string]: (...args: DefaultBehaviorType[]) => unknown;
|
||||
}
|
Loading…
Reference in New Issue
Block a user