From 11f3cbdb36de6ca77db38b6512e2594b2dd84cd0 Mon Sep 17 00:00:00 2001 From: Knut Sveidqvist Date: Fri, 30 Apr 2021 10:34:50 +0200 Subject: [PATCH] #1958 Handling multiple edges from and to the same node tuple --- cypress/integration/rendering/flowchart-v2.spec.js | 12 ++++++++++++ cypress/platform/knsv.html | 11 +++-------- src/dagre-wrapper/edges.js | 4 ++-- src/diagrams/flowchart/flowRenderer-v2.js | 14 +++++++++++++- 4 files changed, 30 insertions(+), 11 deletions(-) diff --git a/cypress/integration/rendering/flowchart-v2.spec.js b/cypress/integration/rendering/flowchart-v2.spec.js index acc42c68b..48d5e0e95 100644 --- a/cypress/integration/rendering/flowchart-v2.spec.js +++ b/cypress/integration/rendering/flowchart-v2.spec.js @@ -598,4 +598,16 @@ flowchart RL {htmlLabels: true, flowchart: {htmlLabels: true}, securityLevel: 'loose'} ); }); + it('74: Handle labels for multiple edges from and to the same couple of nodes', () => { + imgSnapshotTest( + ` +flowchart RL + subgraph one + a1 -- l1 --> a2 + a1 -- l2 --> a2 + end + `, + {htmlLabels: true, flowchart: {htmlLabels: true}, securityLevel: 'loose'} + ); + }); }); diff --git a/cypress/platform/knsv.html b/cypress/platform/knsv.html index 37272f297..d6db4d0a7 100644 --- a/cypress/platform/knsv.html +++ b/cypress/platform/knsv.html @@ -56,16 +56,11 @@ flowchart TD linkStyle 0,1 color:orange, stroke: orange;
-flowchart TB +flowchart RL subgraph two - b1 + a1 -- l1 --> a2 + a1 -- l2 --> a2 end - subgraph three - c2 - end - - three --> two - two --> c2
flowchart TB diff --git a/src/dagre-wrapper/edges.js b/src/dagre-wrapper/edges.js index f15574535..c70b9732f 100644 --- a/src/dagre-wrapper/edges.js +++ b/src/dagre-wrapper/edges.js @@ -105,7 +105,7 @@ export const insertEdgeLabel = (elem, edge) => { }; export const positionEdgeLabel = (edge, paths) => { - log.info('Moving label', edge.id, edge.label, edgeLabels[edge.id]); + log.info('Moving label abc78 ', edge.id, edge.label, edgeLabels[edge.id]); let path = paths.updatedPath ? paths.updatedPath : paths.originalPath; if (edge.label) { const el = edgeLabels[edge.id]; @@ -114,7 +114,7 @@ export const positionEdgeLabel = (edge, paths) => { if (path) { // // debugger; const pos = utils.calcLabelPosition(path); - log.info('Moving label from (', x, ',', y, ') to (', pos.x, ',', pos.y, ')'); + log.info('Moving label from (', x, ',', y, ') to (', pos.x, ',', pos.y, ') abc78'); // x = pos.x; // y = pos.y; } diff --git a/src/diagrams/flowchart/flowRenderer-v2.js b/src/diagrams/flowchart/flowRenderer-v2.js index fe30599f3..d5fead9dd 100644 --- a/src/diagrams/flowchart/flowRenderer-v2.js +++ b/src/diagrams/flowchart/flowRenderer-v2.js @@ -174,7 +174,9 @@ export const addVertices = function(vert, g, svgId) { * @param {Object} g The graph object */ export const addEdges = function(edges, g) { + log.info('abc78 edges = ', edges); let cnt = 0; + let linkIdCnt = {}; let defaultStyle; let defaultLabelStyle; @@ -189,7 +191,17 @@ export const addEdges = function(edges, g) { cnt++; // Identify Link - var linkId = 'L-' + edge.start + '-' + edge.end; + var linkIdBase = 'L-' + edge.start + '-' + edge.end; + // count the links from+to the same node to give unique id + if (typeof linkIdCnt[linkIdBase] === 'undefined') { + linkIdCnt[linkIdBase] = 0; + log.info('abc78 new entry', linkIdBase, linkIdCnt[linkIdBase]); + } else { + linkIdCnt[linkIdBase]++; + log.info('abc78 new entry', linkIdBase, linkIdCnt[linkIdBase]); + } + let linkId = linkIdBase + '-' + linkIdCnt[linkIdBase]; + log.info('abc78 new link id to be used is', linkIdBase, linkId, linkIdCnt[linkIdBase]); var linkNameStart = 'LS-' + edge.start; var linkNameEnd = 'LE-' + edge.end;