mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-09-06 09:06:45 +02:00
#5237 Fix for direction handling using ELK
This commit is contained in:
@@ -32,7 +32,7 @@
|
|||||||
<style>
|
<style>
|
||||||
body {
|
body {
|
||||||
/* background: rgb(221, 208, 208); */
|
/* background: rgb(221, 208, 208); */
|
||||||
background: #333;
|
/* background: #333; */
|
||||||
font-family: 'Arial';
|
font-family: 'Arial';
|
||||||
/* font-size: 18px !important; */
|
/* font-size: 18px !important; */
|
||||||
}
|
}
|
||||||
@@ -89,37 +89,38 @@ stateDiagram
|
|||||||
end note
|
end note
|
||||||
</pre
|
</pre
|
||||||
>
|
>
|
||||||
<pre id="diagram" class="mermaid2">
|
<pre id="diagram" class="mermaid">
|
||||||
stateDiagram-v2
|
stateDiagram-v2
|
||||||
[*] --> Active
|
[*] --> Active
|
||||||
|
|
||||||
state Active {
|
state Active {
|
||||||
|
direction BT
|
||||||
[*] --> NumLockOff
|
[*] --> NumLockOff
|
||||||
NumLockOff --> NumLockOn : EvNumLockPressed
|
NumLockOff --> NumLockOn : EvNumLockPressed
|
||||||
NumLockOn --> NumLockOff : EvNumLockPressed
|
|
||||||
--
|
|
||||||
[*] --> CapsLockOff
|
|
||||||
CapsLockOff --> CapsLockOn : EvCapsLockPressed
|
|
||||||
CapsLockOn --> CapsLockOff : EvCapsLockPressed
|
|
||||||
--
|
|
||||||
[*] --> ScrollLockOff
|
|
||||||
ScrollLockOff --> ScrollLockOn : EvScrollLockPressed
|
|
||||||
ScrollLockOn --> ScrollLockOff : EvScrollLockPressed
|
|
||||||
}
|
}
|
||||||
</pre
|
</pre
|
||||||
>
|
>
|
||||||
<pre id="diagram" class="mermaid">
|
<pre id="diagram" class="mermaid2">
|
||||||
stateDiagram-v2
|
stateDiagram
|
||||||
TN1: The state with a note
|
direction TB
|
||||||
note right of TN1
|
|
||||||
Important information! You can write
|
accTitle: This is the accessible title
|
||||||
notes.
|
accDescr: This is an accessible description
|
||||||
end note
|
|
||||||
TN1 --> TN2
|
classDef notMoving fill:white,color:#000
|
||||||
note left of TN2 : This is the note to the left.
|
classDef movement font-style:italic;
|
||||||
|
classDef badBadEvent fill:#f00,color:white,font-weight:bold,stroke-width:2px,stroke:yellow
|
||||||
|
|
||||||
|
[*] --> Still:::notMoving
|
||||||
|
Still --> [*]
|
||||||
|
Still --> Moving:::movement
|
||||||
|
Moving --> Still
|
||||||
|
Moving --> Crash:::movement
|
||||||
|
Crash:::badBadEvent --> [*]
|
||||||
|
|
||||||
</pre
|
</pre
|
||||||
>
|
>
|
||||||
<pre id="diagram" class="mermaid">
|
<pre id="diagram" class="mermaid2">
|
||||||
%%{init: {"look": "classic"} }%%
|
%%{init: {"look": "classic"} }%%
|
||||||
stateDiagram-v2
|
stateDiagram-v2
|
||||||
TN3: The state with a note
|
TN3: The state with a note
|
||||||
@@ -522,7 +523,7 @@ mindmap
|
|||||||
// useMaxWidth: false,
|
// useMaxWidth: false,
|
||||||
// });
|
// });
|
||||||
mermaid.initialize({
|
mermaid.initialize({
|
||||||
theme: 'dark',
|
// theme: 'dark',
|
||||||
handdrawnSeed: 12,
|
handdrawnSeed: 12,
|
||||||
look: 'handdrawn',
|
look: 'handdrawn',
|
||||||
// layout: 'dagre',
|
// layout: 'dagre',
|
||||||
|
@@ -299,11 +299,11 @@ export const addEdges = function (dataForLayout, graph, svg) {
|
|||||||
linkIdCnt[linkIdBase]++;
|
linkIdCnt[linkIdBase]++;
|
||||||
log.info('abc78 new entry', linkIdBase, linkIdCnt[linkIdBase]);
|
log.info('abc78 new entry', linkIdBase, linkIdCnt[linkIdBase]);
|
||||||
}
|
}
|
||||||
const linkId = linkIdBase + '-' + linkIdCnt[linkIdBase];
|
const linkId = linkIdBase + '_' + linkIdCnt[linkIdBase];
|
||||||
edge.id = linkId;
|
edge.id = linkId;
|
||||||
log.info('abc78 new link id to be used is', linkIdBase, linkId, linkIdCnt[linkIdBase]);
|
log.info('abc78 new link id to be used is', linkIdBase, linkId, linkIdCnt[linkIdBase]);
|
||||||
const linkNameStart = 'LS-' + edge.start;
|
const linkNameStart = 'LS_' + edge.start;
|
||||||
const linkNameEnd = 'LE-' + edge.end;
|
const linkNameEnd = 'LE_' + edge.end;
|
||||||
|
|
||||||
const edgeData = { style: '', labelStyle: '' };
|
const edgeData = { style: '', labelStyle: '' };
|
||||||
edgeData.minlen = edge.length || 1;
|
edgeData.minlen = edge.length || 1;
|
||||||
@@ -436,6 +436,21 @@ export const addEdges = function (dataForLayout, graph, svg) {
|
|||||||
return graph;
|
return graph;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
function dir2ElkDirection(dir) {
|
||||||
|
switch (dir) {
|
||||||
|
case 'LR':
|
||||||
|
return 'RIGHT';
|
||||||
|
case 'RL':
|
||||||
|
return 'LEFT';
|
||||||
|
case 'TB':
|
||||||
|
return 'DOWN';
|
||||||
|
case 'BT':
|
||||||
|
return 'UP';
|
||||||
|
default:
|
||||||
|
return 'DOWN';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export const render = async (data4Layout, svg, element) => {
|
export const render = async (data4Layout, svg, element) => {
|
||||||
const elk = new ELK();
|
const elk = new ELK();
|
||||||
|
|
||||||
@@ -446,7 +461,7 @@ export const render = async (data4Layout, svg, element) => {
|
|||||||
let elkGraph = {
|
let elkGraph = {
|
||||||
id: 'root',
|
id: 'root',
|
||||||
layoutOptions: {
|
layoutOptions: {
|
||||||
'elk.hierarchyHandling': 'INCLUDE_CHILDREN',
|
// 'elk.hierarchyHandling': 'INCLUDE_CHILDREN',
|
||||||
'org.eclipse.elk.padding': '[top=100, left=100, bottom=110, right=110]',
|
'org.eclipse.elk.padding': '[top=100, left=100, bottom=110, right=110]',
|
||||||
'elk.layered.spacing.edgeNodeBetweenLayers': '30',
|
'elk.layered.spacing.edgeNodeBetweenLayers': '30',
|
||||||
},
|
},
|
||||||
@@ -458,23 +473,7 @@ export const render = async (data4Layout, svg, element) => {
|
|||||||
|
|
||||||
// Set the direction of the graph based on the parsed information
|
// Set the direction of the graph based on the parsed information
|
||||||
const dir = data4Layout.direction || 'DOWN';
|
const dir = data4Layout.direction || 'DOWN';
|
||||||
switch (dir) {
|
elkGraph.layoutOptions['elk.direction'] = dir2ElkDirection(dir);
|
||||||
case 'BT':
|
|
||||||
elkGraph.layoutOptions['elk.direction'] = 'UP';
|
|
||||||
break;
|
|
||||||
case 'TB':
|
|
||||||
elkGraph.layoutOptions['elk.direction'] = 'DOWN';
|
|
||||||
break;
|
|
||||||
case 'LR':
|
|
||||||
elkGraph.layoutOptions['elk.direction'] = 'RIGHT';
|
|
||||||
break;
|
|
||||||
case 'RL':
|
|
||||||
elkGraph.layoutOptions['elk.direction'] = 'LEFT';
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
elkGraph.layoutOptions['elk.direction'] = 'DOWN';
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create the lookup db for the subgraphs and their children to used when creating
|
// Create the lookup db for the subgraphs and their children to used when creating
|
||||||
// the tree structured graph
|
// the tree structured graph
|
||||||
@@ -513,7 +512,12 @@ export const render = async (data4Layout, svg, element) => {
|
|||||||
height: node?.labelData?.height || 100,
|
height: node?.labelData?.height || 100,
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
node['elk.direction'] = 'RIGHT';
|
// console.log('DAGA node dir: ', node.dir);
|
||||||
|
if (node.dir) {
|
||||||
|
node.layoutOptions = {
|
||||||
|
'elk.direction': dir2ElkDirection(node.dir),
|
||||||
|
};
|
||||||
|
}
|
||||||
delete node.x;
|
delete node.x;
|
||||||
delete node.y;
|
delete node.y;
|
||||||
delete node.width;
|
delete node.width;
|
||||||
|
Reference in New Issue
Block a user