Accessing Graph Structure
The read-only graph structure can be accessed via the graph
property of the canvas
.
const element = document.getElementById('canvas'); const canvas = new CanvasBuilder() .setElement(element) .build(); canvas.graph.getAllNodeIds().forEach(nodeId => { console.log(canvas.graph.getNode(nodeId)); });
The graph
object provides all the necessary methods to retrieve the structure of the current graph.
To get the state of a node, call:
This method returnsconst node = canvas.graph.getNode("node-1");
null
if the node does not exist.To get the IDs of all nodes, call:
const nodeIds = canvas.graph.getAllNodeIds();
To get the state of a port, call:
This method returnsconst port = canvas.graph.getPort("port-1");
null
if the port does not exist.To get the IDs of all ports, call:
const portIds = canvas.graph.getAllPortIds();
To get the IDs of all ports for a specific node, call:
This method returnsconst portIds = canvas.graph.getNodePortIds("node-1");
null
if the node does not exist.To get the IDs of all edges, call:
const edgeIds = canvas.graph.getAllEdgeIds();
To get the state of an edge, call:
This method returnsconst edge = canvas.graph.getEdge("edge-1");
null
if the edge does not exist.To get the IDs of incoming edges for a specific port, call:
This method returnsconst edgeIds = canvas.graph.getPortIncomingEdgeIds("port-1");
null
if the port does not exist.To get the IDs of outgoing edges for a specific port, call:
This method returnsconst edgeIds = canvas.graph.getPortOutcomingEdgeIds("port-1");
null
if the port does not exist.To get the IDs of cycle edges for a specific port, call:
This method returnsconst edgeIds = canvas.graph.getPortCycleEdgeIds("port-1");
null
if the port does not exist.To get the IDs of adjacent edges for a specific port, call:
This method returnsconst edgeIds = canvas.graph.getPortAdjacentEdgeIds("port-1");
null
if the port does not exist.To get the IDs of incoming edges for a specific node, call:
This method returnsconst edgeIds = canvas.graph.getNodeIncomingEdgeIds("node-1");
null
if the node does not exist.To get the IDs of outgoing edges for a specific node, call:
This method returnsconst edgeIds = canvas.graph.getNodeOutcomingEdgeIds("node-1");
null
if the node does not exist.To get the IDs of cycle edges for a specific node, call:
This method returnsconst edgeIds = canvas.graph.getNodeCycleEdgeIds("node-1");
null
if the node does not exist. Note: A cycle edge is one where the source port and target port are the same. Therefore, edges with the same source and target node are not necessarily cycle edges.To get the IDs of adjacent edges for a specific node, call:
This method returnsconst edgeIds = canvas.graph.getNodeAdjacentEdgeIds("node-1");
null
if the node does not exist.