mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-09-18 06:49:47 +02:00
#5237 fix for node duplication
This commit is contained in:
@@ -74,8 +74,13 @@
|
||||
<body>
|
||||
<pre id="diagram" class="mermaid">
|
||||
stateDiagram-v2
|
||||
Chimp --> Gorilla
|
||||
Chimp --> Bonobo
|
||||
[*] --> First
|
||||
state First {
|
||||
[*] --> second
|
||||
second --> [*]
|
||||
}
|
||||
|
||||
|
||||
|
||||
</pre
|
||||
>
|
||||
|
@@ -716,7 +716,12 @@ const dataFetcher = (parent, parsedItem, diagramStates, nodes, edges, altFlag, u
|
||||
//add parent id to noteData
|
||||
noteData.parentId = parentId;
|
||||
|
||||
nodes.push(groupData, noteData, nodeData);
|
||||
//insert groupData
|
||||
insertOrUpdateNode(nodes, groupData);
|
||||
//insert noteData
|
||||
insertOrUpdateNode(nodes, noteData);
|
||||
//insert nodeData
|
||||
insertOrUpdateNode(nodes, nodeData);
|
||||
|
||||
let from = itemId;
|
||||
let to = noteData.id;
|
||||
@@ -742,7 +747,7 @@ const dataFetcher = (parent, parsedItem, diagramStates, nodes, edges, altFlag, u
|
||||
useRough,
|
||||
});
|
||||
} else {
|
||||
nodes.push(nodeData);
|
||||
insertOrUpdateNode(nodes, nodeData);
|
||||
}
|
||||
|
||||
console.log('Nodes:', nodes);
|
||||
@@ -753,6 +758,16 @@ const dataFetcher = (parent, parsedItem, diagramStates, nodes, edges, altFlag, u
|
||||
}
|
||||
};
|
||||
|
||||
function insertOrUpdateNode(nodes, nodeData) {
|
||||
const existingNodeData = nodes.find((node) => node.id === nodeData.id);
|
||||
if (existingNodeData) {
|
||||
//update the existing nodeData
|
||||
Object.assign(existingNodeData, nodeData);
|
||||
} else {
|
||||
nodes.push(nodeData);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a standard string for the dom ID of an item.
|
||||
* If a type is given, insert that before the counter, preceded by the type spacer
|
||||
|
@@ -88,7 +88,7 @@ export const draw = async function (text: string, id: string, _version: string,
|
||||
|
||||
data4Layout.type = diag.type;
|
||||
data4Layout.layoutAlgorithm = 'dagre-wrapper';
|
||||
// data4Layout.layoutAlgorithm = 'elk';
|
||||
//data4Layout.layoutAlgorithm = 'elk';
|
||||
data4Layout.direction = DIR;
|
||||
data4Layout.nodeSpacing = conf.nodeSpacing || 50;
|
||||
data4Layout.rankSpacing = conf.rankSpacing || 50;
|
||||
|
Reference in New Issue
Block a user