From 86c13644a8cb405dd3398967cd92e775faaf5b31 Mon Sep 17 00:00:00 2001 From: Piotr Pekala Date: Tue, 18 Jun 2019 08:09:19 -0700 Subject: [PATCH] reimplementation of adding links --- .../link-created/link-created.component.ts | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/app/components/drawings-listeners/link-created/link-created.component.ts b/src/app/components/drawings-listeners/link-created/link-created.component.ts index baa5286c..338e67c3 100644 --- a/src/app/components/drawings-listeners/link-created/link-created.component.ts +++ b/src/app/components/drawings-listeners/link-created/link-created.component.ts @@ -38,6 +38,9 @@ export class LinkCreatedComponent implements OnInit, OnDestroy { const xLength = Math.abs(linkCreated.sourceNode.x - linkCreated.targetNode.x); const yLength = Math.abs(linkCreated.sourceNode.y - linkCreated.targetNode.y); const zLength = Math.sqrt(Math.pow(xLength, 2) + Math.pow(yLength, 2)); + //from law of sines + const sinY = yLength/zLength; + const x = (45 / zLength) * xLength; const y = (45 / zLength) * yLength; @@ -49,21 +52,21 @@ export class LinkCreatedComponent implements OnInit, OnDestroy { if ((linkCreated.sourceNode.x <= linkCreated.targetNode.x) && (linkCreated.sourceNode.y <= linkCreated.targetNode.y)) { xLabelSourceNode = Math.floor(linkCreated.sourceNode.width/2) + Math.round(x) + 5; yLabelSourceNode = Math.floor(linkCreated.sourceNode.height/2) + Math.round(y) + 5; - xLabelTargetNode = Math.floor(linkCreated.targetNode.width/2) - Math.round(x) - 25; - yLabelTargetNode = Math.floor(linkCreated.targetNode.height/2) - Math.round(y) - 25; + xLabelTargetNode = Math.floor(linkCreated.targetNode.width/2) - Math.round(x) - 5 - Math.round(20 * sinY); + yLabelTargetNode = Math.floor(linkCreated.targetNode.height/2) - Math.round(y) + 5 - Math.round(20 * sinY); } else if ((linkCreated.sourceNode.x > linkCreated.targetNode.x) && (linkCreated.sourceNode.y < linkCreated.targetNode.y)) { - xLabelSourceNode = Math.floor(linkCreated.sourceNode.width/2) - Math.round(x) - 15; - yLabelSourceNode = Math.floor(linkCreated.sourceNode.height/2) + Math.round(y) + 15; + xLabelSourceNode = Math.floor(linkCreated.sourceNode.width/2) - Math.round(x) - 5 - Math.round(20 * sinY); + yLabelSourceNode = Math.floor(linkCreated.sourceNode.height/2) + Math.round(y) + 5 - Math.round(20 * sinY); xLabelTargetNode = Math.floor(linkCreated.targetNode.width/2) + Math.round(x) + 5; yLabelTargetNode = Math.floor(linkCreated.targetNode.height/2) - Math.round(y) - 5; } else if ((linkCreated.sourceNode.x < linkCreated.targetNode.x) && (linkCreated.sourceNode.y > linkCreated.targetNode.y)) { - xLabelSourceNode = Math.floor(linkCreated.sourceNode.width/2) + Math.round(x) + 25; - yLabelSourceNode = Math.floor(linkCreated.sourceNode.height/2) - Math.round(y) - 25; + xLabelSourceNode = Math.floor(linkCreated.sourceNode.width/2) + Math.round(x) + 5 - Math.round(20 * sinY); + yLabelSourceNode = Math.floor(linkCreated.sourceNode.height/2) - Math.round(y) - 5 - Math.round(20 * sinY); xLabelTargetNode = Math.floor(linkCreated.targetNode.width/2) - Math.round(x) - 5; yLabelTargetNode = Math.floor(linkCreated.targetNode.height/2) + Math.round(y) + 5; } else if ((linkCreated.sourceNode.x >= linkCreated.targetNode.x) && (linkCreated.sourceNode.y >= linkCreated.targetNode.y)) { - xLabelSourceNode = Math.floor(linkCreated.sourceNode.width/2) - Math.round(x) - 25; - yLabelSourceNode = Math.floor(linkCreated.sourceNode.height/2) - Math.round(y) - 25; + xLabelSourceNode = Math.floor(linkCreated.sourceNode.width/2) - Math.round(x) - 5 - Math.round(20 * sinY); + yLabelSourceNode = Math.floor(linkCreated.sourceNode.height/2) - Math.round(y) + 5 - Math.round(20 * sinY); xLabelTargetNode = Math.floor(linkCreated.targetNode.width/2) + Math.round(x) + 5; yLabelTargetNode = Math.floor(linkCreated.targetNode.height/2) + Math.round(y) + 5; }