Skip to main content
Registers custom layout algorithms for positioning nodes and edges in diagrams. This allows you to extend Mermaid with additional graph layout engines beyond the built-in options.

Signature

Parameters

LayoutLoaderDefinition[]
required
Array of layout loader definitions.

Return value

void - This method does not return a value.

Layout algorithm interface

The loader must return an object implementing the LayoutAlgorithm interface:

Examples

Basic layout registration

Registering multiple layouts

Using external layout library

Complete layout implementation example

Using layout in diagram configuration

Fallback layout configuration

D3-based layout

Built-in layouts

Mermaid includes these layouts by default:
  • dagre: Hierarchical layout using the Dagre library (default)
  • cose-bilkent: Force-directed layout using COSE (Compound Spring Embedder)

Usage notes

  • Layouts are loaded lazily when first used
  • Custom layouts must implement the LayoutAlgorithm interface
  • The layoutData parameter contains nodes and edges with their properties
  • The svg parameter is a D3 selection of the SVG element
  • The helpers parameter provides access to internal Mermaid utilities
  • Layout algorithm names are case-sensitive
  • If a requested layout is not found, Mermaid falls back to dagre

Layout data structure