Appearance
Easy Grouping new
Easy Grouping API Example
This example demonstrates the new easy-to-use grouping API in Ogma, featuring two powerful methods:
Features
1. NodeList.group()
Groups multiple nodes together into a meta-node with a simple method call. This example shows:
- Grouping nodes by category (Technology, Finance, Healthcare, Education)
- Grouping nodes by region (North, South, East, West)
- Custom node generators to style grouped nodes
- Toggle functionality to group/ungroup nodes
2. Node.addSubGraph()
Replaces a single node with a group containing a specified subgraph. This example shows:
- Adding a small subgraph (3 nodes, 3 edges) to any selected node
- Specifying a layout for the subgraph (force layout)
- Creating hierarchical graph structures on-the-fly
Usage
- Group by Category: Click this button to group all nodes by their category attribute
- Group by Region: Click this button to group all nodes by their region attribute
- Add SubGraph: Select a single node, then click this button to replace it with a group containing a small subgraph
- Reset All: Clear all transformations and return to the original graph
- Inspect Groups: Click on any grouped node (purple) to see its sub-nodes logged in the console
API Reference
NodeList.group()
typescript
nodeList.group(options?: GroupByOptions): Promise<void>Groups the nodes in the list together into a meta-node. Options include:
nodeGenerator: Function to customize the meta-node appearanceduration: Animation duration in millisecondspadding: Padding around the grouped contentshowContents: Whether to show the contents of the group
Node.addSubGraph()
typescript
node.addSubGraph(subGraph: RawGraph, layout?: SubLayout): Promise<void>Replaces the node with a group containing the specified subgraph:
subGraph: The graph data (nodes and edges) to add inside the nodelayout: Layout configuration for arranging the subgraph
Key Concepts
- Virtual Nodes: Grouped nodes are marked as "virtual" and can be identified with
node.isVirtual() - Sub-nodes: Access the nodes inside a group with
node.getSubNodes() - Meta-nodes: The parent group of a node can be accessed with
node.getMetaNode()