Graph State
The read-only graph state can be accessed via the graph property of the canvas.
const element = document.getElementById("canvas");
const canvas = new CanvasBuilder(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.
Nodes
check if node exists
const exists = canvas.graph.hasNode("node-1");get the state of a node
const node = canvas.graph.getNode("node-1");get the IDs of all nodes
const nodeIds = canvas.graph.getAllNodeIds();get the IDs of all ports for a specific node
const portIds = canvas.graph.getNodePortIds("node-1");get the IDs of incoming edges for a specific node
const edgeIds = canvas.graph.getNodeIncomingEdgeIds("node-1");get the IDs of outgoing edges for a specific node
const edgeIds = canvas.graph.getNodeOutgoingEdgeIds("node-1");get the IDs of cycle edges for a specific node
const edgeIds = canvas.graph.getNodeCycleEdgeIds("node-1");get the IDs of adjacent edges for a specific node
const edgeIds = canvas.graph.getNodeAdjacentEdgeIds("node-1");get node ID for a specific
ElementThis method returnsconst nodeId = canvas.graph.findNodeIdByElement(nodeElement);undefinedif specified element is not a node.
Ports
check if port exists
const exists = canvas.graph.hasPort("port-1");get the state of a port
const port = canvas.graph.getPort("port-1");get the IDs of all ports
const portIds = canvas.graph.getAllPortIds();get the IDs of incoming edges for a specific port
const edgeIds = canvas.graph.getPortIncomingEdgeIds("port-1");get the IDs of outgoing edges for a specific port
const edgeIds = canvas.graph.getPortOutgoingEdgeIds("port-1");get the IDs of cycle edges for a specific port
const edgeIds = canvas.graph.getPortCycleEdgeIds("port-1");get the IDs of adjacent edges for a specific port
const edgeIds = canvas.graph.getPortAdjacentEdgeIds("port-1");get all port IDs attached to a specific
Elementconst portIds = canvas.graph.findPortIdsByElement(portElement);
Edges
check if edge exists
const exists = canvas.graph.hasEdge("edge-1");get the IDs of all edges
const edgeIds = canvas.graph.getAllEdgeIds();get the state of an edge
const edge = canvas.graph.getEdge("edge-1");