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:
@@ -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);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user