Fixed graph layout

This commit is contained in:
Sam 2026-11-03 00:06:01 +08:00
parent 0f0ab77327
commit 432ec27e68

View File

@ -960,6 +960,27 @@
if (x.label) if (x.label)
x.label.classList.toggle('hl', !!r.edges[i]); 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)) ]); }; 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 // filters on the way into a subscription: halfway along the last stretch
if (e.kind == 'use' && e.label && le.pts) { if (e.kind == 'use' && e.label && le.pts) {
var q = le.pts[le.pts.length - 1], o = le.pts[le.pts.length - 2]; 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); gl.appendChild(x.label);
} }
edgeEls[i] = x; edgeEls[i] = x;