From bf1576252b480c31602cb41ff4f584d2f03f7ed7 Mon Sep 17 00:00:00 2001 From: Justin Paul Date: Thu, 11 Jun 2026 08:58:36 -0400 Subject: [PATCH] Fix fly-to vertical centering at non-1 zoom levels MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Clicking ×N sometimes flew to a blank area far below the tree. Cause: family-chart's cardToMiddle scales datum.x by the zoom factor k but not datum.y (`y = height/2 - datum.y`, missing the ·k), so vertical centering is only correct at k=1 and drifts by datum.y·(k−1) at any other zoom — worse the deeper the person sits. That's why it worked only when the view happened to be near 1:1. Compensate by pre-multiplying the y we pass to cardToMiddle by the current scale, cancelling the library's missing ·k. x was already correct. Signed-off-by: Justin Paul --- frontend/app/trees/[id]/tree/page.tsx | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/frontend/app/trees/[id]/tree/page.tsx b/frontend/app/trees/[id]/tree/page.tsx index 2baeef1..02b3c35 100644 --- a/frontend/app/trees/[id]/tree/page.tsx +++ b/frontend/app/trees/[id]/tree/page.tsx @@ -315,8 +315,12 @@ export default function TreePage() { try { const rect = svg.getBoundingClientRect(); const scale = handlers.getCurrentZoom ? handlers.getCurrentZoom(svg).k : 1; + // family-chart's cardToMiddle scales datum.x by the zoom but NOT + // datum.y (a library bug), so vertical centering is only correct at + // scale 1 and drifts by datum.y·(k−1) otherwise — landing "below the + // tree". Pre-multiply y by the scale to cancel the missing ·k. handlers.cardToMiddle({ - datum: xy, + datum: { x: xy.x, y: xy.y * scale }, svg, svg_dim: { width: rect.width, height: rect.height }, scale,