From 2b94baf090421461ee6c6793b5ef98bfff591741 Mon Sep 17 00:00:00 2001 From: fukunee Date: Sun, 15 Nov 2026 10:47:51 +0800 Subject: [PATCH] Notes: wider max width, staggered connector channels, no end dots --- static/js/notes.js | 26 +++++++++----------------- 1 file changed, 9 insertions(+), 17 deletions(-) diff --git a/static/js/notes.js b/static/js/notes.js index a7479ee..2c1cb6d 100644 --- a/static/js/notes.js +++ b/static/js/notes.js @@ -3,11 +3,12 @@ // 窄屏 / 空白不够时交还给 CSS(虚线框内嵌)。 (function () { var MIN_W = 160; // 低于这个宽度就不做边注 - var MAX_W = 320; // 注释最大宽度 - var GAP = 24; // 注释卡片与正文文字之间的间距(折线走这里) + var MAX_W = 360; // 注释最大宽度 + var GAP = 32; // 注释卡片与正文文字之间的间距(折线走这里) var EDGE = 8; // 注释与视口边缘的最小距离 var MIN_STACK = 12; // 同一侧两条注释之间的最小垂直间距 - var STUB = 10; // 折线从原文节点向左先走的一小段 + var CHANNELS = 3; // 折线在间距里分几条竖向通道,避免互相重叠 + var CHANNEL_GAP = 6; // 相邻通道的间距 var SVG_NS = "http://www.w3.org/2000/svg"; function reset(main, notes) { @@ -61,7 +62,7 @@ note.style.width = width + "px"; var height = note.offsetHeight; - var lineY = markRect.top - mr.top + markRect.height * 0.75; + var lineY = markRect.top - mr.top + markRect.height / 2; var top = Math.max(0, lineY - 6); if (top < bottom + MIN_STACK) top = bottom + MIN_STACK; @@ -99,12 +100,11 @@ while (svg.firstChild) svg.removeChild(svg.firstChild); - notes.forEach(function (note) { - var x0 = textLeft - 6; // 原文所在行左侧的节点 + notes.forEach(function (note, noteIndex) { + var x0 = textLeft - 2; // 原文所在行左侧的起点 var x2 = note.offsetLeft + note.offsetWidth; // 卡片右边中点 - // 折线拐点:先向左一小段,再纵向落到卡片中线,最后横向接上卡片 - var x1 = x0 - STUB; - if (x1 <= x2 + 2) x1 = (x0 + x2) / 2; + // 竖向通道:按序号错开,避免几条折线叠在同一根竖线上 + var x1 = x2 + 8 + (noteIndex % CHANNELS) * CHANNEL_GAP; var y0 = note._lineY; var y1 = note._midY; @@ -114,14 +114,6 @@ "M" + x0 + " " + y0 + " H" + x1 + " V" + y1 + " H" + x2, ); svg.appendChild(path); - - [ [x0, y0], [x2, y1] ].forEach(function (p) { - var dot = document.createElementNS(SVG_NS, "circle"); - dot.setAttribute("cx", p[0]); - dot.setAttribute("cy", p[1]); - dot.setAttribute("r", "2.5"); - svg.appendChild(dot); - }); }); }