Groups
Groups in ngDiagram are containers for other nodes, allowing you to organize, move, and manage multiple nodes as a single unit. They are essential for structuring complex diagrams, enabling collective operations and visual grouping.
What is a Group?
Section titled “What is a Group?”A group is a node that can contain other nodes (children), serving as both a visual and logical container. Groups support most node features but have unique behaviors for layout and interaction.
Key Concepts:
- Container Node: Groups encapsulate other nodes, but child nodes retain their global coordinates.
- Visual Organization: Useful for representing subsystems, clusters, or logical groupings.
- Interactive: Groups can be moved, resized, selected, and highlighted.
To add a node to a group, simply select the node and drag and drop it into the group. To remove a node from a group, drag the node out of the group.
Creating a Group
Section titled “Creating a Group”To create a group, add a node with isGroup: true
to your diagram model.
Child nodes reference their parent group via the groupId
property.
{ id: 'group1', isGroup: true, position: { x: 300, y: 400 }, data: { title: 'My Group' }, // Optional: size, autoSize, resizable},{ id: 'node1', position: { x: 350, y: 450 }, groupId: 'group1', data: { label: 'Child Node' }}
Default Group
Section titled “Default Group”ngDiagram provides a default group template with built-in styling and resizing. If you do not specify a custom type, the default group template is used.
Features:
- Styled container with content area
- Supports resizing and selection
- Highlighted when nodes are dragged over
Resizing Groups
Section titled “Resizing Groups”Groups can be resized interactively if resizable: true
is set.
The resize adornment appears, allowing users to adjust the group’s dimensions.
For more details, see the Group Resizing via diagram config.
Resizing Configuration
Section titled “Resizing Configuration”You can control resizing behavior globally via the resize
config in NgDiagramConfig
, such as setting minimum group size.
The grouping
configuration in NgDiagramConfig
lets you control advanced grouping behavior:
- canGroup callback:
Use the
canGroup
function to control which nodes can be grouped together. This callback receives the group node and the candidate child node, and should returntrue
if grouping is allowed.
config = { resize: { getMinNodeSize: (node) => (node.isGroup ? { width: 200, height: 120 } : { width: 80, height: 40 }), }, grouping: { canGroup: (node: Node, group: Node) => true; },};
Highlighting Groups
Section titled “Highlighting Groups”Groups can be visually highlighted when nodes are dragged over them or programmatically via the highlighted
property.
Selecting Groups
Section titled “Selecting Groups”Groups can be visually selected with built-in functionality.
Rotation
Section titled “Rotation”Groups can be rotated if rotatable: true
is set.
However, rotation only affects the group container—child nodes are not rotated with the group.
Children retain their global orientation and position.
Coordinate System
Section titled “Coordinate System”All group and child node positions are defined in the global coordinate system. Adding a node to a group does not change its coordinates. When a group moves, all its children move by the same delta, preserving their relative positions.
Custom Groups
Section titled “Custom Groups”See Custom Groups for information on creating your own group templates, registering them, and handling advanced behaviors.