Model
阅读时间约 12 分钟
配置
model
画布对应的模型,默认创建一个新模型。
方法
isNode(…)
isNode(cell: Cell): cell is Node
返回指定的 Cell 是否是节点。
参数
名称 类型 必选 默认值 描述
cell Cell ✓ 指定的 Cell。
isEdge(…)
isEdge(cell: Cell): cell is Edge
返回指定的 Cell 是否是边。
参数
名称 类型 必选 默认值 描述
cell Cell ✓ 指定的 Cell。
createNode(…)
createNode(metadata: Node.Metadata): Node
创建节点。
参数
名称 类型 必选 默认值 描述
metadata Node.Metadata ✓ 节点元数据。
addNode(…)
addNode(metadata: Node.Metadata, options?: AddOptions): Node
addNode(node: Node, options?: AddOptions): Node
添加节点到画布,返回添加的节点。
参数
名称 类型 必选 默认值 描述
node Node.Metadata | Node ✓ 节点元数据或节点实例。
options.silent boolean false 为 true 时不触发 ‘node:added’ 和 ‘cell:added’ 事件和画布重绘。
options.sort boolean true 是否按照 zIndex 排序。
options…others object 其他自定义键值对,可以在事件回调中使用。
removeNode(…)
removeNode(nodeId: string, options?: RemoveOptions): Node | null
removeNode(node: Node, options?: RemoveOptions): Node | null
删除节点,返回删除的节点。
参数
名称 类型 必选 默认值 描述
node string | Node ✓ 节点 ID 或节点实例。
options.silent boolean false 为 true 时不触发 ‘node:removed’ 和 ‘cell:removed’ 事件和画布重绘。
options…others object 其他自定义键值对,可以在事件回调中使用。
createEdge(…)
createEdge(metadata: Edge.Metadata): Edge
创建边。
参数
名称 类型 必选 默认值 描述
metadata Edge.Metadata ✓ 节点元数据。
addEdge(…)
addEdge(metadata: Edge.Metadata, options?: AddOptions): Edge
addEdge(edge:Edge, options?: AddOptions): Edge
添加边到画布,返回添加的边。
参数
名称 类型 必选 默认值 描述
edge Edge.Metadata | Edge ✓ 边元数据或边实例。
options.silent boolean false 为 true 时不触发 ‘edge:added’ 和 ‘cell:added’ 事件和画布重绘。
options.sort boolean true 是否按照 zIndex 排序。
options…others object 其他自定义键值对,可以在事件回调中使用。
removeEdge(…)
removeEdge(edgeId: string, options?: RemoveOptions): Edge | null
removeEdge(edge: Edge, options?: RemoveOptions): Edge | null
删除边,返回删除的边。
参数
名称 类型 必选 默认值 描述
edge string | Edge ✓ 边 ID 或边实例。
options.silent boolean false 为 true 时不触发 ‘edge:removed’ 和 ‘cell:removed’ 事件和画布重绘。
options…others object 其他自定义键值对,可以在事件回调中使用。
addCell(…)
addCell(cell: Cell | Cell[], options?: AddOptions): this
添加节点或边到画布。
参数
名称 类型 必选 默认值 描述
cell Cell | Cell[] ✓ 节点实例或边实例,支持传入数组同时添加多个节点或边。
options.silent boolean false 为 true 时不触发 ‘cell:added’、‘node:added’ 和 ‘edge:added’ 事件和画布重绘。
options.sort boolean true 是否按照 zIndex 排序。
options…others object 其他自定义键值对,可以在事件回调中使用。
removeCell(…)
removeCell(cellId: string, options?: RemoveOptions): Cell | null
removeCell(cell: Cell, options?: RemoveOptions): Cell | null
删除节点或边,返回删除的节点或边。
参数
名称 类型 必选 默认值 描述
cell