refactor(NetworkMapUnifi): enhance curve point calculations for improved edge rendering and layout aesthetics
Publish Fast Tabler Docker image / build-and-push-fast (push) Successful in 1m59s
Publish Fast Tabler Docker image / build-and-push-fast (push) Successful in 1m59s
This commit is contained in:
@@ -182,8 +182,10 @@ export default function NetworkMapUnifi({ servers = [], connections = [], pingMa
|
|||||||
}).filter((e) => e.p1 && e.p2);
|
}).filter((e) => e.p1 && e.p2);
|
||||||
}, [connections, positions, pingMap]);
|
}, [connections, positions, pingMap]);
|
||||||
|
|
||||||
// Вычисляем старт/финиш и контрольную точку так, чтобы рёбра выходили
|
// Вычисляем старт/финиш и контрольную точку так, чтобы:
|
||||||
// с «боков» карточек и красиво изгибались (как в UniFi).
|
// - рёбра выходили из карточек строго под 90° (горизонтально/вертикально),
|
||||||
|
// - рядом с узлами был короткий прямой участок,
|
||||||
|
// - далее шла плавная дуга (как в UniFi).
|
||||||
const computeCurvePoints = useCallback((e) => {
|
const computeCurvePoints = useCallback((e) => {
|
||||||
const { p1, p2 } = e;
|
const { p1, p2 } = e;
|
||||||
const dx = p2.x - p1.x;
|
const dx = p2.x - p1.x;
|
||||||
@@ -210,30 +212,40 @@ export default function NetworkMapUnifi({ servers = [], connections = [], pingMa
|
|||||||
ey = p2.y - sign * (NODE_HEIGHT / 2);
|
ey = p2.y - sign * (NODE_HEIGHT / 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
const mx = (sx + ex) / 2;
|
|
||||||
const my = (sy + ey) / 2;
|
|
||||||
const ddx = ex - sx;
|
const ddx = ex - sx;
|
||||||
const ddy = ey - sy;
|
const ddy = ey - sy;
|
||||||
const len = Math.hypot(ddx, ddy) || 1;
|
const len = Math.hypot(ddx, ddy) || 1;
|
||||||
|
const ux = ddx / len;
|
||||||
|
const uy = ddy / len;
|
||||||
|
const stub = 22; // длина прямого участка перед узлами
|
||||||
|
|
||||||
|
// Точки начала/конца дуги (после прямых участков)
|
||||||
|
const csx = sx + ux * stub;
|
||||||
|
const csy = sy + uy * stub;
|
||||||
|
const cex = ex - ux * stub;
|
||||||
|
const cey = ey - uy * stub;
|
||||||
|
|
||||||
|
const mx = (csx + cex) / 2;
|
||||||
|
const my = (csy + cey) / 2;
|
||||||
const baseOffset = 40;
|
const baseOffset = 40;
|
||||||
const perpX = (-ddy / len) * baseOffset;
|
const perpX = (-ddy / len) * baseOffset;
|
||||||
const perpY = (ddx / len) * baseOffset;
|
const perpY = (ddx / len) * baseOffset;
|
||||||
const cpx = mx + perpX;
|
const cpx = mx + perpX;
|
||||||
const cpy = my + perpY;
|
const cpy = my + perpY;
|
||||||
|
|
||||||
return { sx, sy, ex, ey, cpx, cpy };
|
return { sx, sy, ex, ey, csx, csy, cex, cey, cpx, cpy };
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
const pathD = useCallback((e) => {
|
const pathD = useCallback((e) => {
|
||||||
const { sx, sy, ex, ey, cpx, cpy } = computeCurvePoints(e);
|
const { sx, sy, ex, ey, csx, csy, cex, cey, cpx, cpy } = computeCurvePoints(e);
|
||||||
return `M ${sx} ${sy} Q ${cpx} ${cpy} ${ex} ${ey}`;
|
return `M ${sx} ${sy} L ${csx} ${csy} Q ${cpx} ${cpy} ${cex} ${cey} L ${ex} ${ey}`;
|
||||||
}, [computeCurvePoints]);
|
}, [computeCurvePoints]);
|
||||||
|
|
||||||
const labelPoint = useCallback((e) => {
|
const labelPoint = useCallback((e) => {
|
||||||
const { sx, sy, ex, ey, cpx, cpy } = computeCurvePoints(e);
|
const { csx, csy, cex, cey, cpx, cpy } = computeCurvePoints(e);
|
||||||
const t = 0.5;
|
const t = 0.5;
|
||||||
const lx = (1 - t) * (1 - t) * sx + 2 * (1 - t) * t * cpx + t * t * ex;
|
const lx = (1 - t) * (1 - t) * csx + 2 * (1 - t) * t * cpx + t * t * cex;
|
||||||
const ly = (1 - t) * (1 - t) * sy + 2 * (1 - t) * t * cpy + t * t * ey;
|
const ly = (1 - t) * (1 - t) * csy + 2 * (1 - t) * t * cpy + t * t * cey;
|
||||||
return { x: lx, y: ly };
|
return { x: lx, y: ly };
|
||||||
}, [computeCurvePoints]);
|
}, [computeCurvePoints]);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user