diff --git a/static/app.js b/static/app.js
index f485c5c..bcd2aa6 100644
--- a/static/app.js
+++ b/static/app.js
@@ -324,16 +324,25 @@ function dagSize() {
}
function dagFitView() {
- // 画布适配视口:缩放并居中,让全部节点可见
+ // 画布适配视口:基于节点实际包围盒缩放并居中,让全部节点可见
const s = dagState;
const box = $('#dag-box');
- const {width, height} = dagSize();
if (!box || !s) return;
+ const poss = Object.values(s.pos || {});
+ if (!poss.length) return;
+ const minX = Math.min(...poss.map(p => p.x)) - 120;
+ const maxX = Math.max(...poss.map(p => p.x)) + 120;
+ const minY = Math.min(...poss.map(p => p.y)) - 120;
+ const maxY = Math.max(...poss.map(p => p.y)) + 120;
+ const cw = Math.max(200, maxX - minX), ch = Math.max(200, maxY - minY);
const bw = box.clientWidth, bh = box.clientHeight;
- const scale = Math.max(0.25, Math.min(1, (bw - 60) / width, (bh - 60) / height));
+ const scale = Math.max(0.25, Math.min(1, (bw - 60) / cw, (bh - 60) / ch));
s.scale = scale;
- s.tx = (bw - width * scale) / 2;
- s.ty = (bh - height * scale) / 2;
+ // 节点包围盒中心(viewBox 坐标)对准视口中心
+ const cx = DAG_M + (minX + maxX) / 2;
+ const cy = DAG_M + (minY + maxY) / 2;
+ s.tx = bw / 2 - cx * scale;
+ s.ty = bh / 2 - cy * scale;
dagApplyView();
saveDagState();
}
@@ -382,6 +391,7 @@ function drawDag() {
const body = $('#tab-body');
if (!body) return;
const NW = 140, NHW = 70; // 节点宽 / 半宽
+ const M = DAG_M; // svg 盒边距:节点平移/缩放后仍在盒内可命中
const dagText = t => {
const raw = `#${t.id} ${t.title}`;
return raw.length > 13 ? raw.slice(0, 13) + '…' : raw;
@@ -397,9 +407,9 @@ function drawDag() {
🗑️ 删除区0
-