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
3. Node.addToGroup() / ungroup() / toggle()
Manage existing groups interactively:
- Drag a node onto a group to add it (
group.addToGroup(nodes)) - Hover a grouped node and click the × button (a DOM overlay) to remove it (
node.ungroup()) - Double-click a group to open or close it (
group.toggle())
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
- Drag / hover / double-click: see the interactions listed in feature 3
API Reference
NodeList.group()
typescript
nodeList.group(options?: GroupByOptions): Promise<Node> // the new group nodeGroups 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, options?: AddSubGraphOptions): Promise<NodeList> // the created group(s)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
Node.addToGroup() / ungroup()
typescript
group.addToGroup(nodes: Node | NodeList): Promise<Node> // throws if `group` is not a group
nodeOrList.ungroup(): void // accepts a single node; nodes not in a group are ignoredKey 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()