feat(stammbaum): recentre-on-node with legible auto-zoom (#692)

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
Marcel
2026-05-29 16:29:55 +02:00
parent 5d752fcc0f
commit 197b668f20
2 changed files with 48 additions and 0 deletions

View File

@@ -5,8 +5,10 @@ import {
serializePanZoomParams,
screenDeltaToSvg,
zoomAtPoint,
recentreOn,
DEFAULT_VIEW,
DEFAULT_ZOOM,
LEGIBLE_ZOOM,
MIN_ZOOM,
MAX_ZOOM
} from './panZoom';
@@ -120,3 +122,26 @@ describe('zoomAtPoint', () => {
expect(next).toEqual({ x: 30, y: 10, z: MAX_ZOOM });
});
});
describe('recentreOn', () => {
const node = { x: 300, y: 200 };
const base = { x: 100, y: 100 };
it('pans so the node sits at the viewBox centre, keeping the current zoom', () => {
expect(recentreOn(node, base, { x: 0, y: 0, z: 1 }, false)).toEqual({ x: 200, y: 100, z: 1 });
});
it('auto-zooms up to LEGIBLE_ZOOM when zoomed out (OQ-005)', () => {
const next = recentreOn(node, base, { x: 0, y: 0, z: 0.4 }, true);
expect(next.z).toBe(LEGIBLE_ZOOM);
expect({ x: next.x, y: next.y }).toEqual({ x: 200, y: 100 });
});
it('does not reduce an already-legible zoom when auto-zooming', () => {
expect(recentreOn(node, base, { x: 0, y: 0, z: 2 }, true).z).toBe(2);
});
it('leaves zoom untouched when auto-zoom is off', () => {
expect(recentreOn(node, base, { x: 0, y: 0, z: 0.4 }, false).z).toBe(0.4);
});
});