From 8931d76a43c09f0eeb06878ceffbbac9cfd9894b Mon Sep 17 00:00:00 2001 From: DiTus Date: Sat, 21 Mar 2026 14:24:57 +0100 Subject: [PATCH] refactor: improve measurement label anchoring to track area edges during resize --- js/ui/drawing-tools.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/js/ui/drawing-tools.js b/js/ui/drawing-tools.js index d0d116a..a743357 100644 --- a/js/ui/drawing-tools.js +++ b/js/ui/drawing-tools.js @@ -674,8 +674,16 @@ export class DrawingManager { ctx.font = '500 12px Inter'; const labelWidth = Math.max(...labelLines.map(l => ctx.measureText(l).width)) + 24; const labelHeight = 65; - const defaultLabelX = x2 - labelWidth / 2; - const defaultLabelY = isUp ? y2 - labelHeight - 10 : y2 + 10; + + // Natural position: Centered horizontally at midpoint, + // vertically offset from the top/bottom edge. + // This makes the label follow the box edges correctly during resize. + const midX = (x1 + x2) / 2; + const topY = Math.min(y1, y2); + const bottomY = Math.max(y1, y2); + + const defaultLabelX = midX - labelWidth / 2; + const defaultLabelY = isUp ? topY - labelHeight - 10 : bottomY + 10; const labelX = defaultLabelX + (d.labelOffset?.x || 0); const labelY = defaultLabelY + (d.labelOffset?.y || 0);