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 names in a two-layer Galaxy hierarchy and tidy its edge labels

Bernhard Jackiewicz76fb819f7b02
diff --git a/graph-ui/src/galaxy/GalaxyPanel.hierarchy-scope.test.tsx b/graph-ui/src/galaxy/GalaxyPanel.hierarchy-scope.test.tsx
index a51b30b3d..b8d90e54c 100644
--- a/graph-ui/src/galaxy/GalaxyPanel.hierarchy-scope.test.tsx
+++ b/graph-ui/src/galaxy/GalaxyPanel.hierarchy-scope.test.tsx
@@ -4,7 +4,7 @@
* der Mitte, Ausgehendes rechts, ein ehrlicher Hinweis, und Pfad und
* Aufrufreihe gibt es auch hier, mit Hervorhebung im Bild der Hierarchie.
*/
-import { act } from 'react';
+import { act, isValidElement } from 'react';
import { createRoot, type Root } from 'react-dom/client';
import { afterEach, beforeEach, expect, it, vi } from 'vitest';
import GalaxyPanel from './GalaxyPanel';
@@ -12,17 +12,25 @@ import type { GraphData } from './types';
import type { ScenePath } from './PathLayer';
import { scopeFetch, scopeNode } from './test-scope-fetch';
import { GALAXY_LEGEND_KEY } from './galaxy-legend';
+import { HierarchyEdgeLabels } from './HierarchyEdgeLabels';
const scene = vi.hoisted(() => ({ data: undefined as GraphData | undefined, path: undefined as ScenePath | undefined, highlighted: null as Set<number> | null,
- labelMaxTextWidth: undefined as number | undefined, overlay: false }));
+ labelMaxTextWidth: undefined as number | undefined, overlay: false, overlayNode: undefined as unknown, showLabels: false, labelBudget: undefined as number | undefined }));
vi.mock('./GraphScene', async importOriginal => ({
...await importOriginal<typeof import('./GraphScene')>(),
- GraphScene: ({ data, path, highlightedIds, labelMaxTextWidth, overlay }: { data: GraphData; path?: ScenePath; highlightedIds: Set<number> | null;
- labelMaxTextWidth?: number; overlay?: unknown }) => {
+ GraphScene: ({ data, path, highlightedIds, labelMaxTextWidth, overlay, showLabels, labelBudget }: { data: GraphData; path?: ScenePath; highlightedIds: Set<number> | null;
+ labelMaxTextWidth?: number; overlay?: unknown; showLabels: boolean; labelBudget?: number }) => {
scene.data = data; scene.path = path; scene.highlighted = highlightedIds; scene.labelMaxTextWidth = labelMaxTextWidth; scene.overlay = Boolean(overlay);
+ scene.overlayNode = overlay; scene.showLabels = showLabels; scene.labelBudget = labelBudget;
return <output data-testid="scene" />;
},
}));
+/** Die Kantenschilder der Hierarchie im Baum der Ueberlagerung, ohne sie zu zeichnen. */
+function edgeLabelProps(node: unknown): { edges: unknown[] } | undefined {
+ if (!isValidElement(node)) return Array.isArray(node) ? node.map(edgeLabelProps).find(Boolean) : undefined;
+ if (node.type === HierarchyEdgeLabels) return node.props as { edges: unknown[] };
+ return edgeLabelProps((node.props as { children?: unknown }).children);
+}
let host: HTMLDivElement, root: Root;
beforeEach(() => {
@@ -89,3 +97,32 @@ it('K5: the hint follows the trace direction', async () => {
});
expect(host.innerHTML).toContain('what the root reaches, one column per layer to the right');
});
+
+/*
+ * Review of K5: above sixty nodes the hierarchy of a scope drew no name at all
+ * (JSONBAgg at two layers, 90 nodes) but eighty edge-type labels. Names now
+ * stand up to 150 nodes, and above that neither names nor edge labels, and the
+ * hint says why and how to get them back.
+ */
+it('K5: a two-layer scope of 90 nodes keeps its names in the hierarchy; above 150 names and edge labels go together, and the hint says so', async () => {
+ const fan = (count: number) => Array.from({ length: count }, (_, at) => scopeNode(100 + at));
+ const render = async (count: number) => {
+ const nodes = [scopeNode(1), ...fan(count)];
+ const edges = fan(count).map((node, at) => ({ id: 10 + at, source: node.id, target: 1, type: 'CALLS' }));
+ await act(async () => root.render(<GalaxyPanel key={count} project="sample" visible workspaceExpanded onOpenNode={vi.fn()} fetch={scopeFetch({ nodes, edges }).fetch} />));
+ await settle(() => expect(seam().nodes).toBe(count + 1));
+ await act(async () => { seam().clickNode('sample.n1'); });
+ await settle(() => expect(host.querySelector('.atlas-graph-scope-count')?.textContent).toBe(`${count + 1} nodes · ${count} edges`));
+ await act(async () => host.querySelector<HTMLButtonElement>('[data-testid="atlas-graph-mode-chip"][data-mode="hierarchy"]')!.click());
+ };
+ await render(89);
+ expect(scene.showLabels).toBe(true);
+ expect(scene.labelBudget).toBeGreaterThanOrEqual(90);
+ expect(edgeLabelProps(scene.overlayNode)?.edges).toHaveLength(89);
+ expect(host.innerHTML).not.toContain('names and edge types show');
+
+ await render(200);
+ expect(scene.showLabels).toBe(false);
+ expect(edgeLabelProps(scene.overlayNode)).toBeUndefined();
+ expect(host.innerHTML).toContain('names and edge types show for up to 150 nodes');
+});
diff --git a/graph-ui/src/galaxy/GalaxyPanel.tsx b/graph-ui/src/galaxy/GalaxyPanel.tsx
index 154ea4691..5daf12b51 100644
--- a/graph-ui/src/galaxy/GalaxyPanel.tsx
+++ b/graph-ui/src/galaxy/GalaxyPanel.tsx
@@ -147,7 +147,7 @@ import { galaxyHistoryOptions, historyEntryDetail, historyEntryLabel, scopeIdent
import { useOrganicLayout } from './use-organic-layout';
import RenderProgress from './RenderProgress';
import { useGraphScope } from './use-graph-scope';
-import { SCOPED_HIERARCHY_LABEL_MAX_TEXT_WIDTH, limitGraphRender, nextLayerEstimate, scenePictureFor, scopedHierarchy } from './graph-scope';
+import { SCOPED_HIERARCHY_LABEL_BUDGET, SCOPED_HIERARCHY_LABEL_MAX_TEXT_WIDTH, limitGraphRender, nextLayerEstimate, scenePictureFor, scopedHierarchy } from './graph-scope';
import './graph-exploration.css';
import { layoutNodeForSelection } from './selected-node';
import { galaxyScopeEvidence, useSelectionEvidence, type SelectionEvidenceListener } from './selection-evidence';
@@ -1109,6 +1109,11 @@ export default function GalaxyPanel(props: GalaxyPanelProps): JSX.Element {
const scopedProjection = useMemo(() => props.workspaceExpanded && scope.scope && scope.result
? scopedHierarchy(scope.result, scope.scope.name) : undefined, [props.workspaceExpanded, scope.scope, scope.result]);
+ /* Review zu K5: bis 150 Knoten stehen in der Hierarchie eines Ausschnitts alle Namen, darueber weder Namen noch Kantenschilder. */
+ const scopedNamesHidden = Boolean(scopedProjection && scopedProjection.data.nodes.length > SCOPED_HIERARCHY_LABEL_BUDGET);
+ const scopedSpots = useMemo(() => scopedProjection
+ ? new Map(scopedProjection.placements.map(placement => [placement.id, { hop: placement.hop, x: placement.x, y: placement.y }])) : undefined,
+ [scopedProjection]);
const projection = useMemo(
() => scopedProjection ?? (readerHierarchyActive ? readerProjection
: activeWalk === undefined ? undefined : projectHierarchy(activeWalk, { layout: data })),
@@ -2368,8 +2373,9 @@ export default function GalaxyPanel(props: GalaxyPanelProps): JSX.Element {
* Koerpern nicht unterscheiden: was hier steht, ist ein Kind ihres Baums.
*/
/* K5: die Kantenarten an den Linien der Hierarchie eines Ausschnitts, solange kein Pfad seine eigenen zeigt. */
- const hierarchyEdgeLabels = mode === 'hierarchy' && scopedProjection && !sceneTrailIds && sceneShown
- ? <HierarchyEdgeLabels nodes={sceneShown.nodes} edges={sceneShown.edges} nameBoxes={labelBoxes} /> : undefined;
+ // Review zu K5: Kantenschilder nur neben Namen; ohne Namen waeren sie Schilder an Punkten, die niemand zuordnen kann.
+ const hierarchyEdgeLabels = mode === 'hierarchy' && scopedProjection && !scopedNamesHidden && !sceneTrailIds && sceneShown
+ ? <HierarchyEdgeLabels nodes={sceneShown.nodes} edges={sceneShown.edges} layout={scopedSpots} nameBoxes={labelBoxes} /> : undefined;
const overlay: ReactNode = (pulseRing === undefined && !liveOn && hierarchyEdgeLabels === undefined) ? undefined : (
<>
{pulseRing}
@@ -2452,7 +2458,7 @@ export default function GalaxyPanel(props: GalaxyPanelProps): JSX.Element {
: candidate === 'galaxy'
? 'galaxy: the whole project, laid out by the server'
: readerHierarchyActive ? 'hierarchy: incoming relationships, file definitions, and outgoing relationships'
- : scopedProjection ? galaxyHierarchyText.hint(scope.direction)
+ : scopedProjection ? galaxyHierarchyText.hint(scope.direction, scopedNamesHidden ? SCOPED_HIERARCHY_LABEL_BUDGET : undefined)
: 'hierarchy: what the chosen symbol reaches, one column per call depth'
}
>
@@ -2823,14 +2829,16 @@ export default function GalaxyPanel(props: GalaxyPanelProps): JSX.Element {
* gestellt wurde.
*
* In der Hierarchie sind die Namen immer an: dort
- * stehen hoechstens sechzig Punkte, und eine
- * Aufrufkette ohne Namen waere eine Reihe Punkte.
+ * stehen hoechstens sechzig Punkte (im Ausschnitt
+ * 150, Review zu K5), und eine Aufrufkette ohne
+ * Namen waere eine Reihe Punkte.
*/
showLabels={
mode === 'hierarchy'
- ? sceneShown.nodes.length <= HIERARCHY_LABEL_BUDGET
+ ? scopedProjection ? !scopedNamesHidden : sceneShown.nodes.length <= HIERARCHY_LABEL_BUDGET
: trailIds !== undefined || (highlighted !== null && highlighted.size > 0)
}
+ labelBudget={mode === 'hierarchy' && scopedProjection ? SCOPED_HIERARCHY_LABEL_BUDGET : undefined}
/*
* Landmarken nur in der Galaxie: der Halo sitzt auf den
* groessten Knoten, und "gross" heisst in der Projektion
diff --git a/graph-ui/src/galaxy/GraphScene.tsx b/graph-ui/src/galaxy/GraphScene.tsx
index 2d678fd79..61a72b0a8 100644
--- a/graph-ui/src/galaxy/GraphScene.tsx
+++ b/graph-ui/src/galaxy/GraphScene.tsx
@@ -849,6 +849,8 @@ interface GraphSceneProps {
/* Label geometry, passed straight through to NodeLabels (Aenderung 9). */
labelWorldFontSize?: number | undefined;
labelMaxTextWidth?: number | undefined;
+ /* Wie viele Namen hoechstens; ohne Angabe die achtzig von NodeLabels (Review zu K5: die Hierarchie eines Ausschnitts traegt mehr). */
+ labelBudget?: number | undefined;
onLabelLayout?: ((boxes: LabelBox[]) => void) | undefined;
/* Aenderung 10 (W10): was Rechenzeit kostet. Ohne diese vier zeichnet die
* Szene wie vorher. */
@@ -902,6 +904,7 @@ export function GraphScene({
overlay,
labelWorldFontSize,
labelMaxTextWidth,
+ labelBudget,
onLabelLayout,
projection = 'spatial',
drawEdges = true,
@@ -1070,6 +1073,7 @@ export function GraphScene({
<NodeLabels
nodes={labelNodes}
highlightedIds={highlightedIds}
+ {...(labelBudget !== undefined ? { maxLabels: labelBudget } : {})}
worldFontSize={labelWorldFontSize}
maxTextWidth={labelMaxTextWidth}
maxDistance={labelMaxDistance}
diff --git a/graph-ui/src/galaxy/HierarchyEdgeLabels.tsx b/graph-ui/src/galaxy/HierarchyEdgeLabels.tsx
index 83f5330e3..739b79329 100644
--- a/graph-ui/src/galaxy/HierarchyEdgeLabels.tsx
+++ b/graph-ui/src/galaxy/HierarchyEdgeLabels.tsx
@@ -15,6 +15,7 @@ import { Html } from '@react-three/drei';
import * as THREE from 'three';
import { placeAlongSegment, type ScreenRect } from './path-frame';
import type { LabelBox } from './NodeLabels';
+import { HIERARCHY_LABEL_FONT_SIZE } from './hierarchy-layout';
import type { GraphEdge, GraphNode } from './types';
/** Mehr Schilder waeren kein Text mehr, sondern eine Flaeche. */
@@ -22,8 +23,21 @@ export const HIERARCHY_EDGE_LABEL_BUDGET = 80;
export interface HierarchyEdgeLabel { key: string; source: number; target: number; text: string }
-/** Ein Schild je Knotenpaar, die Arten ohne Doppelte, CALLS zuerst. */
-export function hierarchyEdgeLabels(edges: readonly GraphEdge[]): HierarchyEdgeLabel[] {
+/** Wo ein Knoten in der Hierarchie steht: Ebene und Lage. */
+export type HierarchySpot = { hop: number; x: number; y: number };
+
+/*
+ * Ein Schild je Knotenpaar, die Arten ohne Doppelte, CALLS zuerst.
+ *
+ * Mit `layout` (Review zu K5): bei zwei Ebenen um JSONBAgg standen achtzig
+ * Schilder auf den ersten achtzig Paaren in Kantenreihenfolge, Reihen von
+ * "DEFINES" ohne einen Namen. Jetzt traegt jede Linie an der Wurzel ihr
+ * Schild; weiter draussen bekommt ein Faecher, ein Knoten zu vielen ueber
+ * dieselben Arten, EIN Schild mit seiner Zahl auf seiner mittleren Linie. Die
+ * Reihenfolge geht von der Wurzel nach aussen, damit eine Obergrenze die
+ * aeusseren Schilder trifft und nicht die inneren.
+ */
+export function hierarchyEdgeLabels(edges: readonly GraphEdge[], layout?: ReadonlyMap<number, HierarchySpot>): HierarchyEdgeLabel[] {
const pairs = new Map<string, { source: number; target: number; types: Set<string> }>();
for (const edge of edges) {
if (edge.source === edge.target) continue;
@@ -32,25 +46,74 @@ export function hierarchyEdgeLabels(edges: readonly GraphEdge[]): HierarchyEdgeL
const pair = pairs.get(key) ?? { source: edge.source, target: edge.target, types: new Set<string>() };
pair.types.add(edge.type); pairs.set(key, pair);
}
- return [...pairs].map(([key, pair]) => ({ key, source: pair.source, target: pair.target,
+ const labels = [...pairs].map(([key, pair]) => ({ key, source: pair.source, target: pair.target,
text: [...pair.types].sort((x, y) => Number(y === 'CALLS') - Number(x === 'CALLS') || x.localeCompare(y)).join(' · ') }));
+ if (!layout) return labels;
+ const placed: { hop: number; order: number; label: HierarchyEdgeLabel }[] = [];
+ type Member = { label: HierarchyEdgeLabel; order: number; hop: number; nearId: number; farId: number; near: HierarchySpot; far: HierarchySpot };
+ const outer: Member[] = [];
+ labels.forEach((label, order) => {
+ const a = layout.get(label.source), b = layout.get(label.target);
+ if (!a || !b || a.hop === b.hop) { placed.push({ hop: a?.hop ?? Number.MAX_SAFE_INTEGER, order, label }); return; }
+ const [nearId, farId, near, far] = a.hop < b.hop ? [label.source, label.target, a, b] : [label.target, label.source, b, a];
+ if (near.hop === 0) { placed.push({ hop: 0, order, label }); return; }
+ outer.push({ label, order, hop: near.hop, nearId, farId, near, far });
+ });
+ // Erst die Faecher, die von einem Knoten ausgehen, dann die, die auf einen Knoten zulaufen.
+ const gather = (members: Member[], keyOf: (member: Member) => string, yOf: (member: Member) => number, last: boolean): Member[] => {
+ const fans = new Map<string, Member[]>();
+ for (const member of members) fans.set(keyOf(member), [...fans.get(keyOf(member)) ?? [], member]);
+ const single: Member[] = [];
+ for (const [key, fan] of fans) {
+ if (fan.length === 1 && !last) { single.push(fan[0]!); continue; }
+ const middle = [...fan].sort((x, y) => yOf(y) - yOf(x))[Math.floor((fan.length - 1) / 2)]!.label;
+ placed.push({ hop: fan[0]!.hop, order: fan[0]!.order, label: fan.length === 1 ? middle
+ : { ...middle, key: `fan:${key}`, text: `${middle.text} ×${fan.length}` } });
+ }
+ return single;
+ };
+ const single = gather(outer, member => `${member.nearId}|${member.label.text}|${Math.sign(member.far.x - member.near.x)}`, member => member.far.y, false);
+ gather(single, member => `in:${member.farId}|${member.label.text}|${Math.sign(member.near.x - member.far.x)}`, member => member.near.y, true);
+ return placed.sort((x, y) => x.hop - y.hop || x.order - y.order).map(entry => entry.label);
}
const PLACE_EVERY_FRAMES = 3;
-export function HierarchyEdgeLabels({ nodes, edges, nameBoxes }: {
+/*
+ * Ein Schild nur dort, wo die Namen zu lesen sind (Review zu K5, im Browser
+ * gesehen): bei zwei Ebenen standen die Namen im eingepassten Bild bei rund
+ * 5 px, und siebzig Schilder in festen 10 px deckten es zu. Darunter traegt die
+ * Farbe der Linie die Art, wie in der Legende; wer hineinzoomt, bekommt die
+ * Schilder an den Linien, die er sieht.
+ */
+export const EDGE_LABEL_MIN_NAME_PIXELS = 9;
+
+/** Ein freier Platz fuer ein Schild der Hierarchie, sonst keiner: hier liegt kein Schild auf einem Namen, die Farbe der Linie sagt die Art auch. */
+export function hierarchyLabelSpot(from: { x: number; y: number }, to: { x: number; y: number }, size: { width: number; height: number },
+ blockers: readonly ScreenRect[], placed: readonly ScreenRect[]): { t: number; rect: ScreenRect } | undefined {
+ const choice = placeAlongSegment(from, to, size, blockers, placed);
+ return choice.overlap > 0 ? undefined : choice;
+}
+export function edgeLabelVisible(namePixels: number, at: { x: number; y: number }, canvas: ScreenRect): boolean {
+ return namePixels >= EDGE_LABEL_MIN_NAME_PIXELS && at.x >= canvas.left && at.x <= canvas.right && at.y >= canvas.top && at.y <= canvas.bottom;
+}
+
+export function HierarchyEdgeLabels({ nodes, edges, layout, nameBoxes }: {
nodes: readonly GraphNode[];
edges: readonly GraphEdge[];
+ /** Ebene und Lage je Knoten: fasst die Faecher draussen zusammen (siehe `hierarchyEdgeLabels`). */
+ layout?: ReadonlyMap<number, HierarchySpot>;
/** Die gezeichneten Namen, in Weltkoordinaten (NodeLabels). */
nameBoxes: RefObject<LabelBox[]>;
}) {
const byId = useMemo(() => new Map(nodes.map((node) => [node.id, node])), [nodes]);
- const labels = useMemo(() => hierarchyEdgeLabels(edges).flatMap((label) => {
+ const labels = useMemo(() => hierarchyEdgeLabels(edges, layout).flatMap((label) => {
const from = byId.get(label.source), to = byId.get(label.target);
return from && to ? [{ ...label, from, to }] : [];
- }).slice(0, HIERARCHY_EDGE_LABEL_BUDGET), [edges, byId]);
+ }).slice(0, HIERARCHY_EDGE_LABEL_BUDGET), [edges, layout, byId]);
const groups = useRef(new Map<string, THREE.Group>());
const elements = useRef(new Map<string, HTMLElement>());
+ const sizes = useRef(new Map<string, { width: number; height: number }>());
const camera = useThree((state) => state.camera);
const gl = useThree((state) => state.gl);
const tick = useRef(0);
@@ -69,11 +132,26 @@ export function HierarchyEdgeLabels({ nodes, edges, nameBoxes }: {
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) };
});
const placed: ScreenRect[] = [];
+ // So hoch steht ein Name auf dem Schirm: die Schriftgroesse der Hierarchie, durch dieselbe Kamera.
+ const anchor = labels[0]?.from;
+ const namePixels = anchor ? Math.abs(toScreen(anchor.x, anchor.y + HIERARCHY_LABEL_FONT_SIZE, anchor.z).y - toScreen(anchor.x, anchor.y, anchor.z).y) : 0;
+ const canvas = { left: box.left, top: box.top, right: box.right, bottom: box.bottom };
for (const { key, from, to } of labels) {
const group = groups.current.get(key), element = elements.current.get(key);
- if (!group || !element || element.offsetWidth === 0) continue;
+ if (!group || !element) continue;
const a = toScreen(from.x, from.y, from.z), b = toScreen(to.x, to.y, to.z);
- const choice = placeAlongSegment(a, b, { width: element.offsetWidth, height: element.offsetHeight }, blockers, placed);
+ // Die Groesse eines Schildes einmal messen: Schreiben und Lesen im Wechsel hiesse ein Layout je Schild und Durchgang.
+ let size = sizes.current.get(key);
+ if (!size) {
+ element.style.display = '';
+ size = { width: element.offsetWidth, height: element.offsetHeight };
+ if (size.width > 0) sizes.current.set(key, size);
+ }
+ const choice = size.width > 0 && edgeLabelVisible(namePixels, { x: (a.x + b.x) / 2, y: (a.y + b.y) / 2 }, canvas)
+ ? hierarchyLabelSpot(a, b, size, blockers, placed) : undefined;
+ const display = choice ? '' : 'none';
+ if (element.style.display !== display) element.style.display = display;
+ if (!choice) continue;
placed.push(choice.rect);
group.position.lerpVectors(ends.from.set(from.x, from.y, from.z), ends.to.set(to.x, to.y, to.z), choice.t);
const onEdge = { x: a.x + (b.x - a.x) * choice.t, y: a.y + (b.y - a.y) * choice.t };
diff --git a/graph-ui/src/galaxy/galaxy-strings.ts b/graph-ui/src/galaxy/galaxy-strings.ts
index 124f7500f..0b4c258aa 100644
--- a/graph-ui/src/galaxy/galaxy-strings.ts
+++ b/graph-ui/src/galaxy/galaxy-strings.ts
@@ -64,11 +64,14 @@ export const galaxyHistoryText = {
/** The hierarchy of a Galaxy scope (hand test K5): what the columns mean, per trace direction. */
export const galaxyHierarchyText = {
- hint: (direction: 'both' | 'inbound' | 'outbound') => direction === 'inbound'
- ? 'hierarchy: what reaches the root, one column per layer to the left; edge types at the lines'
+ /** With `namesUpTo` the scope is past the name budget: no names and no edge labels, and the hint says how to get them back. */
+ hint: (direction: 'both' | 'inbound' | 'outbound', namesUpTo?: number) => (direction === 'inbound'
+ ? 'hierarchy: what reaches the root, one column per layer to the left'
: direction === 'outbound'
- ? 'hierarchy: what the root reaches, one column per layer to the right; edge types at the lines'
- : 'hierarchy: incoming relationships on the left, the root in the middle, outgoing on the right; one column per layer, edge types at the lines',
+ ? 'hierarchy: what the root reaches, one column per layer to the right'
+ : 'hierarchy: incoming relationships on the left, the root in the middle, outgoing on the right; one column per layer')
+ + (namesUpTo === undefined ? ', edge types at the lines'
+ : `; names and edge types show for up to ${namesUpTo.toLocaleString()} nodes, so remove a layer or trace fewer edge types to see them`),
};
const count = (value: number, one: string, many: string) => `${value.toLocaleString()} ${value === 1 ? one : many}`;
diff --git a/graph-ui/src/galaxy/graph-scope.ts b/graph-ui/src/galaxy/graph-scope.ts
index 227a2d828..9e18ee121 100644
--- a/graph-ui/src/galaxy/graph-scope.ts
+++ b/graph-ui/src/galaxy/graph-scope.ts
@@ -313,8 +313,11 @@ export const SCOPED_HIERARCHY_LEVEL_GAP = 160;
export const SCOPED_HIERARCHY_ROW_GAP = 32;
/** Texture width of a hierarchy name in a scope: about forty characters before an ellipsis. */
export const SCOPED_HIERARCHY_LABEL_MAX_TEXT_WIDTH = 1600;
-/** Up to this many nodes every name is drawn, and columns stay single columns; above it they wrap into grids. */
-export const SCOPED_HIERARCHY_LABEL_BUDGET = 60;
+/**
+ * Up to this many nodes every name is drawn, and columns stay single columns; above it they wrap into grids,
+ * without names or edge labels. Sixty left JSONBAgg at two layers (90 nodes) without a single name (review of K5).
+ */
+export const SCOPED_HIERARCHY_LABEL_BUDGET = 150;
const SCOPED_HIERARCHY_WRAP_AT = 12;
const LABEL_UNITS_PER_CHAR = 7.1, LABEL_UNITS_PADDING = 12, LABEL_GUTTER = 40;
const LABEL_MAX_CHARS = Math.floor((SCOPED_HIERARCHY_LABEL_MAX_TEXT_WIDTH - 64) / 38);
diff --git a/graph-ui/src/galaxy/hierarchy-edge-labels.test.ts b/graph-ui/src/galaxy/hierarchy-edge-labels.test.ts
index 1297c7fd0..bdc917766 100644
--- a/graph-ui/src/galaxy/hierarchy-edge-labels.test.ts
+++ b/graph-ui/src/galaxy/hierarchy-edge-labels.test.ts
@@ -1,5 +1,5 @@
import { expect, it } from 'vitest';
-import { hierarchyEdgeLabels } from './HierarchyEdgeLabels';
+import { EDGE_LABEL_MIN_NAME_PIXELS, edgeLabelVisible, hierarchyEdgeLabels, hierarchyLabelSpot } from './HierarchyEdgeLabels';
it('hand test K5: writes one label per node pair, its types without repeats and CALLS first', () => {
const labels = hierarchyEdgeLabels([
@@ -9,3 +9,58 @@ it('hand test K5: writes one label per node pair, its types without repeats and
]);
expect(labels.map(label => [label.key, label.text])).toEqual([['1:10', 'CALLS · TESTS'], ['1:30', 'DEFINES'], ['1:40', 'INHERITS · USAGE']]);
});
+
+/*
+ * Review of K5: at two layers (JSONBAgg, 90 nodes) eighty labels stood on the
+ * first eighty pairs in edge order, rows of "DEFINES" without a name in sight.
+ * The lines at the root keep a label each; a fan further out, one node to many
+ * of the same types, carries one label with its count on its middle line.
+ */
+it('labels every line at the root, and a fan further out once with its count, nearest the root first', () => {
+ const at = (hop: number, x: number, y: number) => ({ hop, x, y });
+ const layout = new Map([[1, at(0, 0, 0)], [10, at(1, -200, 32)], [11, at(1, -200, 0)], [30, at(1, -200, -32)],
+ [50, at(2, -400, 32)], [51, at(2, -400, 0)], [52, at(2, -400, -32)], [60, at(2, -400, 64)]]);
+ const labels = hierarchyEdgeLabels([
+ { source: 30, target: 52, type: 'DEFINES' }, { source: 30, target: 50, type: 'DEFINES' }, { source: 10, target: 60, type: 'CALLS' },
+ { source: 10, target: 1, type: 'CALLS' }, { source: 11, target: 1, type: 'CALLS' }, { source: 30, target: 1, type: 'DEFINES' },
+ { source: 30, target: 51, type: 'DEFINES' }, { source: 50, target: 51, type: 'CALLS' },
+ ], layout);
+ expect(labels.map(label => [label.text, label.source, label.target])).toEqual([
+ ['CALLS', 10, 1], ['CALLS', 11, 1], ['DEFINES', 30, 1],
+ ['DEFINES ×3', 30, 51], ['CALLS', 10, 60], ['CALLS', 50, 51],
+ ]);
+});
+
+/*
+ * Review of K5, seen in the browser: at two layers the fitted picture drew the
+ * names at about 5 px, and seventy edge labels at a fixed 10 px covered it.
+ * An edge label stands beside a name only where the names can be read, and
+ * only on the lines in view.
+ */
+it('shows an edge label only while the names read and its line is in view', () => {
+ const canvas = { left: 0, top: 0, right: 1600, bottom: 900 };
+ expect(EDGE_LABEL_MIN_NAME_PIXELS).toBeGreaterThanOrEqual(8);
+ expect(edgeLabelVisible(12, { x: 800, y: 450 }, canvas)).toBe(true);
+ expect(edgeLabelVisible(5, { x: 800, y: 450 }, canvas)).toBe(false);
+ expect(edgeLabelVisible(12, { x: -40, y: 450 }, canvas)).toBe(false);
+ expect(edgeLabelVisible(12, { x: 800, y: 960 }, canvas)).toBe(false);
+});
+
+it('gathers lines that converge further out on one node too, when they leave no fan of their own', () => {
+ const at = (hop: number, x: number, y: number) => ({ hop, x, y });
+ const layout = new Map([[1, at(0, 0, 0)], [10, at(1, -200, 32)], [11, at(1, -200, 0)], [12, at(1, -200, -32)], [70, at(2, -400, 0)], [71, at(2, -400, 32)]]);
+ const labels = hierarchyEdgeLabels([
+ { source: 10, target: 70, type: 'WRITES' }, { source: 11, target: 70, type: 'WRITES' }, { source: 12, target: 70, type: 'WRITES' },
+ { source: 12, target: 71, type: 'CALLS' },
+ ], layout);
+ expect(labels.map(label => [label.text, label.source, label.target])).toEqual([['WRITES ×3', 11, 70], ['CALLS', 12, 71]]);
+});
+
+it('drops a hierarchy edge label that finds no free place instead of laying it over a name', () => {
+ const name = { left: 90, right: 210, top: 90, bottom: 110 };
+ // A short edge whose whole neighbourhood is a name: no spot without overlap.
+ expect(hierarchyLabelSpot({ x: 100, y: 100 }, { x: 200, y: 100 }, { width: 60, height: 14 }, [{ left: 0, right: 400, top: 0, bottom: 200 }], [])).toBeUndefined();
+ const spot = hierarchyLabelSpot({ x: 100, y: 100 }, { x: 400, y: 100 }, { width: 60, height: 14 }, [name], []);
+ expect(spot).toBeDefined();
+ expect(spot!.rect.left >= name.right || spot!.rect.bottom <= name.top || spot!.rect.top >= name.bottom).toBe(true);
+});
diff --git a/graph-ui/tools/handtest-fixes-galaxy.mjs b/graph-ui/tools/handtest-fixes-galaxy.mjs
index 579eb2304..b069b7824 100644
--- a/graph-ui/tools/handtest-fixes-galaxy.mjs
+++ b/graph-ui/tools/handtest-fixes-galaxy.mjs
@@ -15,6 +15,13 @@
*
* Es startet keinen Server. Gebraucht wird ein Ursprung mit UI und /rpc, etwa
* tools/lib/static-proxy.mjs vor einem laufenden Server.
+ *
+ * Nach dem Review der Korrekturen kamen dazu: die Auswahl bleibt bei Zurueck
+ * auf dieselbe Wurzel und beim Abbruch (K2/K8), die Leiste passt auch bei
+ * 1.494, 1.440, 1.366 und 1.280 px mit offenem Chat, ohne etwas abzuschneiden
+ * (K3), die Hierarchie bei zwei Ebenen traegt Namen (K5), das Laden zaehlt
+ * Seite fuer Seite und warnt vorher (K8), und der Quelltext nennt die echte
+ * letzte Zeile (K13).
*/
import { chromium } from 'playwright';
@@ -238,6 +245,8 @@ async function checkK2(page) {
await check('K2', 'Back and Forward buttons exist in the scoped toolbar', false, { steps });
return;
}
+ const a11y = await page.evaluate(() => ({ group: document.querySelector('.atlas-graph-history')?.getAttribute('aria-label') ?? null,
+ rootButton: document.querySelector('button.atlas-graph-scope-name')?.getAttribute('aria-label') ?? null }));
const t0 = Date.now();
await backButton.click();
await shot(page, 'K2', 'back-0ms', '0 ms after Back');
@@ -248,7 +257,10 @@ async function checkK2(page) {
await shot(page, 'K2', 'back-1', `After Back: ${ROOT} at 2 layers again, Forward names the test`);
await backButton.click();
await settled(page);
- steps.push({ step: 'Back', ...await state() });
+ // Review: Back to the same root at another depth keeps the selection and its details.
+ const sameRoot = { ...await state(), details: await page.locator('.atlas-galaxy-selection-details').count() };
+ steps.push({ step: 'Back (same root, 1 layer)', ...sameRoot });
+ await shot(page, 'K2', 'back-same-root', `Back to ${ROOT} at 1 layer: Selection details still there (${sameRoot.details})`);
await backButton.click();
await wait(1500);
steps.push({ step: 'Back', ...await state() });
@@ -287,6 +299,9 @@ async function checkK2(page) {
await settled(page);
steps.push({ step: `Back until disabled (${backs} steps)`, ...await state() });
const at = (index) => steps[index] ?? {};
+ await check('K2', 'Back to the same root at another depth keeps the selection; the history group and the root button are named for assistive technology',
+ sameRoot.scope === ROOT && sameRoot.layers === '1 layer' && sameRoot.details === 1 && a11y.group === 'History'
+ && a11y.rootButton === 'Open the source of test_jsonb_agg_jsonfield_order_by', { sameRoot, a11y });
const pass = at(0).back?.startsWith('Back to All graph') && at(2).back?.startsWith(`Back to ${ROOT} · 2 layers`)
&& at(3).scope === ROOT && at(3).layers === '2 layers' && at(3).forward?.startsWith('Forward to test_jsonb_agg_jsonfield_order_by')
&& at(4).layers === '1 layer' && at(5).scope === '' && at(5).backDisabled === true && at(6).scope === ROOT
@@ -313,7 +328,14 @@ async function checkK8(page) {
await shot(page, 'K8', 'two-layers', `${ROOT} at 2 layers: ${await countText(page)}`);
const minus = page.getByRole('button', { name: 'Remove graph layer' });
const expandButton = page.getByRole('button', { name: 'Expand +1' });
+ // Review: the counted calls at the edge reach the toolbar a moment after the layer is complete.
+ await page.waitForFunction(() => /The index lists/.test([...document.querySelectorAll('.atlas-graph-exploration button')]
+ .find((el) => el.getAttribute('aria-label') === 'Expand +1')?.title ?? ''), null, { timeout: 10000 }).catch(() => {});
const expandTitle = await expandButton.getAttribute('title');
+ const expandWarning = await expandButton.getAttribute('data-warning');
+ await check('K8', 'Before layer 3 loads, Expand warns: the index counts the calls waiting at the edge nodes',
+ expandWarning === 'true' && /^Likely past the render limit\. Load layer 3: \d+ nodes to expand\. The index lists [\d.,]+ calls at them/.test(expandTitle ?? ''),
+ { expandTitle, expandWarning });
// 1. Abbrechen waehrend die dritte Ebene laedt.
await expandButton.click();
@@ -332,8 +354,9 @@ async function checkK8(page) {
await wait(750);
const cancelled = { layers: await layerText(page), status: await countText(page), state: await scopeState(page), ms: cancelMs };
await shot(page, 'K8', 'cancel-1s', `1 s after "−": ${cancelled.layers}, ${cancelled.status}`);
- await check('K8', '"−" cancels a running layer and returns to the previous one within 1 s', during.state === 'loading' && during.minusDisabled === false
- && cancelMs <= 1000 && cancelled.layers === '2 layers' && /^90 nodes · 201 edges/.test(cancelled.status), { expandTitle, during, cancelled });
+ cancelled.details = await page.locator('.atlas-galaxy-selection-details').count();
+ await check('K8', '"−" cancels a running layer and returns to the previous one within 1 s, and the selection stays', during.state === 'loading' && during.minusDisabled === false
+ && cancelMs <= 1000 && cancelled.layers === '2 layers' && /^90 nodes · 201 edges/.test(cancelled.status) && cancelled.details === 1, { expandTitle, during, cancelled });
// 2. Die dritte Ebene ganz laden.
await wait(1500);
@@ -341,12 +364,15 @@ async function checkK8(page) {
const w0 = Date.now();
await expandButton.click();
const frames = [];
- for (const [label, at] of [['0ms', 0], ['250ms', 250], ['1s', 1000], ['3s', 3000]]) {
+ for (const [label, at] of [['0ms', 0], ['250ms', 250], ['1s', 1000], ['2s', 2000], ['3s', 3000]]) {
const elapsed = Date.now() - w0;
if (at > elapsed) await wait(at - elapsed);
- frames.push({ at: label, status: await countText(page), state: await scopeState(page), progress: await progressShown(page) });
+ frames.push({ at: label, status: await countText(page), state: await scopeState(page), progress: await progressShown(page),
+ title: await page.locator('.atlas-graph-scope-count').first().getAttribute('title').catch(() => null) });
await shot(page, 'K8', `layer3-${label}`, `${label} after Expand: "${frames.at(-1).status}"${frames.at(-1).progress ? `, overlay "${frames.at(-1).progress}"` : ''}`);
}
+ // Review: the counts move page by page instead of standing still for a whole batch.
+ const loadingStatuses = [...new Set(frames.filter((frame) => frame.state === 'loading').map((frame) => frame.status))];
await page.waitForFunction(() => ['complete', 'partial'].includes(document.querySelector('.atlas-graph-scope-count')?.getAttribute('data-state') ?? ''), null, { timeout: 180000 }).catch(() => {});
const doneMs = Date.now() - w0;
const calls = await rpcSince(page, t0);
@@ -362,6 +388,9 @@ async function checkK8(page) {
await check('K8', 'Layer 3 completes (or stops at the render limit with a partial note) within 30 s in few large requests, and the overlay goes away',
['complete', 'partial'].includes(done.state ?? '') && doneMs <= 30000 && done.queryGraph <= 40 && done.overlayAfter2s === '' && done.layers === '3 layers',
{ frames, done });
+ const doneRequests = frames.filter((frame) => /Request \d+ to the index/.test(frame.title ?? '')).length;
+ await check('K8', 'While layer 3 loads, the counts move page by page and the tooltip names the running request',
+ doneMs <= 3000 || (loadingStatuses.length >= 2 && doneRequests >= 1), { loadingStatuses, doneMs, titles: frames.map((frame) => frame.title) });
}
/* ------------------------------------------------------------------ */
@@ -377,7 +406,12 @@ async function toolbarRows(page) {
const rows = [...new Set(centres.map((centre) => Math.round(centre / 16)))].length;
const clipped = items.filter((el) => el.scrollWidth > el.clientWidth + 1 && getComputedStyle(el).textOverflow === 'ellipsis')
.map((el) => el.textContent?.trim().slice(0, 40));
- return { width: Math.round(box.width), height: Math.round(box.height), rows, overflow: bar.scrollWidth > bar.clientWidth + 1, clipped,
+ const style = getComputedStyle(bar);
+ const edge = box.right - parseFloat(style.paddingRight) - parseFloat(style.borderRightWidth);
+ const outside = items.filter((el) => el.getBoundingClientRect().right > edge + 0.5).map((el) => (el.getAttribute('aria-label') || el.textContent || el.tagName).trim().slice(0, 24));
+ const more = bar.querySelector('details.atlas-graph-more > summary')?.getBoundingClientRect();
+ return { width: Math.round(box.width), height: Math.round(box.height), rows, overflow: bar.scrollWidth > bar.clientWidth + 1, clipped, fit: bar.dataset.fit ?? null,
+ outside, moreInside: Boolean(more && more.width > 0 && more.right <= edge + 0.5 && more.left >= box.left),
items: items.map((el) => `${(el.getAttribute('aria-label') || el.textContent || el.tagName).trim().slice(0, 18)}:${Math.round(el.getBoundingClientRect().width)}`) };
});
}
@@ -419,8 +453,43 @@ async function checkK3(page) {
await measure('open-partial', 'Chat open, layer 3 stopped at the render limit');
await chatToggle(false);
await measure('closed-partial', 'Chat closed again, layer 3 partial');
- const pass = rows.length === 7 && rows.every((row) => row.rows === 1 && row.height < 60 && !row.overflow);
+ const pass = rows.length === 7 && rows.every((row) => row.rows === 1 && row.height < 60 && !row.overflow && row.outside.length === 0);
await check('K3', 'One toolbar row in every state, chat open (bar about 1170 px) and closed (1600 px)', pass, { rows });
+
+ /*
+ * Review: bei 1.494 px (das Fenster des Handtests) und darunter schnitt die
+ * Leiste Zaehler und Menue "⋯" ab. Jetzt passt sie ohne Abschneiden: eine
+ * Zeile bis 1.440 px, darunter zwei, und das Menue mit den Limits oeffnet.
+ */
+ await chatToggle(true);
+ const narrow = [];
+ const atWidth = async (width, state) => {
+ await page.setViewportSize({ width, height: VIEWPORT.height });
+ await wait(900);
+ const value = await toolbarRows(page);
+ const more = page.locator('details.atlas-graph-more').first();
+ await more.locator('> summary').click({ timeout: 3000 }).catch(() => {});
+ await wait(300);
+ const limitsVisible = await page.getByRole('combobox', { name: 'Rendered node limit' }).first().isVisible().catch(() => false);
+ const label = `${state}-${width}`;
+ await shot(page, 'K3', label, `Chat open at ${width} px, ${state}: fit "${value?.fit}", ${value?.rows} row(s), ${value?.outside.length} item(s) past the edge, ⋯ menu open with Limits ${limitsVisible ? 'visible' : 'missing'}`);
+ await page.keyboard.press('Escape');
+ await more.evaluate((el) => { el.open = false; }).catch(() => {});
+ await page.locator('.atlas-graph-exploration').first().screenshot({ path: join(OUT, 'K3', `${label}-toolbar.png`) }).catch(() => {});
+ narrow.push({ label, width, ...value, limitsVisible });
+ };
+ for (const width of [1494, 1440, 1366, 1280]) await atWidth(width, 'partial');
+ await page.setViewportSize(VIEWPORT);
+ await wait(600);
+ if (await back.count()) await back.click();
+ await settled(page);
+ for (const width of [1494, 1440, 1366, 1280]) await atWidth(width, 'two-layers');
+ await page.setViewportSize(VIEWPORT);
+ await wait(600);
+ const narrowPass = narrow.length === 8 && narrow.every((row) => row.outside.length === 0 && !row.overflow && row.moreInside && row.limitsVisible
+ && (row.width >= 1440 ? row.rows === 1 && row.height < 60 : row.rows <= 2));
+ await check('K3', 'With the chat open at 1494, 1440, 1366 and 1280 px nothing is cut off: one row down to 1440 px, two below, the ⋯ menu with Limits opens',
+ narrowPass, { narrow });
}
/* ------------------------------------------------------------------ */
@@ -475,8 +544,8 @@ async function checkK13(page) {
await page.locator('.source-evidence-lines').evaluate((el) => { el.scrollTop = el.scrollHeight; }).catch(() => {});
await wait(300);
await shot(page, 'K13', 'source-evidence-end', `Source evidence for general.py scrolled to the end: "${pagerText.replace(/\s+/g, ' ')}"`);
- await check('K13', '"Next lines" is disabled at the real end of general.py and says so', /end of file/.test(pagerText) && nextState.disabled === true
- && /end of this file/.test(nextState.title ?? ''), { pagerText, nextState, renderedLines: lines });
+ await check('K13', '"Next lines" is disabled at the real end of general.py and names its last line, 65', /end of file/.test(pagerText) && nextState.disabled === true
+ && nextState.title === 'Line 65 is the last line of this file.', { pagerText, nextState, renderedLines: lines });
await page.keyboard.press('Escape');
}
@@ -637,6 +706,35 @@ async function checkK5(page) {
&& JSON.stringify(columnOrder) === JSON.stringify(firstSeen) && callView.overlaps.length === 0,
{ callees, columnOrder, firstSeen, overlaps: callView.overlaps, truncated: callView.truncated });
await page.keyboard.press('Escape');
+ await wait(500);
+
+ /*
+ * Review: bei zwei Ebenen (90 Knoten) stand kein einziger Name, aber achtzig
+ * Kantenschilder auf beliebigen Paaren. Jetzt tragen bis 150 Knoten alle
+ * ihren Namen, und draussen hat ein Faecher ein Schild mit seiner Zahl.
+ */
+ await select(page, ROOT);
+ await settled(page);
+ if (await page.locator('[data-testid="atlas-graph-mode-chip"][data-mode="hierarchy"][data-active="true"]').count() === 0) {
+ await page.locator('[data-testid="atlas-graph-mode-chip"][data-mode="hierarchy"]').click();
+ }
+ await expand(page);
+ await wait(3000);
+ const twoLayers = await hierarchyLayout(page);
+ const count = await countText(page);
+ await shot(page, 'K5', 'hierarchy-two-layers', `${ROOT} at 2 layers in hierarchy, fitted (${count}): ${twoLayers.names} names, ${twoLayers.edgeLabels.length} edge labels shown, ${twoLayers.overlaps.length} overlaps`);
+ // Hineinzoomen auf die linken Spalten: dort werden die Namen lesbar, und erst dann stehen die Kantenschilder.
+ const box = await canvasBox(page);
+ await page.mouse.move(box.x + box.width * 0.42, box.y + box.height * 0.55);
+ for (let step = 0; step < 6; step += 1) { await page.mouse.wheel(0, -300); await wait(200); }
+ await wait(2000);
+ const zoomed = await hierarchyLayout(page);
+ await shot(page, 'K5', 'hierarchy-two-layers-zoomed', `Zoomed in at 2 layers: names read in full, ${zoomed.edgeLabels.length} edge labels on the lines in view, ${zoomed.overlaps.length} overlaps`);
+ await check('K5', 'At 2 layers (90 nodes) the hierarchy draws every name; edge labels wait until the names read and then sit clear of them',
+ /^90 nodes/.test(count) && twoLayers.names >= 85 && twoLayers.overlaps.length === 0 && twoLayers.truncated.length === 0
+ && zoomed.edgeLabels.length > 0 && zoomed.overlaps.length === 0 && /edge types at the lines/.test(twoLayers.hint),
+ { count, fitted: { names: twoLayers.names, edgeLabels: twoLayers.edgeLabels, overlaps: twoLayers.overlaps },
+ zoomed: { names: zoomed.names, edgeLabels: zoomed.edgeLabels, overlaps: zoomed.overlaps }, truncated: twoLayers.truncated, hint: twoLayers.hint });
}
/* ------------------------------------------------------------------ */