refactor: improve measurement label anchoring to track area edges during resize

This commit is contained in:
DiTus
2026-03-21 14:24:57 +01:00
parent a1564c25a7
commit 8931d76a43

View File

@ -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);