Skip to content

NgDiagramModelService

The NgDiagramModelService provides methods for accessing and manipulating the diagram’s model,

private modelService = inject(NgDiagramModelService);
// Add nodes
this.modelService.addNodes([node1, node2]);
  • NgDiagramBaseService
  • OnDestroy

readonly edges: Signal<Edge<object>[]>

Readonly signal of current edges in the diagram.


readonly metadata: Signal<Metadata<object>>

Readonly signal of current diagram metadata.


readonly nodes: Signal<Node[]>

Readonly signal of current nodes in the diagram.

addEdges(edges): void

Adds new edges to the diagram.

Edge<object>[]

Array of edges to add.

void


addNodes(nodes): void

Adds new nodes to the diagram.

Node[]

Array of nodes to add.

void


deleteEdges(ids): void

Deletes edges by their IDs.

string[]

Array of edge IDs to delete.

void


deleteNodes(ids): void

Deletes nodes by their IDs.

string[]

Array of node IDs to delete.

void


getChildren(groupId): Node[]

Gets all children nodes for a given group node id

string

group node id

Node[]

Array of child nodes


getChildrenNested(groupId): Node[]

Gets all nested children (descendants) of a group node

string

Group node id

Node[]

Array of all descendant nodes (children, grandchildren, etc.)


getConnectedEdges(nodeId): Edge<object>[]

Gets all edges connected to a node

string

Node id

Edge<object>[]

Array of edges where the node is either source or target


getConnectedNodes(nodeId): Node[]

Gets all nodes connected to a node via edges

string

Node id

Node[]

Array of nodes connected to the given node


getEdgeById(edgeId): null | Edge<object>

Gets an edge by id.

string

Edge id.

null | Edge<object>

Edge or null if not found.


getModel(): ModelAdapter

Returns the current model that NgDiagram instance is using. Returns null if flowCore is not initialized.

ModelAdapter


getNearestNodeInRange(point, range): null | Node

Gets the nearest node in a range from a point.

Point

Point to check from.

number

Range to check in.

null | Node

Nearest node in range or null.


getNearestPortInRange(point, range): null | Port

Gets the nearest port in a range from a point.

Point

Point to check from.

number

Range to check in.

null | Port

Nearest port in range or null.


getNodeById(nodeId): null | Node

Gets a node by id.

string

Node id.

null | Node

Node or null if not found.


getNodeEnds(edgeId): null | { source: Node; target: Node; }

Gets the source and target nodes of an edge

string

Edge id

null | { source: Node; target: Node; }

Object containing source and target nodes, or null if edge doesn’t exist


getNodesInRange(point, range): Node[]

Gets all nodes in a range from a point.

Point

Point to check from.

number

Range to check in.

Node[]

Array of nodes in range.


getOverlappingNodes(nodeId): Node[]

Detects collision with other nodes by finding all nodes whose rectangles intersect with the specified node’s bounding rectangle.

string

The ID of the node to check for collisions

Node[]

An array of Nodes that overlap with the specified node


getParentHierarchy(nodeId): GroupNode<object>[]

Gets the full chain of parent group Nodes for a given nodeId.

string

Node id

GroupNode<object>[]

Array of parent group Node objects, from closest parent to farthest ancestor


isNestedChild(nodeId, groupId): boolean

Checks if a node is a nested child (descendant) of a group node

string

Node id

string

Group node id

boolean

True if the node is part of the group’s nested subgraph


toJSON(): string

Serializes the current model to a JSON string.

string

The model as a JSON string.


updateEdge(edgeId, edge): void

Updates the properties of an edge.

string

Edge id.

Partial<Edge>

New edge properties.

void


updateEdgeData<T>(edgeId, data): void

Updates the data of an edge.

T extends undefined | Record<string, unknown>

string

Edge id.

T

New data to set for the edge (can be strongly typed).

void


updateEdges(edges): void

Updates multiple edges at once.

Pick<Edge<object>, "id"> & Partial<Edge<object>>[]

Array of edge updates (must include id and any properties to update).

void


updateNode(nodeId, node): void

Updates the properties of a node.

string

Node id.

Partial<Node>

New node properties.

void


updateNodeData<T>(nodeId, data): void

Updates the data of a node.

T extends undefined | Record<string, unknown>

string

Node id.

T

New data to set for the node (can be strongly typed).

void


updateNodes(nodes): void

Updates multiple nodes at once.

Pick<Node, "id"> & Partial<Node>[]

Array of node updates (must include id and any properties to update).

void