> **Warning** > > ## THIS IS AN AUTOGENERATED FILE. DO NOT EDIT. > > ## Please edit the corresponding file in [/packages/mermaid/src/docs/layouts/development.md](../../packages/mermaid/src/docs/layouts/development.md). # π οΈ How to Create a New Layout Algorithm in Mermaid Mermaid supports pluggable layout engines, and contributors can add custom layout algorithms to support specialized rendering needs such as clustered layouts, nested structures, or domain-specific visualizations. This guide outlines the steps required to **create and integrate a new layout algorithm** into the Mermaid codebase. --- ## π¦ Prerequisites Before starting, ensure the following: - You have [Node.js](https://nodejs.org/) installed. - You have [pnpm](https://pnpm.io/) installed globally: ```bash npm install -g pnpm ``` --- ## π Step-by-Step Integration ### Refer [Mermaid Contributing Guide](../community/contributing.md) --- ## π§ Implementing Your Custom Layout Algorithm ### 1. Create Your Layout Folder Navigate to the relevant source directory and create a folder for your new algorithm: ```bash cd packages/mermaid/src/layout mkdir myCustomLayout touch myCustomLayout/index.ts ``` > π You can organize supporting files, utils, and types inside this folder. ### 2. Register the Layout Algorithm Open the file: ``` packages/mermaid/src/rendering-util/render.ts ``` Inside the function `registerDefaultLayoutLoaders`, find the `layoutLoaders` array. Add your layout here: ```ts registerDefaultLayoutLoaders([ ..., { id: 'myCustomLayout', loader: () => import('../layout/myCustomLayout'), }, ]); ``` This tells Mermaid how to load your layout dynamically by name (`id`). --- ## π§ͺ Testing Your Algorithm ### 3. Create a Test File To visually test your layout implementation, create a test HTML file in: ``` cypress/platform/ ``` Example: ```bash touch cypress/platform/myCustomLayoutTest.html ``` Inside the file, load your diagram like this: ```html