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(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
get the state of a node
This method returnsconst node = canvas.graph.getNode("node-1");
null
if the node does not exist.get the IDs of all nodes
const nodeIds = canvas.graph.getAllNodeIds();
get the IDs of all ports for a specific node
This method returnsconst portIds = canvas.graph.getNodePortIds("node-1");
null
if the node does not exist.get the IDs of incoming edges for a specific node
This method returnsconst edgeIds = canvas.graph.getNodeIncomingEdgeIds("node-1");
null
if the node does not exist.get the IDs of outgoing edges for a specific node
This method returnsconst edgeIds = canvas.graph.getNodeOutgoingEdgeIds("node-1");
null
if the node does not exist.get the IDs of cycle edges for a specific node
This method returnsconst edgeIds = canvas.graph.getNodeCycleEdgeIds("node-1");
null
if the node does not exist.get the IDs of adjacent edges for a specific node
This method returnsconst edgeIds = canvas.graph.getNodeAdjacentEdgeIds("node-1");
null
if the node does not exist.get node ID for a specific HTMLElement
This method returnsconst nodeId = canvas.graph.getElementNodeId(nodeElement);
null
if specified element is not a node.
Ports
get the state of a port
This method returnsconst port = canvas.graph.getPort("port-1");
null
if the port does not exist.get the IDs of all ports
const portIds = canvas.graph.getAllPortIds();
get the IDs of incoming edges for a specific port
This method returnsconst edgeIds = canvas.graph.getPortIncomingEdgeIds("port-1");
null
if the port does not exist.get the IDs of outgoing edges for a specific port
This method returnsconst edgeIds = canvas.graph.getPortOutgoingEdgeIds("port-1");
null
if the port does not exist.get the IDs of cycle edges for a specific port
This method returnsconst edgeIds = canvas.graph.getPortCycleEdgeIds("port-1");
null
if the port does not exist.get the IDs of adjacent edges for a specific port
This method returnsconst edgeIds = canvas.graph.getPortAdjacentEdgeIds("port-1");
null
if the port does not exist.get all port IDs attached to a specific HTMLElement
const portIds = canvas.graph.getElementPortIds(portElement);
Edges
get the IDs of all edges
const edgeIds = canvas.graph.getAllEdgeIds();
get the state of an edge
This method returnsconst edge = canvas.graph.getEdge("edge-1");
null
if the edge does not exist.