NgDiagramModelService
The NgDiagramModelService provides methods for accessing and manipulating the diagram’s model,
Example usage
Section titled “Example usage”private modelService = inject(NgDiagramModelService);
// Add nodesthis.modelService.addNodes([node1, node2]);Extends
Section titled “Extends”NgDiagramBaseService
Implements
Section titled “Implements”OnDestroy
Properties
Section titled “Properties”
readonlyedges:Signal<Edge<object>[]>
Readonly signal of current edges in the diagram.
metadata
Section titled “metadata”
readonlymetadata:Signal<Metadata<object>>
Readonly signal of current diagram metadata.
readonlynodes:Signal<Node[]>
Readonly signal of current nodes in the diagram.
Methods
Section titled “Methods”addEdges()
Section titled “addEdges()”addEdges(
edges):void
Adds new edges to the diagram.
Parameters
Section titled “Parameters”Edge<object>[]
Array of edges to add.
Returns
Section titled “Returns”void
addNodes()
Section titled “addNodes()”addNodes(
nodes):void
Adds new nodes to the diagram.
Parameters
Section titled “Parameters”Node[]
Array of nodes to add.
Returns
Section titled “Returns”void
deleteEdges()
Section titled “deleteEdges()”deleteEdges(
ids):void
Deletes edges by their IDs.
Parameters
Section titled “Parameters”string[]
Array of edge IDs to delete.
Returns
Section titled “Returns”void
deleteNodes()
Section titled “deleteNodes()”deleteNodes(
ids):void
Deletes nodes by their IDs.
Parameters
Section titled “Parameters”string[]
Array of node IDs to delete.
Returns
Section titled “Returns”void
getChildren()
Section titled “getChildren()”getChildren(
groupId):Node[]
Gets all children nodes for a given group node id
Parameters
Section titled “Parameters”groupId
Section titled “groupId”string
group node id
Returns
Section titled “Returns”Node[]
Array of child nodes
getChildrenNested()
Section titled “getChildrenNested()”getChildrenNested(
groupId):Node[]
Gets all nested children (descendants) of a group node
Parameters
Section titled “Parameters”groupId
Section titled “groupId”string
Group node id
Returns
Section titled “Returns”Node[]
Array of all descendant nodes (children, grandchildren, etc.)
getConnectedEdges()
Section titled “getConnectedEdges()”getConnectedEdges(
nodeId):Edge<object>[]
Gets all edges connected to a node
Parameters
Section titled “Parameters”nodeId
Section titled “nodeId”string
Node id
Returns
Section titled “Returns”Edge<object>[]
Array of edges where the node is either source or target
getConnectedNodes()
Section titled “getConnectedNodes()”getConnectedNodes(
nodeId):Node[]
Gets all nodes connected to a node via edges
Parameters
Section titled “Parameters”nodeId
Section titled “nodeId”string
Node id
Returns
Section titled “Returns”Node[]
Array of nodes connected to the given node
getEdgeById()
Section titled “getEdgeById()”getEdgeById(
edgeId):null|Edge<object>
Gets an edge by id.
Parameters
Section titled “Parameters”edgeId
Section titled “edgeId”string
Edge id.
Returns
Section titled “Returns”null | Edge<object>
Edge or null if not found.
getModel()
Section titled “getModel()”getModel():
ModelAdapter
Returns the current model that NgDiagram instance is using. Returns null if flowCore is not initialized.
Returns
Section titled “Returns”getNearestNodeInRange()
Section titled “getNearestNodeInRange()”getNearestNodeInRange(
point,range):null|Node
Gets the nearest node in a range from a point.
Parameters
Section titled “Parameters”Point to check from.
number
Range to check in.
Returns
Section titled “Returns”null | Node
Nearest node in range or null.
getNearestPortInRange()
Section titled “getNearestPortInRange()”getNearestPortInRange(
point,range):null|Port
Gets the nearest port in a range from a point.
Parameters
Section titled “Parameters”Point to check from.
number
Range to check in.
Returns
Section titled “Returns”null | Port
Nearest port in range or null.
getNodeById()
Section titled “getNodeById()”getNodeById(
nodeId):null|Node
Gets a node by id.
Parameters
Section titled “Parameters”nodeId
Section titled “nodeId”string
Node id.
Returns
Section titled “Returns”null | Node
Node or null if not found.
getNodeEnds()
Section titled “getNodeEnds()”Gets the source and target nodes of an edge
Parameters
Section titled “Parameters”edgeId
Section titled “edgeId”string
Edge id
Returns
Section titled “Returns”null | { source: Node; target: Node; }
Object containing source and target nodes, or null if edge doesn’t exist
getNodesInRange()
Section titled “getNodesInRange()”getNodesInRange(
point,range):Node[]
Gets all nodes in a range from a point.
Parameters
Section titled “Parameters”Point to check from.
number
Range to check in.
Returns
Section titled “Returns”Node[]
Array of nodes in range.
getOverlappingNodes()
Section titled “getOverlappingNodes()”getOverlappingNodes(
nodeId):Node[]
Detects collision with other nodes by finding all nodes whose rectangles intersect with the specified node’s bounding rectangle.
Parameters
Section titled “Parameters”nodeId
Section titled “nodeId”string
The ID of the node to check for collisions
Returns
Section titled “Returns”Node[]
An array of Nodes that overlap with the specified node
getParentHierarchy()
Section titled “getParentHierarchy()”getParentHierarchy(
nodeId):GroupNode<object>[]
Gets the full chain of parent group Nodes for a given nodeId.
Parameters
Section titled “Parameters”nodeId
Section titled “nodeId”string
Node id
Returns
Section titled “Returns”GroupNode<object>[]
Array of parent group Node objects, from closest parent to farthest ancestor
isNestedChild()
Section titled “isNestedChild()”isNestedChild(
nodeId,groupId):boolean
Checks if a node is a nested child (descendant) of a group node
Parameters
Section titled “Parameters”nodeId
Section titled “nodeId”string
Node id
groupId
Section titled “groupId”string
Group node id
Returns
Section titled “Returns”boolean
True if the node is part of the group’s nested subgraph
toJSON()
Section titled “toJSON()”toJSON():
string
Serializes the current model to a JSON string.
Returns
Section titled “Returns”string
The model as a JSON string.
updateEdge()
Section titled “updateEdge()”updateEdge(
edgeId,edge):void
Updates the properties of an edge.
Parameters
Section titled “Parameters”edgeId
Section titled “edgeId”string
Edge id.
Partial<Edge>
New edge properties.
Returns
Section titled “Returns”void
updateEdgeData()
Section titled “updateEdgeData()”updateEdgeData<
T>(edgeId,data):void
Updates the data of an edge.
Type Parameters
Section titled “Type Parameters”T extends undefined | Record<string, unknown>
Parameters
Section titled “Parameters”edgeId
Section titled “edgeId”string
Edge id.
T
New data to set for the edge (can be strongly typed).
Returns
Section titled “Returns”void
updateEdges()
Section titled “updateEdges()”updateEdges(
edges):void
Updates multiple edges at once.
Parameters
Section titled “Parameters”Pick<Edge<object>, "id"> & Partial<Edge<object>>[]
Array of edge updates (must include id and any properties to update).
Returns
Section titled “Returns”void
updateNode()
Section titled “updateNode()”updateNode(
nodeId,node):void
Updates the properties of a node.
Parameters
Section titled “Parameters”nodeId
Section titled “nodeId”string
Node id.
Partial<Node>
New node properties.
Returns
Section titled “Returns”void
updateNodeData()
Section titled “updateNodeData()”updateNodeData<
T>(nodeId,data):void
Updates the data of a node.
Type Parameters
Section titled “Type Parameters”T extends undefined | Record<string, unknown>
Parameters
Section titled “Parameters”nodeId
Section titled “nodeId”string
Node id.
T
New data to set for the node (can be strongly typed).
Returns
Section titled “Returns”void
updateNodes()
Section titled “updateNodes()”updateNodes(
nodes):void
Updates multiple nodes at once.
Parameters
Section titled “Parameters”Pick<Node, "id"> & Partial<Node>[]
Array of node updates (must include id and any properties to update).
Returns
Section titled “Returns”void