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): frame the next scope picture along the kept view direction

Bernhard Jackiewiczef6725570f11
diff --git a/graph-ui/src/galaxy/GalaxyPanel.tsx b/graph-ui/src/galaxy/GalaxyPanel.tsx
index db44174c8..afe25f54f 100644
--- a/graph-ui/src/galaxy/GalaxyPanel.tsx
+++ b/graph-ui/src/galaxy/GalaxyPanel.tsx
@@ -769,12 +769,10 @@ export default function GalaxyPanel(props: GalaxyPanelProps): JSX.Element {
}, [scope.result, scope.scope, organicKey, scope.depth]);
const organicTask = useOrganicLayout(scope.scope ? scope.result?.data : undefined, organicOptions);
const organic = organicTask.result;
- // Jedes gezeichnete Bild desselben Scopes haelt seine Punkte fest, auch die
- // Vorschau: sonst springt die Wolke beim Wechsel zur vollstaendigen Antwort.
useEffect(() => {
- if (organic) organicHistory.current = { key: organicKey, depth: scope.result?.depth ?? scope.depth, data: organic.data };
+ if (scope.complete && organic) organicHistory.current = { key: organicKey, depth: scope.depth, data: organic.data };
if (!scope.scope) organicHistory.current = undefined;
- }, [scope.scope, scope.result, organic, organicKey, scope.depth]);
+ }, [scope.complete, scope.scope, organic, organicKey, scope.depth]);
const data = scope.scope ? organic?.data : layout;
/*
* Was die Szene zeigt, solange das naechste Bild noch angeordnet wird.
@@ -1462,8 +1460,9 @@ export default function GalaxyPanel(props: GalaxyPanelProps): JSX.Element {
* Kantenarten) und nicht sein Bild: ein Expand, eine Vorschau und die
* vollstaendige Antwort danach sind derselbe Ausschnitt, und eine Kamera,
* die bei jedem davon neu einpasst, stellt den Leser jedes Mal anders hin
- * (Review-Befund G1). Was dabei neu hinzukommt, holt die Szene selbst ins
- * Bild, solange der Leser die Kamera nicht bewegt hat (GraphScene,
+ * (Review-Befund G1). Wie weit die Kamera fuer das neue Bild stehen muss,
+ * stellt die Szene selbst nach, entlang derselben Blickrichtung und nur,
+ * solange der Leser die Kamera nicht bewegt hat (GraphScene,
* `FitContainment`).
*/
const fitScope = mode === 'galaxy' && props.workspaceExpanded && scope.scope ? organicKey : undefined;
diff --git a/graph-ui/src/galaxy/GraphScene.camera.test.tsx b/graph-ui/src/galaxy/GraphScene.camera.test.tsx
index e274ec68c..8d48a2c11 100644
--- a/graph-ui/src/galaxy/GraphScene.camera.test.tsx
+++ b/graph-ui/src/galaxy/GraphScene.camera.test.tsx
@@ -5,6 +5,7 @@ import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
import { PerspectiveCamera, Vector3 } from 'three';
import type { OrbitControls as OrbitControlsImpl } from 'three-stdlib';
import { CameraAnimator, FitContainment, type CameraTarget } from './GraphScene';
+import { FRAME_MARGIN, FRAME_MIN_DISTANCE } from './camera-frame';
import type { GraphNode } from './types';
const fiber = vi.hoisted(() => ({ frames: [] as ((state: unknown, delta: number) => void)[] }));
@@ -52,29 +53,35 @@ describe('FitContainment', () => {
const render = (nodes: GraphNode[], target: CameraTarget | null) => act(() => root.render(
<FitContainment nodes={nodes} target={target} controlsRef={controlsRef} moved={moved} enabled />));
- it('steps back along the view direction after a fit until added nodes are inside, keeping the direction', () => {
+ const half = Math.tan(25 * Math.PI / 180);
+ /** How much of the half-height the outermost node uses, margin included. */
+ const reach = (y: number) => y * FRAME_MARGIN / (scene.camera.position.z * half);
+
+ it('frames the next picture along the kept view direction: back for a larger one, forward for a smaller one', () => {
moved.current = false;
const fit = fitTo(800);
- scene.camera.position.copy(fit.position);
- render([node(1, 0, 0)], fit);
- expect(scene.camera.position.z).toBe(800);
render([node(1, 0, 0), node(2, 0, 900)], fit);
expect(scene.camera.position.x).toBe(0); expect(scene.camera.position.y).toBe(0);
expect(scene.camera.position.z).toBeGreaterThan(800);
- const half = Math.tan(25 * Math.PI / 180);
- expect(900 / (scene.camera.position.z * half)).toBeLessThan(1);
+ expect(reach(900)).toBeCloseTo(1, 4);
+ render([node(1, 0, 0), node(2, 0, 300)], fit);
+ expect(reach(300)).toBeCloseTo(1, 4);
+ // Never closer to the pivot than any fit would stand.
+ render([node(1, 0, 0)], fit);
+ expect(scene.camera.position.z).toBeCloseTo(FRAME_MIN_DISTANCE, 6);
});
it('leaves the camera alone after the reader moved it or after a fly-to', () => {
moved.current = false;
const fit = fitTo(800);
- render([node(1, 0, 0)], fit);
+ render([node(1, 0, 0), node(2, 0, 300)], fit);
+ const framed = scene.camera.position.z;
moved.current = true;
render([node(1, 0, 0), node(2, 0, 900)], fit);
- expect(scene.camera.position.z).toBe(800);
+ expect(scene.camera.position.z).toBe(framed);
const fly = flyTo(0);
render([node(1, 0, 0), node(2, 0, 900)], fly);
render([node(1, 0, 0), node(2, 0, 1900)], fly);
- expect(scene.camera.position.z).toBe(800);
+ expect(scene.camera.position.z).toBe(framed);
});
});
diff --git a/graph-ui/src/galaxy/GraphScene.tsx b/graph-ui/src/galaxy/GraphScene.tsx
index d67fcdd2f..0167d9817 100644
--- a/graph-ui/src/galaxy/GraphScene.tsx
+++ b/graph-ui/src/galaxy/GraphScene.tsx
@@ -87,9 +87,9 @@
* 14. Neu (Review-Call 2026-10-02): CameraAnimator spielt einen Anflug, der
* schon vor dem Aufsetzen der Szene gesetzt war, nicht nach. Er gehoert
* zum Bild davor; eine Einpassung gilt weiter.
- * 15. Neu (Review-Call 2026-10-02): `FitContainment` holt Knoten, die nach
- * einer Einpassung dazukommen, ins Bild, indem die Kamera entlang ihrer
- * Blickrichtung zuruecktritt, solange der Leser sie nicht bewegt hat.
+ * 15. Neu (Review-Call 2026-10-02): `FitContainment` rahmt das naechste Bild
+ * eines Scopes, ohne neu einzupassen: die Kamera tritt entlang ihrer
+ * Blickrichtung zurueck oder vor, solange der Leser sie nicht bewegt hat.
* 16. Neu (Review-Call 2026-10-02): die OrbitControls zoomen zum Mauszeiger
* (`zoomToCursor`), nicht mehr in die Bildmitte.
*/
@@ -107,7 +107,7 @@ import { EdgeLines } from './EdgeLines';
import { NodeLabels } from './NodeLabels';
import { ScreenNodeSeparation } from './ScreenNodeSeparation';
import type { LabelBox } from './NodeLabels';
-import { containBackoff, fitCamera, flatBounds, frameDistance, orthographicZoom } from './camera-frame';
+import { FRAME_MIN_DISTANCE, containShift, fitCamera, flatBounds, frameDistance, orthographicZoom } from './camera-frame';
import type { CameraFit, FrameBox } from './camera-frame';
import { FRAME_WINDOW_MS, recordFrameWindow, recordSceneFacts } from './frame-rate';
import { springStep } from '../agents/agent-motion';
@@ -340,17 +340,18 @@ export function CameraAnimator({
}
/*
- * Aenderung 15: was nach einer Einpassung dazukommt, kommt ins Bild.
+ * Aenderung 15: das naechste Bild eines Scopes wird gerahmt, nicht eingepasst.
*
* Ein Expand und die vollstaendige Antwort nach einer Vorschau passen nicht
* neu ein (Review-Befund G1): eine neue Einpassung stellte die Kamera jedes
- * Mal anders hin. Die neuen Knoten liegen aber oft ausserhalb des alten
- * Rahmens, und die Trennung auf dem Schirm schiebt Knoten nach aussen. Also
- * tritt die Kamera entlang ihrer Blickrichtung genau so weit zurueck, dass
- * jeder gezeichnete Knoten mit Rand im Bild liegt (`containBackoff`). Richtung,
- * Oben und Drehpunkt bleiben. Das gilt nur, solange die letzte Lage eine
- * Einpassung war und der Leser die Kamera seitdem nicht bewegt hat: wer
- * hineingezoomt hat, wollte genau diesen Ausschnitt.
+ * Mal anders hin. Das neue Bild ist aber groesser oder kleiner als das alte,
+ * und die Trennung auf dem Schirm schiebt Knoten nach aussen. Also tritt die
+ * Kamera entlang ihrer Blickrichtung so weit zurueck oder vor, dass der
+ * aeusserste gezeichnete Knoten mit Rand am Bildrand steht (`containShift`).
+ * Richtung, Oben und Drehpunkt bleiben, und naeher als jede Einpassung
+ * (`FRAME_MIN_DISTANCE`) kommt sie dem Drehpunkt nicht. Das gilt nur, solange
+ * die letzte Lage eine Einpassung war und der Leser die Kamera seitdem nicht
+ * bewegt hat: wer gezoomt hat, wollte genau diesen Ausschnitt.
*/
export function FitContainment({
nodes,
@@ -368,30 +369,32 @@ export function FitContainment({
}): null {
const camera = useThree((state) => state.camera);
const size = useThree((state) => state.size);
- const armed = useRef(false);
+ const armed = useRef<CameraTarget | null>(null);
useEffect(() => {
if (target === null) {
return;
}
- armed.current = target.immediate === true;
+ armed.current = target.immediate === true ? target : null;
moved.current = false;
}, [target, moved]);
useEffect(() => {
- if (!enabled || !armed.current || moved.current || size.height <= 0
+ const fit = armed.current;
+ if (!enabled || fit === null || moved.current || nodes.length === 0 || size.height <= 0
|| !(camera instanceof THREE.PerspectiveCamera)) {
return;
}
camera.updateMatrixWorld();
const view = nodes.map((node) =>
new THREE.Vector3(node.x, node.y, node.z).applyMatrix4(camera.matrixWorldInverse));
- const back = containBackoff(view, camera.fov, size.width / size.height);
- if (!(back > 0.001)) {
+ const shift = Math.max(containShift(view, camera.fov, size.width / size.height),
+ FRAME_MIN_DISTANCE - camera.position.distanceTo(fit.lookAt));
+ if (!(Math.abs(shift) > 0.5)) {
return;
}
const direction = camera.getWorldDirection(new THREE.Vector3());
- camera.position.addScaledVector(direction, -back);
+ camera.position.addScaledVector(direction, -shift);
camera.updateMatrixWorld();
controlsRef.current?.update();
}, [nodes, enabled, camera, size, controlsRef, moved]);
diff --git a/graph-ui/src/galaxy/camera-frame.test.ts b/graph-ui/src/galaxy/camera-frame.test.ts
index af4fbbb3d..b7b08afde 100644
--- a/graph-ui/src/galaxy/camera-frame.test.ts
+++ b/graph-ui/src/galaxy/camera-frame.test.ts
@@ -15,7 +15,7 @@ import {
FLAT_MIN_ZOOM,
FRAME_MARGIN,
FRAME_MIN_DISTANCE,
- containBackoff,
+ containShift,
fitCamera,
flatBounds,
frameDistance,
@@ -333,37 +333,43 @@ describe('fitCamera', () => {
});
/*
- * Was nach einer Einpassung dazukommt (Review-Befund G1).
+ * Das naechste Bild desselben Scopes (Review-Befund G1).
*
- * Ein Expand passt nicht neu ein; die Kamera tritt nur so weit zurueck, dass
- * die neuen Knoten mit Rand ins Bild kommen. Gerechnet im Blickraum: vor der
- * Kamera ist z negativ.
+ * Ein Expand und die Antwort nach einer Vorschau passen nicht neu ein; die
+ * Kamera tritt entlang ihrer Blickrichtung nur so weit zurueck oder vor, dass
+ * der aeusserste Knoten mit Rand am Bildrand steht. Gerechnet im Blickraum:
+ * vor der Kamera ist z negativ.
*/
-describe('containBackoff', () => {
+describe('containShift', () => {
const ASPECT = 1.5;
const half = Math.tan((FOV * Math.PI) / 360);
- it('bleibt stehen, solange jeder Punkt mit Rand im Bild liegt', () => {
- const points = [{ x: 0, y: 0, z: -400 }, { x: 100, y: -80, z: -500 }];
- expect(containBackoff(points, FOV, ASPECT)).toBe(0);
- });
-
it('tritt genau so weit zurueck, dass der aeusserste Punkt am Rand steht', () => {
const point = { x: 0, y: 300, z: -200 };
- const back = containBackoff([point], FOV, ASPECT);
- const depth = 200 + back;
- expect((point.y * FRAME_MARGIN) / (depth * half)).toBeCloseTo(1, 6);
+ const back = containShift([point], FOV, ASPECT);
+ expect(back).toBeGreaterThan(0);
+ expect((point.y * FRAME_MARGIN) / ((200 + back) * half)).toBeCloseTo(1, 6);
+ });
+
+ it('tritt vor, wenn ein kleineres Bild mit viel Rand dasteht', () => {
+ const points = [{ x: 0, y: 0, z: -400 }, { x: 100, y: -80, z: -500 }];
+ const shift = containShift(points, FOV, ASPECT);
+ expect(shift).toBeLessThan(0);
+ const fills = points.map((point) => Math.max(
+ (Math.abs(point.x) * FRAME_MARGIN) / ((-point.z + shift) * half * ASPECT),
+ (Math.abs(point.y) * FRAME_MARGIN) / ((-point.z + shift) * half)));
+ expect(Math.max(...fills)).toBeCloseTo(1, 6);
});
it('rechnet die Breite mit dem Seitenverhaeltnis und holt auch Punkte hinter der Kamera', () => {
const wide = { x: 600, y: 0, z: -100 };
- const back = containBackoff([wide], FOV, ASPECT);
+ const back = containShift([wide], FOV, ASPECT);
expect((wide.x * FRAME_MARGIN) / ((100 + back) * half * ASPECT)).toBeCloseTo(1, 6);
- expect(containBackoff([{ x: 0, y: 0, z: 50 }], FOV, ASPECT)).toBeCloseTo(50, 6);
+ expect(containShift([{ x: 0, y: 0, z: 50 }], FOV, ASPECT)).toBeCloseTo(50, 6);
});
- it('uebergeht unbrauchbare Zahlen statt NaN zu liefern', () => {
- expect(containBackoff([{ x: Number.NaN, y: 0, z: -1 }], FOV, ASPECT)).toBe(0);
- expect(containBackoff([], FOV, ASPECT)).toBe(0);
+ it('bleibt ohne brauchbare Punkte stehen, statt NaN zu liefern', () => {
+ expect(containShift([{ x: Number.NaN, y: 0, z: -1 }], FOV, ASPECT)).toBe(0);
+ expect(containShift([], FOV, ASPECT)).toBe(0);
});
});
diff --git a/graph-ui/src/galaxy/camera-frame.ts b/graph-ui/src/galaxy/camera-frame.ts
index 9adce99f2..8359622bd 100644
--- a/graph-ui/src/galaxy/camera-frame.ts
+++ b/graph-ui/src/galaxy/camera-frame.ts
@@ -415,16 +415,16 @@ export function principalFrame(points: readonly Vector3Like[]): PrincipalFrame {
}
/**
- * Wie weit eine Kamera entlang ihrer Blickrichtung zuruecktreten muss, damit
- * jeder Punkt mit Rand im Bild liegt.
+ * Wie weit eine Kamera entlang ihrer Blickrichtung treten muss, damit jeder
+ * Punkt mit Rand im Bild liegt und der aeusserste genau am Rand steht.
*
* Die Punkte stehen im Blickraum der Kamera (vor ihr ist z negativ). Ein
- * Schritt zurueck aendert ihr x und y nicht, nur ihre Tiefe, also ist die
- * Antwort fuer jeden Punkt geschlossen ausrechenbar: die Tiefe, bei der er
- * genau am Rand steht, weniger der Tiefe, die er hat. Null heisst: alles ist
- * schon im Bild, und die Kamera bleibt, wo sie ist. Sie tritt nie vor.
+ * Schritt entlang der Blickrichtung aendert ihr x und y nicht, nur ihre Tiefe,
+ * also ist die Antwort fuer jeden Punkt geschlossen ausrechenbar: die Tiefe,
+ * bei der er genau am Rand steht, weniger der Tiefe, die er hat. Positiv heisst
+ * zurueck, negativ heisst vor; ohne brauchbare Punkte bleibt sie stehen.
*/
-export function containBackoff(
+export function containShift(
points: readonly Vector3Like[],
fovDegrees: number,
aspect: number,
@@ -434,15 +434,15 @@ export function containBackoff(
const scale = Number.isFinite(margin) && margin > 0 ? margin : 1;
const vertical = Math.tan(fov / 2) / scale;
const horizontal = vertical * (Number.isFinite(aspect) && aspect > 0 ? aspect : 1);
- let back = 0;
+ let shift = Number.NEGATIVE_INFINITY;
for (const point of points) {
if (!Number.isFinite(point.x) || !Number.isFinite(point.y) || !Number.isFinite(point.z)) {
continue;
}
const needed = Math.max(Math.abs(point.x) / horizontal, Math.abs(point.y) / vertical);
- back = Math.max(back, needed + point.z);
+ shift = Math.max(shift, needed + point.z);
}
- return back;
+ return Number.isFinite(shift) ? shift : 0;
}
/** Wo die Kamera steht, damit die ganze Wolke im Bild ist. */