From 671e4d72e0b1a2e895d966f46617b491b3df10a6 Mon Sep 17 00:00:00 2001 From: Igor Wessel Date: Sat, 7 Sep 2024 07:47:09 -0300 Subject: [PATCH 1/3] fix(utils): add two underscore for edge id separator --- packages/mermaid/src/utils.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/mermaid/src/utils.ts b/packages/mermaid/src/utils.ts index c1d6748344..05d38d4b89 100644 --- a/packages/mermaid/src/utils.ts +++ b/packages/mermaid/src/utils.ts @@ -939,7 +939,7 @@ export const getEdgeId = ( suffix?: string; } ) => { - return `${prefix ? `${prefix}_` : ''}${from}_${to}_${counter}${suffix ? `_${suffix}` : ''}`; + return `${prefix ? `${prefix}__` : ''}${from}__${to}__${counter}${suffix ? `__${suffix}` : ''}`; }; /** From 0fc9fe7fd8a3a19b630686296d2f70a804567bdc Mon Sep 17 00:00:00 2001 From: Igor Wessel Date: Sat, 7 Sep 2024 07:49:07 -0300 Subject: [PATCH 2/3] feat(state): add from, to id in edge path --- packages/mermaid/src/diagrams/state/dataFetcher.js | 8 ++++++-- .../rendering-util/layout-algorithms/dagre/index.js | 13 ++++++++++--- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/packages/mermaid/src/diagrams/state/dataFetcher.js b/packages/mermaid/src/diagrams/state/dataFetcher.js index 921544ff27..b0650c3bb5 100644 --- a/packages/mermaid/src/diagrams/state/dataFetcher.js +++ b/packages/mermaid/src/diagrams/state/dataFetcher.js @@ -1,3 +1,4 @@ +import { getEdgeId } from '$root/utils.js'; import { getConfig } from '../../diagram-api/diagramAPI.js'; import { log } from '../../logger.js'; import common from '../common/common.js'; @@ -88,7 +89,10 @@ const setupDoc = (parentParsedItem, doc, diagramStates, nodes, edges, altFlag, l classes ); const edgeData = { - id: 'edge' + graphItemCount, + id: getEdgeId(item.state1.id, item.state2.id, { + counter: graphItemCount, + prefix: 'edge', + }), start: item.state1.id, end: item.state2.id, arrowhead: 'normal', @@ -349,7 +353,7 @@ export const dataFetcher = ( } edges.push({ - id: from + '-' + to, + id: getEdgeId(from, to, { prefix: 'edge' }), start: from, end: to, arrowhead: 'none', diff --git a/packages/mermaid/src/rendering-util/layout-algorithms/dagre/index.js b/packages/mermaid/src/rendering-util/layout-algorithms/dagre/index.js index 6f1fa7d3bf..1abd8cd0c4 100644 --- a/packages/mermaid/src/rendering-util/layout-algorithms/dagre/index.js +++ b/packages/mermaid/src/rendering-util/layout-algorithms/dagre/index.js @@ -26,6 +26,7 @@ import { import { log } from '../../../logger.js'; import { getSubGraphTitleMargins } from '../../../utils/subGraphTitleMargins.js'; import { getConfig } from '../../../diagram-api/diagramAPI.js'; +import { getEdgeId } from '$root/utils.js'; const recursiveRender = async (_elem, graph, diagramType, id, parentCluster, siteConfig) => { log.warn('Graph in recursive render:XAX', graphlibJson.write(graph), parentCluster); @@ -345,15 +346,21 @@ export const render = async (data4Layout, svg) => { const edge2 = structuredClone(edge); edge1.label = ''; edge1.arrowTypeEnd = 'none'; - edge1.id = nodeId + '-cyclic-special-1'; + edge1.id = getEdgeId(nodeId, nodeId, { + counter: 'cyclic-special-1', + }); edgeMid.arrowTypeEnd = 'none'; - edgeMid.id = nodeId + '-cyclic-special-mid'; + edgeMid.id = getEdgeId(nodeId, nodeId, { + counter: 'cyclic-special-mid', + }); edge2.label = ''; if (node.isGroup) { edge1.fromCluster = nodeId; edge2.toCluster = nodeId; } - edge2.id = nodeId + '-cyclic-special-2'; + edge2.id = getEdgeId(nodeId, nodeId, { + counter: 'cyclic-special-2', + }); graph.setEdge(nodeId, specialId1, edge1, nodeId + '-cyclic-special-0'); graph.setEdge(specialId1, specialId2, edgeMid, nodeId + '-cyclic-special-1'); graph.setEdge(specialId2, nodeId, edge2, nodeId + '-cyc Date: Fri, 8 Nov 2024 11:10:07 -0300 Subject: [PATCH 3/3] fix(utils): replace with relative path --- packages/mermaid/src/diagrams/state/dataFetcher.js | 2 +- .../mermaid/src/rendering-util/layout-algorithms/dagre/index.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/mermaid/src/diagrams/state/dataFetcher.js b/packages/mermaid/src/diagrams/state/dataFetcher.js index b0650c3bb5..dd5b35a224 100644 --- a/packages/mermaid/src/diagrams/state/dataFetcher.js +++ b/packages/mermaid/src/diagrams/state/dataFetcher.js @@ -1,4 +1,4 @@ -import { getEdgeId } from '$root/utils.js'; +import { getEdgeId } from '../../utils.js'; import { getConfig } from '../../diagram-api/diagramAPI.js'; import { log } from '../../logger.js'; import common from '../common/common.js'; diff --git a/packages/mermaid/src/rendering-util/layout-algorithms/dagre/index.js b/packages/mermaid/src/rendering-util/layout-algorithms/dagre/index.js index 1abd8cd0c4..1c6d1649de 100644 --- a/packages/mermaid/src/rendering-util/layout-algorithms/dagre/index.js +++ b/packages/mermaid/src/rendering-util/layout-algorithms/dagre/index.js @@ -26,7 +26,7 @@ import { import { log } from '../../../logger.js'; import { getSubGraphTitleMargins } from '../../../utils/subGraphTitleMargins.js'; import { getConfig } from '../../../diagram-api/diagramAPI.js'; -import { getEdgeId } from '$root/utils.js'; +import { getEdgeId } from '../../../utils.js'; const recursiveRender = async (_elem, graph, diagramType, id, parentCluster, siteConfig) => { log.warn('Graph in recursive render:XAX', graphlibJson.write(graph), parentCluster);