From 19d46fc823915d2b672868ea127cbd29031468a6 Mon Sep 17 00:00:00 2001 From: Knut Sveidqvist Date: Thu, 22 Aug 2024 16:29:23 +0200 Subject: [PATCH] #5237 Fix for weird line intersection --- .../rendering-elements/edges.js | 29 ++++++++++--------- .../rendering-elements/shapes/question.ts | 9 +++++- 2 files changed, 24 insertions(+), 14 deletions(-) diff --git a/packages/mermaid/src/rendering-util/rendering-elements/edges.js b/packages/mermaid/src/rendering-util/rendering-elements/edges.js index 087fcf0be..0502da097 100644 --- a/packages/mermaid/src/rendering-util/rendering-elements/edges.js +++ b/packages/mermaid/src/rendering-util/rendering-elements/edges.js @@ -429,19 +429,22 @@ export const insertEdge = function (elem, edge, clusterDb, diagramType, startNod const tail = startNode; var head = endNode; - if (head.intersect && tail.intersect) { - points = points.slice(1, edge.points.length - 1); - points.unshift(tail.intersect(points[0])); - log.debug( - 'Last point APA12', - edge.start, - '-->', - edge.end, - points[points.length - 1], - head, - head.intersect(points[points.length - 1]) - ); - points.push(head.intersect(points[points.length - 1])); + if (head.intersect && tail.intersect && points.length > 2) { + const initialStartPoint = Object.assign({}, points[0]); + const newEnd = head.intersect(points[points.length - 2]); + + const newStart = tail.intersect(points[1]); + if (newStart.x && newStart.y) { + points.unshift(newStart); + } else { + points.unshift(initialStartPoint); + } + if (newEnd.x && newEnd.y) { + const lastPoint = points[points.length - 1]; + if (lastPoint.x !== newEnd.x && lastPoint.y !== newEnd.y) { + points.push(newEnd); + } + } } if (edge.toCluster) { log.info('to cluster abc88', clusterDb.get(edge.toCluster)); diff --git a/packages/mermaid/src/rendering-util/rendering-elements/shapes/question.ts b/packages/mermaid/src/rendering-util/rendering-elements/shapes/question.ts index f6f3f3049..ba770ab4e 100644 --- a/packages/mermaid/src/rendering-util/rendering-elements/shapes/question.ts +++ b/packages/mermaid/src/rendering-util/rendering-elements/shapes/question.ts @@ -63,7 +63,14 @@ export const question = async (parent: SVGAElement, node: Node): Promise