From d32fb0e4c0036ddb4b9dd2dc63b156500b975c27 Mon Sep 17 00:00:00 2001 From: Ashish Jain Date: Thu, 26 Aug 2021 17:18:05 +0200 Subject: [PATCH] Fix for classDiagram-v2 support for cardinality label positioning --- src/dagre-wrapper/edges.js | 12 ++++++++---- src/utils.js | 4 ++-- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/dagre-wrapper/edges.js b/src/dagre-wrapper/edges.js index 9f3b00c72..fcdda1d68 100644 --- a/src/dagre-wrapper/edges.js +++ b/src/dagre-wrapper/edges.js @@ -141,7 +141,7 @@ export const positionEdgeLabel = (edge, paths) => { let y = edge.y; if (path) { // debugger; - const pos = utils.calcTerminalLabelPosition(0, 'start_left', path); + const pos = utils.calcTerminalLabelPosition(edge.arrowTypeStart ? 10 : 0, 'start_left', path); x = pos.x; y = pos.y; } @@ -153,7 +153,11 @@ export const positionEdgeLabel = (edge, paths) => { let y = edge.y; if (path) { // debugger; - const pos = utils.calcTerminalLabelPosition(0, 'start_right', path); + const pos = utils.calcTerminalLabelPosition( + edge.arrowTypeStart ? 10 : 0, + 'start_right', + path + ); x = pos.x; y = pos.y; } @@ -165,7 +169,7 @@ export const positionEdgeLabel = (edge, paths) => { let y = edge.y; if (path) { // debugger; - const pos = utils.calcTerminalLabelPosition(0, 'end_left', path); + const pos = utils.calcTerminalLabelPosition(edge.arrowTypeEnd ? 10 : 0, 'end_left', path); x = pos.x; y = pos.y; } @@ -177,7 +181,7 @@ export const positionEdgeLabel = (edge, paths) => { let y = edge.y; if (path) { // debugger; - const pos = utils.calcTerminalLabelPosition(0, 'end_right', path); + const pos = utils.calcTerminalLabelPosition(edge.arrowTypeEnd ? 10 : 0, 'end_right', path); x = pos.x; y = pos.y; } diff --git a/src/utils.js b/src/utils.js index 546d02c2a..96306f189 100644 --- a/src/utils.js +++ b/src/utils.js @@ -410,7 +410,7 @@ const calcTerminalLabelPosition = (terminalMarkerSize, position, _points) => { }); // Traverse only 25 total distance along points to find cardinality point - const distanceToCardinalityPoint = 25; + const distanceToCardinalityPoint = 25 + terminalMarkerSize; let remainingDistance = distanceToCardinalityPoint; let center; @@ -437,7 +437,7 @@ const calcTerminalLabelPosition = (terminalMarkerSize, position, _points) => { prevPoint = point; }); // if relation is present (Arrows will be added), change cardinality point off-set distance (d) - let d = 10; + let d = 10 + terminalMarkerSize * 0.5; //Calculate Angle for x and y axis let angle = Math.atan2(points[0].y - center.y, points[0].x - center.x);