Notes: wider max width, staggered connector channels, no end dots
This commit is contained in:
+9
-17
@@ -3,11 +3,12 @@
|
|||||||
// 窄屏 / 空白不够时交还给 CSS(虚线框内嵌)。
|
// 窄屏 / 空白不够时交还给 CSS(虚线框内嵌)。
|
||||||
(function () {
|
(function () {
|
||||||
var MIN_W = 160; // 低于这个宽度就不做边注
|
var MIN_W = 160; // 低于这个宽度就不做边注
|
||||||
var MAX_W = 320; // 注释最大宽度
|
var MAX_W = 360; // 注释最大宽度
|
||||||
var GAP = 24; // 注释卡片与正文文字之间的间距(折线走这里)
|
var GAP = 32; // 注释卡片与正文文字之间的间距(折线走这里)
|
||||||
var EDGE = 8; // 注释与视口边缘的最小距离
|
var EDGE = 8; // 注释与视口边缘的最小距离
|
||||||
var MIN_STACK = 12; // 同一侧两条注释之间的最小垂直间距
|
var MIN_STACK = 12; // 同一侧两条注释之间的最小垂直间距
|
||||||
var STUB = 10; // 折线从原文节点向左先走的一小段
|
var CHANNELS = 3; // 折线在间距里分几条竖向通道,避免互相重叠
|
||||||
|
var CHANNEL_GAP = 6; // 相邻通道的间距
|
||||||
var SVG_NS = "http://www.w3.org/2000/svg";
|
var SVG_NS = "http://www.w3.org/2000/svg";
|
||||||
|
|
||||||
function reset(main, notes) {
|
function reset(main, notes) {
|
||||||
@@ -61,7 +62,7 @@
|
|||||||
note.style.width = width + "px";
|
note.style.width = width + "px";
|
||||||
|
|
||||||
var height = note.offsetHeight;
|
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);
|
var top = Math.max(0, lineY - 6);
|
||||||
if (top < bottom + MIN_STACK) top = bottom + MIN_STACK;
|
if (top < bottom + MIN_STACK) top = bottom + MIN_STACK;
|
||||||
@@ -99,12 +100,11 @@
|
|||||||
|
|
||||||
while (svg.firstChild) svg.removeChild(svg.firstChild);
|
while (svg.firstChild) svg.removeChild(svg.firstChild);
|
||||||
|
|
||||||
notes.forEach(function (note) {
|
notes.forEach(function (note, noteIndex) {
|
||||||
var x0 = textLeft - 6; // 原文所在行左侧的节点
|
var x0 = textLeft - 2; // 原文所在行左侧的起点
|
||||||
var x2 = note.offsetLeft + note.offsetWidth; // 卡片右边中点
|
var x2 = note.offsetLeft + note.offsetWidth; // 卡片右边中点
|
||||||
// 折线拐点:先向左一小段,再纵向落到卡片中线,最后横向接上卡片
|
// 竖向通道:按序号错开,避免几条折线叠在同一根竖线上
|
||||||
var x1 = x0 - STUB;
|
var x1 = x2 + 8 + (noteIndex % CHANNELS) * CHANNEL_GAP;
|
||||||
if (x1 <= x2 + 2) x1 = (x0 + x2) / 2;
|
|
||||||
var y0 = note._lineY;
|
var y0 = note._lineY;
|
||||||
var y1 = note._midY;
|
var y1 = note._midY;
|
||||||
|
|
||||||
@@ -114,14 +114,6 @@
|
|||||||
"M" + x0 + " " + y0 + " H" + x1 + " V" + y1 + " H" + x2,
|
"M" + x0 + " " + y0 + " H" + x1 + " V" + y1 + " H" + x2,
|
||||||
);
|
);
|
||||||
svg.appendChild(path);
|
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);
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user