mirror of
https://github.com/apache/skywalking-booster-ui.git
synced 2025-05-13 08:17:33 +00:00
fix: section
This commit is contained in:
parent
df5f04a025
commit
ef2a16a387
@ -53,28 +53,18 @@ export function layout(levels: Node[][], calls: Call[]) {
|
||||
}
|
||||
}
|
||||
for (const call of calls) {
|
||||
const sp = lineCircleIntersection(
|
||||
call.sourceObj.x,
|
||||
call.sourceObj.y,
|
||||
call.targetObj.x,
|
||||
call.targetObj.y,
|
||||
const pos: any = getIntersection(
|
||||
call.sourceObj.x,
|
||||
call.sourceObj.y,
|
||||
18,
|
||||
);
|
||||
const tp = lineCircleIntersection(
|
||||
call.sourceObj.x,
|
||||
call.sourceObj.y,
|
||||
call.targetObj.x,
|
||||
call.targetObj.y,
|
||||
call.targetObj.x,
|
||||
call.targetObj.y,
|
||||
18,
|
||||
);
|
||||
call.sourceObj.ax = sp[0];
|
||||
call.sourceObj.ay = sp[1];
|
||||
call.targetObj.ax = tp[0];
|
||||
call.targetObj.ay = tp[1];
|
||||
) || [{}, {}];
|
||||
call.sourceObj.ax = pos[0].x;
|
||||
call.sourceObj.ay = pos[0].y;
|
||||
call.targetObj.ax = pos[1].x;
|
||||
call.targetObj.ay = pos[1].y;
|
||||
}
|
||||
const layout = {
|
||||
width: d3.max(nodes, (n: { x: number }) => n.x) || 0 + node_width + 2 * padding,
|
||||
@ -84,25 +74,32 @@ export function layout(levels: Node[][], calls: Call[]) {
|
||||
return { nodes, layout, calls };
|
||||
}
|
||||
|
||||
function lineCircleIntersection(x1: number, y1: number, x2: number, y2: number, cx: number, cy: number, r: number) {
|
||||
function getIntersection(x1: number, y1: number, r1: number, x2: number, y2: number, r2: number) {
|
||||
const k = (y2 - y1) / (x2 - x1);
|
||||
const b = y1 - k * x1;
|
||||
|
||||
let x = 0;
|
||||
if (k == Infinity || k == -Infinity) {
|
||||
x = x1;
|
||||
} else {
|
||||
x =
|
||||
(b -
|
||||
cy +
|
||||
k * cx +
|
||||
Math.sqrt(
|
||||
Math.abs((cy - b - k * cx) * (cy - b - k * cx) - (1 + k * k) * (cx * cx - 2 * k * cx * cy + cy * cy - r * r)),
|
||||
)) /
|
||||
(1 + k * k);
|
||||
}
|
||||
const A = k * k + 1;
|
||||
const B = 2 * (k * b - k * y1 - x1);
|
||||
const C = y1 * y1 + k * k * x1 * x1 - 2 * k * x1 * y1 - b * b - r1 * r1;
|
||||
|
||||
const delta = B * B - 4 * A * C;
|
||||
|
||||
if (delta < 0) {
|
||||
return null;
|
||||
} else if (delta == 0) {
|
||||
const x = -B / (2 * A);
|
||||
const y = k * x + b;
|
||||
return { x, y };
|
||||
} else {
|
||||
const x1 = (-B + Math.sqrt(delta)) / (2 * A);
|
||||
const y1 = k * x1 + b;
|
||||
|
||||
return [x, y];
|
||||
const x2 = (-B - Math.sqrt(delta)) / (2 * A);
|
||||
const y2 = k * x2 + b;
|
||||
|
||||
return [
|
||||
{ x: x1, y: y1 },
|
||||
{ x: x2, y: y2 },
|
||||
];
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user