JavaScript is required

Use Dagre layout 2

Advanced Dagre Layout - Clustered layouts with edge optimization

Advanced Dagre Layout Configuration

Functional Overview

This example shows advanced Dagre layout configuration with custom clustering, subgraph handling, and edge routing optimization. It demonstrates how to create complex diagram layouts with grouped nodes, cross-cluster connections, and optimized edge paths.

Implementation of Key Features

Cluster Configuration

const applyClusteredDagreLayout = () => {
    const g = new dagre.graphlib.Graph();
    g.setGraph({
        rankdir: 'LR',
        nodesep: 50,
        ranksep: 80,
        edgesep: 20,
        clustering: true
    });

    // Define clusters
    const clusters = {
        'frontend': ['web', 'mobile', 'desktop'],
        'backend': ['api', 'auth', 'database'],
        'services': ['email', 'storage', 'analytics']
    };

    // Apply cluster styling
    Object.entries(clusters).forEach(([clusterId, members]) => {
        members.forEach(memberId => {
            const node = graphInstance.getNodeById(memberId);
            g.setNode(memberId, {
                width: node.width,
                height: node.height,
                cluster: clusterId
            });
        });
    });
};

Edge Routing

const optimizeEdgeRouting = (g: any) => {
    // Reduce edge crossings
    g.graph().edgesep = 30;

    // Handle long edges
    g.edges().forEach((edge: any) => {
        const edgeData = g.edge(edge);
        if (edgeData.length > 200) {
            // Add intermediate waypoints for long edges
            edgeData.breakpoints = calculateBreakpoints(edge);
        }
    });
};

Creative Use Cases

Microservices Architecture: Visualize service clusters and interactions.

System Design: Complex system diagrams with grouped components.

Process Mapping: Multi-stage processes with departmental boundaries.

Network Topology: Clustered network devices with cross-connections.

Enterprise Architecture: Business capability groupings with dependencies.