Merge pull request #6857 from mermaid-js/elk-exposing-considerModelOrder-to-config

Exposing elk configuration forceNodeModelOrder and considerMode…
This commit is contained in:
Sidharth Vinod
2025-08-14 11:18:58 +00:00
committed by GitHub
8 changed files with 105 additions and 41 deletions

View File

@@ -766,7 +766,10 @@ export const render = async (
id: 'root',
layoutOptions: {
'elk.hierarchyHandling': 'INCLUDE_CHILDREN',
'elk.layered.considerModelOrder.strategy': 'NODES_AND_EDGES',
'elk.layered.crossingMinimization.forceNodeModelOrder':
data4Layout.config.elk?.forceNodeModelOrder,
'elk.layered.considerModelOrder.strategy': data4Layout.config.elk?.considerModelOrder,
'elk.algorithm': algorithm,
'nodePlacement.strategy': data4Layout.config.elk?.nodePlacementStrategy,
'elk.layered.mergeEdges': data4Layout.config.elk?.mergeEdges,

View File

@@ -109,6 +109,16 @@ export interface MermaidConfig {
| 'INTERACTIVE'
| 'MODEL_ORDER'
| 'GREEDY_MODEL_ORDER';
/**
* The node order given by the model does not change to produce a better layout. E.g. if node A is before node B in the model this is not changed during crossing minimization. This assumes that the node model order is already respected before crossing minimization. This can be achieved by setting considerModelOrder.strategy to NODES_AND_EDGES.
*
*/
forceNodeModelOrder?: boolean;
/**
* Preserves the order of nodes and edges in the model file if this does not lead to additional edge crossings. Depending on the strategy this is not always possible since the node and edge order might be conflicting.
*
*/
considerModelOrder?: 'NONE' | 'NODES_AND_EDGES' | 'PREFER_EDGES' | 'PREFER_NODES';
};
darkMode?: boolean;
htmlLabels?: boolean;

View File

@@ -24,6 +24,8 @@ const config: RequiredDeep<MermaidConfig> = {
// mergeEdges is needed here to be considered
mergeEdges: false,
nodePlacementStrategy: 'BRANDES_KOEPF',
forceNodeModelOrder: false,
considerModelOrder: 'NODES_AND_EDGES',
},
themeCSS: undefined,

View File

@@ -133,6 +133,21 @@ properties:
- MODEL_ORDER
- GREEDY_MODEL_ORDER
default: GREEDY_MODEL_ORDER
forceNodeModelOrder:
description: |
The node order given by the model does not change to produce a better layout. E.g. if node A is before node B in the model this is not changed during crossing minimization. This assumes that the node model order is already respected before crossing minimization. This can be achieved by setting considerModelOrder.strategy to NODES_AND_EDGES.
type: boolean
default: false
considerModelOrder:
description: |
Preserves the order of nodes and edges in the model file if this does not lead to additional edge crossings. Depending on the strategy this is not always possible since the node and edge order might be conflicting.
type: string
enum:
- NONE
- NODES_AND_EDGES
- PREFER_EDGES
- PREFER_NODES
default: 'NODES_AND_EDGES'
darkMode:
type: boolean
default: false