Skip to content

NgDiagramModelService

since v0.8.0

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


computePartsBounds(nodes, edges): Rect

Node[]

Array of nodes

Edge<object>[]

Array of edges

Rect

Bounding rectangle containing all nodes and edges

0.9.0

Computes the axis-aligned bounding rectangle that contains all specified nodes and edges.


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<T>(groupId): Node<T>[]

Gets all children nodes for a given group node id

T extends object = object

The type of the nodes’ data property. Defaults to DataObject.

string

group node id

Node<T>[]

Array of child nodes


getChildrenNested<T>(groupId): Node<T>[]

Gets all nested children (descendants) of a group node

T extends object = object

The type of the nodes’ data property. Defaults to DataObject.

string

Group node id

Node<T>[]

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


getConnectedEdges<T>(nodeId): Edge<T>[]

Gets all edges connected to a node

T extends object = object

The type of the edges’ data property. Defaults to DataObject.

string

Node id

Edge<T>[]

Array of edges where the node is either source or target


getConnectedNodes<T>(nodeId): Node<T>[]

Gets all nodes connected to a node via edges

T extends object = object

The type of the nodes’ data property. Defaults to DataObject.

string

Node id

Node<T>[]

Array of nodes connected to the given node


getEdgeById<T>(edgeId): null | Edge<T>

Gets an edge by id.

T extends object = object

The type of the edge’s data property. Defaults to DataObject.

string

Edge id.

null | Edge<T>

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<T>(point, range): null | Node<T>

Gets the nearest node in a range from a point.

T extends object = object

The type of the node’s data property. Defaults to DataObject.

Point

Point to check from.

number

Range to check in.

null | Node<T>

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<T>(nodeId): null | Node<T>

Gets a node by id.

T extends object = object

The type of the node’s data property. Defaults to DataObject.

string

Node id.

null | Node<T>

Node or null if not found.


getNodeEnds<S, T>(edgeId): null | { source: Node<S>; target: Node<T>; }

Gets the source and target nodes of an edge

S extends object = object

The type of the source node’s data property. Defaults to DataObject.

T extends object = object

The type of the target node’s data property. Defaults to DataObject.

string

Edge id

null | { source: Node<S>; target: Node<T>; }

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


getNodesInRange<T>(point, range): Node<T>[]

Gets all nodes in a range from a point.

T extends object = object

The type of the nodes’ data property. Defaults to DataObject.

Point

Point to check from.

number

Range to check in.

Node<T>[]

Array of nodes in range.


getOverlappingNodes<T>(nodeId): Node<T>[]

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

T extends object = object

The type of the nodes’ data property. Defaults to DataObject.

string

The ID of the node to check for collisions

Node<T>[]

An array of Nodes that overlap with the specified node

getOverlappingNodes<T>(node): Node<T>[]

T extends object = object

The type of the nodes’ data property. Defaults to DataObject.

Node<T>

The node to check for collisions

Node<T>[]

An array of Nodes that overlap with the specified node

0.9.0

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


getParentHierarchy<T>(nodeId): GroupNode<T>[]

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

T extends object = object

The type of the group nodes’ data property. Defaults to DataObject.

string

Node id

GroupNode<T>[]

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 object = object

The type of the edge’s data property. Defaults to DataObject.

string

Edge id.

T

New data to set for the edge.

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 object = object

The type of the node’s data property. Defaults to DataObject.

string

Node id.

T

New data to set for the node.

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