From 432ec27e684f9696bfaff477c68941958acdf452 Mon Sep 17 00:00:00 2001 From: Sam Date: Tue, 3 Nov 2026 00:06:01 +0800 Subject: [PATCH] Fixed graph layout --- luci/graph.js | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/luci/graph.js b/luci/graph.js index 8afd77e..6874107 100644 --- a/luci/graph.js +++ b/luci/graph.js @@ -960,6 +960,27 @@ if (x.label) x.label.classList.toggle('hl', !!r.edges[i]); }); + spread(r.edges); + }; + // the shown filter labels: edges into one subscription end close together, so their + // labels would lie on each other; each one that hits a placed one goes below it + var spread = function(shown) { + var placed = []; + edgeEls.map(function(x, i) { return shown[i] && x && x.label ? x : null; }).filter(Boolean) + .sort(function(a, b) { return a.by - b.by; }).forEach(function(x) { + var y = x.by, hit = true; + while (hit) { + hit = false; + placed.forEach(function(p) { + if (Math.abs(p.bx - x.bx) < (p.w + x.w) / 2 + 4 && Math.abs(p.y - y) < 12) { + y = p.y + 12; + hit = true; + } + }); + } + placed.push({ bx: x.bx, w: x.w, y: y }); + x.label.setAttribute('y', y); + }); }; var row = function(k, v) { return el('tr', {}, [ el('td', { text: k }), el('td', {}, [].concat(v)) ]); }; @@ -1466,7 +1487,11 @@ // filters on the way into a subscription: halfway along the last stretch if (e.kind == 'use' && e.label && le.pts) { var q = le.pts[le.pts.length - 1], o = le.pts[le.pts.length - 2]; - x.label = el('text', { 'class': 'lbl', x: (o.x + q.x) / 2, y: (o.y + q.y) / 2 - 3, 'text-anchor': 'middle', text: cut(e.label, 30) }); + var t = cut(e.label, 30); + x.bx = (o.x + q.x) / 2; + x.by = (o.y + q.y) / 2 - 3; + x.w = measure(t, 10); + x.label = el('text', { 'class': 'lbl', x: x.bx, y: x.by, 'text-anchor': 'middle', text: t }); gl.appendChild(x.label); } edgeEls[i] = x;