mirror of
https://github.com/jcreek/OpenNetworkDiagram.git
synced 2026-07-13 19:13:43 +00:00
feat(*): Enable lines to turn 90 degrees
This commit is contained in:
@@ -100,10 +100,30 @@
|
|||||||
const cableSpeed = Math.min(localSpeed, remoteSpeed);
|
const cableSpeed = Math.min(localSpeed, remoteSpeed);
|
||||||
const color = getLineColor(cableSpeed);
|
const color = getLineColor(cableSpeed);
|
||||||
|
|
||||||
|
// Calculate the best sockets for the line to exit/enter
|
||||||
|
const localRect = info.element.getBoundingClientRect();
|
||||||
|
const remoteRect = remoteInfo.element.getBoundingClientRect();
|
||||||
|
const dx = remoteRect.left - localRect.left;
|
||||||
|
const dy = remoteRect.top - localRect.top;
|
||||||
|
|
||||||
|
let startSocket = 'right';
|
||||||
|
let endSocket = 'left';
|
||||||
|
if (Math.abs(dx) > Math.abs(dy)) {
|
||||||
|
// More horizontal distance
|
||||||
|
startSocket = dx > 0 ? 'right' : 'left';
|
||||||
|
endSocket = dx > 0 ? 'left' : 'right';
|
||||||
|
} else {
|
||||||
|
// More vertical distance
|
||||||
|
startSocket = dy > 0 ? 'bottom' : 'top';
|
||||||
|
endSocket = dy > 0 ? 'top' : 'bottom';
|
||||||
|
}
|
||||||
|
|
||||||
const line = new LeaderLine(info.element, remoteInfo.element, {
|
const line = new LeaderLine(info.element, remoteInfo.element, {
|
||||||
path: 'straight',
|
path: 'grid',
|
||||||
startPlug: 'behind',
|
startPlug: 'behind',
|
||||||
endPlug: 'behind',
|
endPlug: 'behind',
|
||||||
|
startSocket,
|
||||||
|
endSocket,
|
||||||
color,
|
color,
|
||||||
size: 4,
|
size: 4,
|
||||||
middleLabel: LeaderLine.captionLabel({
|
middleLabel: LeaderLine.captionLabel({
|
||||||
|
|||||||
Reference in New Issue
Block a user