Import it from @grafloria/engine.
Also has every member of BaseLayoutAlgorithm, listed on its own entry.
HybridLayoutAlgorithm
Intelligent layout algorithm that:
- Analyzes the diagram structure
- Detects patterns (grid, tree, network, sparse)
- Automatically selects the best algorithm
- Delegates to the chosen algorithm
Pattern Detection:
- Grid: Few or no edges, uniform structure
- Tree/Hierarchy: Acyclic, directional flow
- Network: Dense connections, cycles
- Sparse: Few nodes, simple connections
Best for:
- Dynamic diagrams where structure changes
- Mixed diagram types
- When user doesn't want to choose algorithm
tsclass HybridLayoutAlgorithm extends BaseLayoutAlgorithm implements ILayoutAlgorithm
Methods
constructor(options?: HybridOptions)getName(): string— Get the name of the layout algorithmgetType(): 'hybrid'— Get the type of the layout algorithmoverride configure(config: LayoutConfiguration): void— Configure the layout algorithmoverride getConfiguration(): LayoutConfiguration— Get current configurationoverride canApply(diagram: DiagramModel): { valid: boolean; reason?: string }— Validate if this algorithm can be applied to the given diagram
For example:
- Hierarchical layout requires a DAG (no cycles)
- Force-directed works better with connected nodes
calculatePlacement(options: PlacementOptions): PlacementResult— Calculate position for a single new node
This is called when a node is added to the diagram. The algorithm should return a position that:
- Doesn't overlap with existing nodes
- Follows the layout strategy
- Fits within the viewport (or is close to existing content)
reLayout(diagram: DiagramModel, config?: LayoutConfiguration): Map<string, Point>— Re-layout all nodes in the diagram
This is called when the user explicitly requests a re-layout (e.g., clicks "Re-Arrange" button). The algorithm should calculate new positions for ALL nodes.
onActivate(): void— Called when the algorithm is activated Use this to initialize any state or cachesonDeactivate(): void— Called when the algorithm is deactivated Use this to clean up state or cachesgetLastDetectedPattern(): DetectedPattern | undefined— Get the last detected pattern (useful for debugging/UI)
Was this page helpful?