From a9a9e47cd9446db9e63137113c20dafb57d5398b Mon Sep 17 00:00:00 2001 From: Liviu Popa Date: Tue, 19 Apr 2022 14:16:03 +0300 Subject: [PATCH] Added edge spreading in three points over target node Signed-off-by: Liviu Popa --- happi-graph-helpers.js | 43 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/happi-graph-helpers.js b/happi-graph-helpers.js index 2810479..b8233a0 100644 --- a/happi-graph-helpers.js +++ b/happi-graph-helpers.js @@ -272,11 +272,54 @@ export const getNodeAnchorPoint = (node, point) => { } }; +export const adjustDestinationNode = (from, to, toPoint) => { + let offset = 5; + + // upwards right + if(from.x < to.x && from.y > to.y) { + if (toPoint == 'BOTTOM' ) { + to.x = to.x - offset; + }else if (toPoint == 'LEFT'){ + to.y = to.y + offset; + } + } + + // upwards left + if(from.x > to.x && from.y > to.y){ + if(toPoint == 'BOTTOM'){ + to.x = to.x + offset; + }else if (toPoint == 'RIGHT'){ + to.y = to.y + offset; + } + } + + // downwards right + if(from.x < to.x && from.y < to.y){ + if(toPoint == 'TOP'){ + to.x = to.x - offset; + }else if (toPoint == 'LEFT'){ + to.y = to.y - offset; + } + } + + // downwards left + if(from.x > to.x && from.y < to.y){ + if(toPoint == 'TOP'){ + to.x = to.x + offset; + }else if (toPoint == 'LEFT'){ + to.y = to.y - offset; + } + } + + return to; +}; + export const getLinkCoordinates = (nodeA, nodeB, graphDirection) => { let _relativeTo = relativeTo(nodeA, nodeB, graphDirection); let from = getNodeAnchorPoint(nodeA, _relativeTo.a); let to = getNodeAnchorPoint(nodeB, _relativeTo.b); + to = adjustDestinationNode(from, to, _relativeTo.b); return { from: { x: from.x, y: from.y },