Skip to content
This repository has been archived by the owner on Jun 10, 2024. It is now read-only.

Commit

Permalink
Added edge spreading in three points over target node
Browse files Browse the repository at this point in the history
Signed-off-by: Liviu Popa <liviu-constantin.popa@ing.com>
  • Loading branch information
lcpopa committed Apr 19, 2022
1 parent 22bf6a7 commit a9a9e47
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions happi-graph-helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 },
Expand Down

0 comments on commit a9a9e47

Please sign in to comment.