- Go backend (server/)
- Frontend (web/, server/static/)
- Database and deployment files
- Scripts and docs
Co-Authored-By: 狸花猫/Claude-Qwen3.6-Plus 🐾
26 KiB
@antv/graphlib / Exports / GraphWithEvent
Class: GraphWithEvent<NodeIDType, NodeType, EdgeType, GraphType>
Type parameters
| Name | Type |
|---|---|
NodeIDType |
string |
NodeType |
Record<string, any> |
EdgeType |
Record<string, any> |
GraphType |
string |
Hierarchy
-
Graph<NodeIDType,NodeType,EdgeType,GraphType>↳
GraphWithEvent
Table of contents
Constructors
Properties
Methods
- appendEvent
- children
- edge
- edgeCount
- edgeFromArgs
- edges
- emitEvent
- filterNodes
- graph
- hasEdge
- hasNode
- inEdges
- isCompound
- isDirected
- isLeaf
- isMultigraph
- neighbors
- node
- nodeCount
- nodeDegree
- nodeEdges
- nodeInDegree
- nodeOutDegree
- nodes
- outEdges
- parent
- predecessors
- removeEdge
- removeEdgeObj
- removeEvent
- removeNode
- setDefaultEdgeLabel
- setDefaultNodeLabel
- setEdge
- setEdgeObj
- setGraph
- setNode
- setNodes
- setParent
- setPath
- sinks
- source
- sources
- successors
- target
- toJSON
Constructors
constructor
• new GraphWithEvent<NodeIDType, NodeType, EdgeType, GraphType>(options?)
Type parameters
| Name | Type |
|---|---|
NodeIDType |
string |
NodeType |
Record<string, any> |
EdgeType |
Record<string, any> |
GraphType |
string |
Parameters
| Name | Type |
|---|---|
options |
GraphOption |
Inherited from
Defined in
Properties
eventPool
• Private eventPool: Record<string, Function[]> = {}
description a pool of event listeners.
description.zh-cn 事件监听器池。
Defined in
Graph/event.ts:15
label
• Optional label: GraphType
description Label for this graph itself
description.zh-cn 图本身的标签(label)
default undefined
Inherited from
Defined in
fromJSON
▪ Static fromJSON: <NodeIDType, NodeType, EdgeType, GraphType>(json: JSONGraph<NodeIDType, NodeType, EdgeType, GraphType>) => Graph<NodeIDType, NodeType, EdgeType, GraphType> = read
Type declaration
▸ <NodeIDType, NodeType, EdgeType, GraphType>(json): Graph<NodeIDType, NodeType, EdgeType, GraphType>
description read a graph from JSON.
description.zh-cn 从 JSON 读取图。
Type parameters
| Name | Type |
|---|---|
NodeIDType |
string |
NodeType |
Record<string, any> |
EdgeType |
Record<string, any> |
GraphType |
string |
Parameters
| Name | Type |
|---|---|
json |
JSONGraph<NodeIDType, NodeType, EdgeType, GraphType> |
Returns
Graph<NodeIDType, NodeType, EdgeType, GraphType>
Inherited from
Defined in
Methods
appendEvent
▸ appendEvent(type, callback): void
description Add an event listener.
description.zh-cn 添加事件监听器。
Parameters
| Name | Type |
|---|---|
type |
GraphEventType |
callback |
Function |
Returns
void
Defined in
Graph/event.ts:21
children
▸ children(node?): undefined | NodeIDType[]
description get graph's or node's children
description.zh-cn 获取图或者节点的字节点
Parameters
| Name | Type |
|---|---|
node? |
NodeIDType |
Returns
undefined | NodeIDType[]
Inherited from
Defined in
edge
▸ edge(edgeObj): undefined | EdgeType
description Get edge between two nodes by edge object
description.zh-cn 从edgeObj获得两个节点中的一条边
Parameters
| Name | Type |
|---|---|
edgeObj |
Object |
edgeObj.name? |
any |
edgeObj.v |
NodeIDType |
edgeObj.w |
NodeIDType |
Returns
undefined | EdgeType
Inherited from
Defined in
edgeCount
▸ edgeCount(): number
description Count the edge in graph
description.zh-cn 返回图中边的数量
Returns
number
number
Inherited from
Defined in
edgeFromArgs
▸ edgeFromArgs(v, w, name?): undefined | EdgeType
description Get edge between two nodes
description.zh-cn 获得两个节点中的一条边
Parameters
| Name | Type |
|---|---|
v |
NodeIDType |
w |
NodeIDType |
name? |
any |
Returns
undefined | EdgeType
Inherited from
Defined in
edges
▸ edges(): DefaultEdgeType<NodeIDType, EdgeType>[]
description get all edges object in graph
description.zh-cn 获得图中所有的边对象
Returns
DefaultEdgeType<NodeIDType, EdgeType>[]
Inherited from
Defined in
emitEvent
▸ emitEvent(type, ...args): void
description trigger an event.
description.zh-cn 触发事件。
Parameters
| Name | Type |
|---|---|
type |
GraphEventType |
...args |
any[] |
Returns
void
Defined in
Graph/event.ts:46
filterNodes
▸ filterNodes(filter): Graph<NodeIDType, NodeType, EdgeType, GraphType>
description Using node filter to create a new graph;
description.zh-cn 过滤节点并创建一个新图
Parameters
| Name | Type |
|---|---|
filter |
(node: NodeIDType) => boolean |
Returns
Graph<NodeIDType, NodeType, EdgeType, GraphType>
Inherited from
Defined in
graph
▸ graph(): GraphType
description Get Graph label (Identity for graph)
description.zh-cn 获取图的标识符
Returns
GraphType
stirng | undefined
Inherited from
Defined in
hasEdge
▸ hasEdge(v, w, name?): boolean
description Does two nodes has a specific edge
description.zh-cn 两个节点之间是否存在确定的一条边
Parameters
| Name | Type |
|---|---|
v |
NodeIDType |
w |
NodeIDType |
name? |
any |
Returns
boolean
Inherited from
Defined in
hasNode
▸ hasNode(node): boolean
description Is the node in graph
description.zh-cn 判断节点是否在图中
Parameters
| Name | Type |
|---|---|
node |
NodeIDType |
Returns
boolean
Inherited from
Defined in
inEdges
▸ inEdges(v, u?): undefined | DefaultEdgeType<NodeIDType, EdgeType>[]
description get edges that target at the node (could be from certain node)
description.zh-cn 获取所有指向节点的边,可以指定来源节点
Parameters
| Name | Type |
|---|---|
v |
NodeIDType |
u? |
NodeIDType |
Returns
undefined | DefaultEdgeType<NodeIDType, EdgeType>[]
Inherited from
Defined in
isCompound
▸ isCompound(): boolean
description Is this graph a compound graph;
description.zh-cn 这个图是否是复合图(包含嵌套节点的图)
default false
Returns
boolean
Inherited from
Defined in
isDirected
▸ isDirected(): boolean
description Is the graph directed or not
description.zh-cn 这个图是否是有向图
default true
Returns
boolean
Inherited from
Defined in
isLeaf
▸ isLeaf(node): boolean
description Is the node a leaf node
description.zh-cn 判断节点是否为叶子节点
Parameters
| Name | Type |
|---|---|
node |
NodeIDType |
Returns
boolean
Inherited from
Defined in
isMultigraph
▸ isMultigraph(): boolean
description Is this graph contains more than one graph data
description.zh-cn 这个图是否包含多个图
default false
Returns
boolean
Inherited from
Defined in
neighbors
▸ neighbors(node): undefined | NodeIDType[]
description get node's neighbors
description.zh-cn 获取节点的所有邻居节点
Parameters
| Name | Type |
|---|---|
node |
NodeIDType |
Returns
undefined | NodeIDType[]
Inherited from
Defined in
node
▸ node(n): undefined | NodeType
description get node label
description.zh-cn 获取节点的标签
Parameters
| Name | Type |
|---|---|
n |
NodeIDType |
Returns
undefined | NodeType
Inherited from
Defined in
nodeCount
▸ nodeCount(): number
description Count the nodes in graph
description.zh-cn 计算图中所有节点的数量
Returns
number
number
Inherited from
Defined in
nodeDegree
▸ nodeDegree(node): number
description Count the total edges of node
description.zh-cn 计算节点的所有边的数量
Parameters
| Name | Type |
|---|---|
node |
NodeIDType |
Returns
number
Inherited from
Defined in
nodeEdges
▸ nodeEdges(v, w?): undefined | DefaultEdgeType<NodeIDType, EdgeType>[]
description get edges between two nodes
description.zh-cn 获取两个节点间所有的节点
Parameters
| Name | Type |
|---|---|
v |
NodeIDType |
w? |
NodeIDType |
Returns
undefined | DefaultEdgeType<NodeIDType, EdgeType>[]
Inherited from
Defined in
nodeInDegree
▸ nodeInDegree(node): number
description Count the in edges of node
description.zh-cn 计算节点的入边的数量
Parameters
| Name | Type |
|---|---|
node |
NodeIDType |
Returns
number
Inherited from
Defined in
nodeOutDegree
▸ nodeOutDegree(node): number
description Count the out edges of node
description.zh-cn 计算节点的出边的数量
Parameters
| Name | Type |
|---|---|
node |
NodeIDType |
Returns
number
Inherited from
Defined in
nodes
▸ nodes(): NodeIDType[]
description Return all nodes in graph
description 返回图中所有节点
Returns
NodeIDType[]
Inherited from
Defined in
outEdges
▸ outEdges(w, u?): undefined | DefaultEdgeType<NodeIDType, EdgeType>[]
description get edges that from the node (could target at certain node)
description.zh-cn 获取所有来源于节点的边,可以指定目标节点
Parameters
| Name | Type |
|---|---|
w |
NodeIDType |
u? |
NodeIDType |
Returns
undefined | DefaultEdgeType<NodeIDType, EdgeType>[]
Inherited from
Defined in
parent
▸ parent(node): undefined | NodeIDType
description Find node's parent (compond graph only)
description.zh-cn 寻找节点的父节点 (只有复合图可以使用)
Parameters
| Name | Type |
|---|---|
node |
NodeIDType |
Returns
undefined | NodeIDType
Inherited from
Defined in
predecessors
▸ predecessors(node): undefined | NodeIDType[]
description get node's predecessors
description.zh-cn 获取节点的所有上游节点
Parameters
| Name | Type |
|---|---|
node |
NodeIDType |
Returns
undefined | NodeIDType[]
Inherited from
Defined in
removeEdge
▸ removeEdge(v_, w_, name?): GraphWithEvent<NodeIDType, NodeType, EdgeType, GraphType>
Parameters
| Name | Type |
|---|---|
v_ |
NodeIDType |
w_ |
NodeIDType |
name? |
any |
Returns
GraphWithEvent<NodeIDType, NodeType, EdgeType, GraphType>
Overrides
Defined in
Graph/event.ts:73
removeEdgeObj
▸ removeEdgeObj(__namedParameters): this
description remove a specific edge by edge object
description.zh-cn 删除一条边
Parameters
| Name | Type |
|---|---|
__namedParameters |
Object |
__namedParameters.name? |
any |
__namedParameters.v |
NodeIDType |
__namedParameters.w |
NodeIDType |
Returns
this
Inherited from
Defined in
removeEvent
▸ removeEvent(type, callback): void
description remove an event listener.
description.zh-cn 移除事件监听器。
Parameters
| Name | Type |
|---|---|
type |
GraphEventType |
callback |
Function |
Returns
void
Defined in
Graph/event.ts:32
removeNode
▸ removeNode(node): GraphWithEvent<NodeIDType, NodeType, EdgeType, GraphType>
Parameters
| Name | Type |
|---|---|
node |
NodeIDType |
Returns
GraphWithEvent<NodeIDType, NodeType, EdgeType, GraphType>
Overrides
Defined in
Graph/event.ts:61
setDefaultEdgeLabel
▸ setDefaultEdgeLabel(newDefault): this
description Set function that generate default label for edge, if param is non-function value then default label will always be this value;
description.zh-cn 设置默认获取边Label的方法,如果传入不是函数的,那么默认label 的值只会是传入值
Parameters
| Name | Type |
|---|---|
newDefault |
any |
Returns
this
Inherited from
Defined in
setDefaultNodeLabel
▸ setDefaultNodeLabel(newDefault): this
description Set function that generate default label for node, if param is non-function value then default label will always be this value;
description.zh-cn 设置默认获取节点Label的方法,如果传入不是函数的,那么默认label 的值只会是传入值
Parameters
| Name | Type | Description |
|---|---|---|
newDefault |
any |
(node) => label | label |
Returns
this
this
Inherited from
Defined in
setEdge
▸ setEdge(v_, w_, value?, name?): GraphWithEvent<NodeIDType, NodeType, EdgeType, GraphType>
Parameters
| Name | Type |
|---|---|
v_ |
NodeIDType |
w_ |
NodeIDType |
value? |
any |
name? |
string |
Returns
GraphWithEvent<NodeIDType, NodeType, EdgeType, GraphType>
Overrides
Defined in
Graph/event.ts:67
setEdgeObj
▸ setEdgeObj(edgeObj, value?): this
Parameters
| Name | Type |
|---|---|
edgeObj |
DefaultEdgeType<NodeIDType, EdgeType> |
value? |
EdgeType |
Returns
this
Inherited from
Defined in
setGraph
▸ setGraph(label?): this
description Set Graph label (Identity for graph)
description.zh-cn 设置图的标识符
Parameters
| Name | Type |
|---|---|
label? |
GraphType |
Returns
this
Inherited from
Defined in
setNode
▸ setNode(node, value?): GraphWithEvent<NodeIDType, NodeType, EdgeType, GraphType>
Parameters
| Name | Type |
|---|---|
node |
NodeIDType |
value? |
NodeType |
Returns
GraphWithEvent<NodeIDType, NodeType, EdgeType, GraphType>
Overrides
Defined in
Graph/event.ts:55
setNodes
▸ setNodes(nodes, value?): this
description Set nodes or add nodes in batch
description.zh-cn 批量设置或者创建节点
Parameters
| Name | Type |
|---|---|
nodes |
NodeIDType[] |
value? |
NodeType |
Returns
this
Inherited from
Defined in
setParent
▸ setParent(node, parent?): this
description Set node's parent(default is the graph) (compond graph only)
description.zh-cn 设置节点的父节点,如果没有给定,父节点为这个图 (只有复合图可以使用)
Parameters
| Name | Type |
|---|---|
node |
NodeIDType |
parent? |
NodeIDType |
Returns
this
Inherited from
Defined in
setPath
▸ setPath(edges, value?): this
description Add edge using a sorted node array ([a,b,c] => a->b b->c c->a)
description.zh-cn 用一系列节点来定义一群边([a,b,c] => a->b b->c c->a)
Parameters
| Name | Type |
|---|---|
edges |
NodeIDType[] |
value? |
any |
Returns
this
Inherited from
Defined in
sinks
▸ sinks(): NodeIDType[]
description Return all sink nodes in graph
description 返回图中所有终点节点(出度为0)
Returns
NodeIDType[]
Inherited from
Defined in
source
▸ source(edge): NodeIDType
description Get the source of edge
description.zh-cn 获取边的源节点
Parameters
| Name | Type |
|---|---|
edge |
DefaultEdgeType<NodeIDType, EdgeType> |
Returns
NodeIDType
Inherited from
Defined in
sources
▸ sources(): NodeIDType[]
description Return all source nodes in graph
description 返回图中所有源头节点(入度为0)
Returns
NodeIDType[]
Inherited from
Defined in
successors
▸ successors(node): undefined | NodeIDType[]
description get node's successors
description.zh-cn 获取节点的所有下游节点
Parameters
| Name | Type |
|---|---|
node |
NodeIDType |
Returns
undefined | NodeIDType[]
Inherited from
Defined in
target
▸ target(edge): NodeIDType
description Get the target of edge
description.zh-cn 获取边的目标节点
Parameters
| Name | Type |
|---|---|
edge |
DefaultEdgeType<NodeIDType, EdgeType> |
Returns
NodeIDType
Inherited from
Defined in
toJSON
▸ toJSON(): JSONGraph<NodeIDType, NodeType, EdgeType, GraphType>
Returns
JSONGraph<NodeIDType, NodeType, EdgeType, GraphType>