Skip to content

Commit

Permalink
#5237 fix for node duplication
Browse files Browse the repository at this point in the history
  • Loading branch information
ashishjain0512 committed May 3, 2024
1 parent 913b29d commit 5e53d6c
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 5 deletions.
9 changes: 7 additions & 2 deletions cypress/platform/knsv2.html
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,13 @@
<body>
<pre id="diagram" class="mermaid">
stateDiagram-v2
Chimp --> Gorilla
Chimp --> Bonobo
[*] --> First
state First {
[*] --> second
second --> [*]
}



</pre
>
Expand Down
19 changes: 17 additions & 2 deletions packages/mermaid/src/diagrams/state/stateDb.js
Original file line number Diff line number Diff line change
Expand Up @@ -716,7 +716,12 @@ const dataFetcher = (parent, parsedItem, diagramStates, nodes, edges, altFlag, u
//add parent id to noteData
noteData.parentId = parentId;

Check failure on line 717 in packages/mermaid/src/diagrams/state/stateDb.js

View workflow job for this annotation

GitHub Actions / lint (18.x)

'parentId' is not defined

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;
Expand All @@ -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);

Check failure on line 753 in packages/mermaid/src/diagrams/state/stateDb.js

View workflow job for this annotation

GitHub Actions / lint (18.x)

Unexpected console statement
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ export const draw = async function (text: string, id: string, _version: string,

data4Layout.type = diag.type;

Check failure on line 89 in packages/mermaid/src/diagrams/state/stateRenderer-v3-unified.ts

View workflow job for this annotation

GitHub Actions / build-mermaid (18.x)

Property 'type' does not exist on type 'LayoutData'.
data4Layout.layoutAlgorithm = 'dagre-wrapper';

Check failure on line 90 in packages/mermaid/src/diagrams/state/stateRenderer-v3-unified.ts

View workflow job for this annotation

GitHub Actions / build-mermaid (18.x)

Property 'layoutAlgorithm' does not exist on type 'LayoutData'.
// data4Layout.layoutAlgorithm = 'elk';
//data4Layout.layoutAlgorithm = 'elk';
data4Layout.direction = DIR;

Check failure on line 92 in packages/mermaid/src/diagrams/state/stateRenderer-v3-unified.ts

View workflow job for this annotation

GitHub Actions / build-mermaid (18.x)

Property 'direction' does not exist on type 'LayoutData'.
data4Layout.nodeSpacing = conf.nodeSpacing || 50;

Check failure on line 93 in packages/mermaid/src/diagrams/state/stateRenderer-v3-unified.ts

View workflow job for this annotation

GitHub Actions / build-mermaid (18.x)

Property 'nodeSpacing' does not exist on type 'LayoutData'.

Check failure on line 93 in packages/mermaid/src/diagrams/state/stateRenderer-v3-unified.ts

View workflow job for this annotation

GitHub Actions / build-mermaid (18.x)

'conf' is possibly 'undefined'.

Check failure on line 93 in packages/mermaid/src/diagrams/state/stateRenderer-v3-unified.ts

View workflow job for this annotation

GitHub Actions / build-mermaid (18.x)

Property 'nodeSpacing' does not exist on type 'StateDiagramConfig'.
data4Layout.rankSpacing = conf.rankSpacing || 50;

Check failure on line 94 in packages/mermaid/src/diagrams/state/stateRenderer-v3-unified.ts

View workflow job for this annotation

GitHub Actions / build-mermaid (18.x)

Property 'rankSpacing' does not exist on type 'LayoutData'.

Check failure on line 94 in packages/mermaid/src/diagrams/state/stateRenderer-v3-unified.ts

View workflow job for this annotation

GitHub Actions / build-mermaid (18.x)

'conf' is possibly 'undefined'.

Check failure on line 94 in packages/mermaid/src/diagrams/state/stateRenderer-v3-unified.ts

View workflow job for this annotation

GitHub Actions / build-mermaid (18.x)

Property 'rankSpacing' does not exist on type 'StateDiagramConfig'.
Expand Down

0 comments on commit 5e53d6c

Please sign in to comment.