From 2b2d002f318e14e8ace92d0d3e3b2c43cd172211 Mon Sep 17 00:00:00 2001 From: yitacls <75364857+yitacls@users.noreply.github.com> Date: Tue, 10 Jun 2025 02:46:00 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=A2=9E=E5=8A=A0=E5=9F=BA=E4=BA=8E?= =?UTF-8?q?=E8=8A=82=E7=82=B9=E5=BA=A6=E6=95=B0=E7=9A=84=E5=9E=82=E7=9B=B4?= =?UTF-8?q?=E5=88=86=E5=B8=83=E5=8A=9B=EF=BC=8C=E9=81=BF=E5=85=8D=E8=BF=87?= =?UTF-8?q?=E4=BA=8E=E5=88=86=E6=95=A3=E6=88=96=E8=81=9A=E9=9B=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/public/script.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/public/script.js b/src/public/script.js index 18452f7..b674d9c 100644 --- a/src/public/script.js +++ b/src/public/script.js @@ -910,7 +910,17 @@ function renderDependencyGraph() { // 其他节点在中间 return width * 0.5; } - }).strength(0.2)) // 调整力的强度,可以根据需要调整 + }).strength(0.2)) + // 新增:基于节点度数的垂直分布力 + .force("y", d3.forceY().y(height / 2).strength(d => { + // 计算节点的总度数(入度+出度) + const inDegree = links.filter(l => (l.target.id || l.target) === d.id).length; + const outDegree = links.filter(l => (l.source.id || l.source) === d.id).length; + const totalDegree = inDegree + outDegree; + + // 度数越大,力越大(基础力0.05,每个连接增加0.03,最大0.3) + return Math.min(0.05 + totalDegree * 0.03, 0.3); + })) .on("tick", ticked); // 添加用於存放連結和節點的組