Skip to content

Local code intelligence for developers and AI agents. Connect code, docs and infrastructure in a persistent graph, with CBM Lens, MCP tools, agent integrations and change-aware test selection.

fix(ui): keep path labels off the hierarchy band title

Bernhard Jackiewicz282df0ac391f
diff --git a/graph-ui/src/galaxy/HierarchyEdgeLabels.tsx b/graph-ui/src/galaxy/HierarchyEdgeLabels.tsx
index 74a959fe4..b3b9a17e8 100644
--- a/graph-ui/src/galaxy/HierarchyEdgeLabels.tsx
+++ b/graph-ui/src/galaxy/HierarchyEdgeLabels.tsx
@@ -15,6 +15,7 @@ import { useFrame, useThree } from '@react-three/fiber';
import { Html, Line } from '@react-three/drei';
import * as THREE from 'three';
import { placeAlongSegment, type ScreenRect } from './path-frame';
+import { screenBlockers } from './PathLayer';
import type { LabelBox } from './NodeLabels';
import { HIERARCHY_LABEL_FONT_SIZE } from './hierarchy-layout';
import { galaxyHierarchyText } from './galaxy-strings';
@@ -101,9 +102,6 @@ export function edgeLabelVisible(namePixels: number, at: { x: number; y: number
return namePixels >= EDGE_LABEL_MIN_NAME_PIXELS && at.x >= canvas.left && at.x <= canvas.right && at.y >= canvas.top && at.y <= canvas.bottom;
}
-/** Was ausser den Namen frei bleibt: die Ueberschrift des Bandes (DOM, wie die Schilder selbst). */
-const BLOCKER_SELECTOR = '.atlas-hierarchy-band-label';
-
export function HierarchyEdgeLabels({ nodes, edges, layout, nameBoxes }: {
nodes: readonly GraphNode[];
edges: readonly GraphEdge[];
@@ -139,11 +137,9 @@ export function HierarchyEdgeLabels({ nodes, edges, layout, nameBoxes }: {
const a = toScreen(name.x - name.width / 2, name.y + name.height / 2), b = toScreen(name.x + name.width / 2, name.y - name.height / 2);
return { left: Math.min(a.x, b.x), right: Math.max(a.x, b.x), top: Math.min(a.y, b.y), bottom: Math.max(a.y, b.y) };
});
+ // Was ausser den Namen frei bleibt, als DOM wie die Schilder selbst: die Ueberschrift des Bandes (dieselbe Liste wie der Pfad).
const host = connected instanceof HTMLElement ? connected : gl.domElement.parentElement;
- for (const element of host?.querySelectorAll<HTMLElement>(BLOCKER_SELECTOR) ?? []) {
- const rect = element.getBoundingClientRect();
- if (rect.width > 0) blockers.push({ left: rect.left, right: rect.right, top: rect.top, bottom: rect.bottom });
- }
+ if (host) blockers.push(...screenBlockers(host));
const placed: ScreenRect[] = [];
// So hoch steht ein Name auf dem Schirm: die Schriftgroesse der Hierarchie, durch dieselbe Kamera.
const anchor = labels[0]?.from;
diff --git a/graph-ui/src/galaxy/PathLayer.tsx b/graph-ui/src/galaxy/PathLayer.tsx
index 4ab907356..0e12f147e 100644
--- a/graph-ui/src/galaxy/PathLayer.tsx
+++ b/graph-ui/src/galaxy/PathLayer.tsx
@@ -39,8 +39,21 @@ export function pathNodeIds(path: ScenePath): number[] {
return [...ids];
}
-/** Welche Namen das Ausweichen beachtet: die des Pfades und die der markierten Wurzel. */
-const NAME_SELECTOR = '.atlas-galaxy-path-node b, .atlas-galaxy-root-marker b';
+/**
+ * Welchen Texten jedes Kantenlabel der Szene ausweicht: den Namen des Pfades,
+ * denen der markierten Wurzeln und der Ueberschrift des Bandes der Hierarchie.
+ * Die Ueberschrift fehlte hier bis zum Handtest vom 2026-10-04 (G2): ein Pfad
+ * durch das Band legte "DEFINES" auf "Mixed directions · 55 nodes". Die
+ * Kantenschilder der Hierarchie (HierarchyEdgeLabels.tsx) lesen dieselbe Liste.
+ */
+export const LABEL_BLOCKER_SELECTOR = '.atlas-galaxy-path-node b, .atlas-galaxy-root-marker b, .atlas-hierarchy-band-label';
+
+/** Die Kaesten dieser Texte auf dem Schirm; was nicht gezeichnet ist (Breite null), steht niemandem im Weg. */
+export function screenBlockers(host: ParentNode): ScreenRect[] {
+ return [...host.querySelectorAll<HTMLElement>(LABEL_BLOCKER_SELECTOR)]
+ .map((element) => element.getBoundingClientRect()).filter((rect) => rect.width > 0)
+ .map((rect) => ({ left: rect.left, right: rect.right, top: rect.top, bottom: rect.bottom }));
+}
/* Nur jedes dritte Bild: die Lage der Namen aendert sich mit der Kamera, nicht schneller. */
const PLACE_EVERY_FRAMES = 3;
@@ -88,9 +101,7 @@ export function PathLayer({ nodes, path, namedRoots }: {
const host = connected instanceof HTMLElement ? connected : gl.domElement.parentElement;
if (tick.current !== 0 || host === null) return;
const box = gl.domElement.getBoundingClientRect();
- const blockers: ScreenRect[] = [...host.querySelectorAll<HTMLElement>(NAME_SELECTOR)]
- .map((element) => element.getBoundingClientRect()).filter((rect) => rect.width > 0)
- .map((rect) => ({ left: rect.left, right: rect.right, top: rect.top, bottom: rect.bottom }));
+ const blockers = screenBlockers(host);
const toScreen = (node: GraphNode) => {
scratch.point.set(node.x, node.y, node.z).project(camera);
return { x: box.left + ((scratch.point.x + 1) / 2) * box.width, y: box.top + ((1 - scratch.point.y) / 2) * box.height };
diff --git a/graph-ui/src/galaxy/path-frame.test.ts b/graph-ui/src/galaxy/path-frame.test.ts
index 161026793..17aca0345 100644
--- a/graph-ui/src/galaxy/path-frame.test.ts
+++ b/graph-ui/src/galaxy/path-frame.test.ts
@@ -76,4 +76,22 @@ describe('hand test K6: edge labels avoid node names', () => {
expect(placed.overlap).toBe(0);
expect(names.some(name => overlaps(placed.rect, name))).toBe(false);
});
+
+ /*
+ * Hand test 2026-10-04 (G2): a wide heading (the band title of the
+ * hierarchy) covers the middle of a steep edge. Every point from 0.2 to
+ * 0.8 lies under it, and a side step on a steep edge only moves sideways
+ * along the heading. The label still finds the free stretch of its edge
+ * just before or after the heading instead of lying on it.
+ */
+ it('finds the free stretch of its edge beyond a wide heading that covers every usual spot', () => {
+ const heading = { left: -500, right: 500, top: 50, bottom: 250 };
+ const placed = placeAlongSegment({ x: 0, y: 0 }, { x: 10, y: 300 }, size, [heading], []);
+ expect(placed.overlap).toBe(0);
+ expect(overlaps(placed.rect, heading)).toBe(false);
+ // On the edge, not beside it, and not on its end points.
+ expect(placed.side).toBe(0);
+ expect(placed.t).toBeGreaterThan(0.05);
+ expect(placed.t).toBeLessThan(0.95);
+ });
});
diff --git a/graph-ui/src/galaxy/path-frame.ts b/graph-ui/src/galaxy/path-frame.ts
index 39b2a0513..17aa207e9 100644
--- a/graph-ui/src/galaxy/path-frame.ts
+++ b/graph-ui/src/galaxy/path-frame.ts
@@ -77,6 +77,8 @@ function overlapArea(a: ScreenRect, b: ScreenRect): number {
}
const SIDES = [0, 1, -1, 2, -2, 3, -3];
+/* Wie nah ein Label seinen Enden kommen darf, wenn es nur so frei steht: dort laufen die Linien eines Knotens zusammen. */
+const LABEL_CLEAR_RANGE = [0.1, 0.9] as const;
/**
* Wo das Label einer Kante steht: der erste Punkt auf der Kante, an dem es
@@ -84,6 +86,13 @@ const SIDES = [0, 1, -1, 2, -2, 3, -3];
* Ueberdeckung. `t` ist der Anteil auf der Kante, `side` der seitliche Versatz
* in Labelhoehen, hoechstens `maxSide` davon (die Hierarchie bleibt mit ihren
* vielen Linien bei einem, damit ein Schild bei seiner Linie steht).
+ *
+ * Handtest 2026-10-04 (G2): eine breite Ueberschrift (die des Bandes der
+ * Hierarchie) deckte auf einer steilen Kante jeden der Punkte von 0.2 bis 0.8,
+ * und ein Schritt zur Seite fuehrt dort nur an ihr entlang. Bevor das Label
+ * sich mit der kleinsten Ueberdeckung begnuegt, versucht es darum die Stellen
+ * der Kante, an denen es gerade aus einem Hindernis heraustritt, davor und
+ * dahinter, zwischen {@link LABEL_CLEAR_RANGE}.
*/
export function placeAlongSegment(from: { x: number; y: number }, to: { x: number; y: number }, size: { width: number; height: number },
blockers: readonly ScreenRect[], placed: readonly ScreenRect[], maxSide = 3): { t: number; side: number; rect: ScreenRect; overlap: number } {
@@ -91,16 +100,25 @@ export function placeAlongSegment(from: { x: number; y: number }, to: { x: numbe
const normal = { x: -(to.y - from.y) / length, y: (to.x - from.x) / length };
// One side step clears the label's own extent across the edge: its height on a flat edge, its width on a steep one.
const step = (size.width / 2) * Math.abs(normal.x) + (size.height / 2) * Math.abs(normal.y) + 6;
+ const others = [...blockers, ...placed];
let best: { t: number; side: number; rect: ScreenRect; overlap: number } | undefined;
+ const tryAt = (t: number, side: number) => {
+ const offset = side * step;
+ const x = from.x + (to.x - from.x) * t + normal.x * offset, y = from.y + (to.y - from.y) * t + normal.y * offset;
+ const rect = { left: x - size.width / 2, right: x + size.width / 2, top: y - size.height / 2, bottom: y + size.height / 2 };
+ const overlap = others.reduce((sum, other) => sum + overlapArea(rect, other), 0);
+ if (!best || overlap < best.overlap) best = { t, side, rect, overlap };
+ return overlap === 0;
+ };
for (const side of SIDES.filter((value) => Math.abs(value) <= maxSide)) {
- for (const t of LABEL_STEPS) {
- const offset = side * step;
- const x = from.x + (to.x - from.x) * t + normal.x * offset, y = from.y + (to.y - from.y) * t + normal.y * offset;
- const rect = { left: x - size.width / 2, right: x + size.width / 2, top: y - size.height / 2, bottom: y + size.height / 2 };
- const overlap = [...blockers, ...placed].reduce((sum, other) => sum + overlapArea(rect, other), 0);
- if (overlap === 0) return { t, side, rect, overlap };
- if (!best || overlap < best.overlap) best = { t, side, rect, overlap };
- }
+ for (const t of LABEL_STEPS) if (tryAt(t, side)) return best!;
}
+ // The points on the edge where the label just leaves an obstacle, on each of its four sides, nearest the middle first.
+ const dx = to.x - from.x, dy = to.y - from.y, margin = LABEL_PAD + 0.5;
+ const leaving = others.flatMap((other) => [
+ dx ? (other.left - margin - size.width / 2 - from.x) / dx : NaN, dx ? (other.right + margin + size.width / 2 - from.x) / dx : NaN,
+ dy ? (other.top - margin - size.height / 2 - from.y) / dy : NaN, dy ? (other.bottom + margin + size.height / 2 - from.y) / dy : NaN,
+ ]).filter((t) => t >= LABEL_CLEAR_RANGE[0] && t <= LABEL_CLEAR_RANGE[1]).sort((a, b) => Math.abs(a - 0.5) - Math.abs(b - 0.5));
+ for (const t of leaving) if (tryAt(t, 0)) return best!;
return best!;
}
diff --git a/graph-ui/src/galaxy/path-layer.test.ts b/graph-ui/src/galaxy/path-layer.test.ts
new file mode 100644
index 000000000..fca391b41
--- /dev/null
+++ b/graph-ui/src/galaxy/path-layer.test.ts
@@ -0,0 +1,42 @@
+// @vitest-environment jsdom
+/*
+ * Handtest 2026-10-04 (G2): in der Hierarchie lag das Label "DEFINES" eines
+ * Pfades (JSONBAgg <-DEFINES- general.py -DEFINES-> __init__) auf der
+ * Ueberschrift des Bandes "Mixed directions · 55 nodes", und beide Texte
+ * waren nicht mehr zu lesen. Die Labels des Pfades wichen nur den Namen aus,
+ * nicht der Ueberschrift. Jetzt weichen alle Kantenlabels der Szene denselben
+ * Texten aus, und dazu gehoert die Ueberschrift.
+ */
+import { afterEach, expect, it } from 'vitest';
+import { LABEL_BLOCKER_SELECTOR, screenBlockers } from './PathLayer';
+import { placeAlongSegment, type ScreenRect } from './path-frame';
+
+const overlaps = (a: ScreenRect, b: ScreenRect) => !(a.right <= b.left || b.right <= a.left || a.bottom <= b.top || b.bottom <= a.top);
+function element(host: HTMLElement, html: string, rect: ScreenRect): HTMLElement {
+ host.insertAdjacentHTML('beforeend', html);
+ const added = host.lastElementChild as HTMLElement;
+ const target = added.querySelector('b') ?? added;
+ target.getBoundingClientRect = () => ({ ...rect, x: rect.left, y: rect.top, width: rect.right - rect.left, height: rect.bottom - rect.top, toJSON: () => ({}) });
+ return target;
+}
+
+afterEach(() => { document.body.innerHTML = ''; });
+
+it('G2: path labels keep clear of the band heading of the hierarchy, as of the path names', () => {
+ const host = document.createElement('div'); document.body.append(host);
+ // Measured in the browser (CSS px): general.py, __init__ and the band heading in between.
+ const heading = { left: 834, right: 1268, top: 652, bottom: 687 };
+ element(host, '<span class="atlas-hierarchy-band-label"><strong>Mixed directions · 55 nodes</strong></span>', heading);
+ element(host, '<span class="atlas-galaxy-path-node"><i></i><b>general.py</b></span>', { left: 778, right: 838, top: 540, bottom: 557 });
+ element(host, '<span class="atlas-galaxy-path-node"><i></i><b>__init__</b></span>', { left: 1135, right: 1185, top: 725, bottom: 742 });
+ // Hidden or not laid out: no blocker.
+ element(host, '<span class="atlas-galaxy-root-marker"><i></i><b>JSONBAgg</b></span>', { left: 0, right: 0, top: 0, bottom: 0 });
+ expect(host.querySelectorAll(LABEL_BLOCKER_SELECTOR)).toHaveLength(4);
+
+ const blockers = screenBlockers(host);
+ expect(blockers).toHaveLength(3);
+ expect(blockers).toContainEqual(heading);
+ const placed = placeAlongSegment({ x: 808, y: 572 }, { x: 1160, y: 757 }, { width: 50, height: 14 }, blockers, []);
+ expect(placed.overlap).toBe(0);
+ expect(overlaps(placed.rect, heading)).toBe(false);
+});