Fix spur label sizing: use narrow end width so text fits inside trapezoid

Position text at 40% from top (toward narrow end) and constrain width
to the narrower edge so text never overflows the trapezoid shape.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
igurielidze 2026-03-30 21:26:16 +04:00
parent 3506d6164d
commit 072c80e886
2 changed files with 12 additions and 7 deletions

View File

@ -556,10 +556,13 @@ function drawConveyanceLabel(ctx: CanvasRenderingContext2D, sym: PlacedSymbol) {
let cx: number, cy: number, availW: number, availH: number; let cx: number, cy: number, availW: number, availH: number;
if (isSpurType(sym.symbolId)) { if (isSpurType(sym.symbolId)) {
const w2 = sym.w2 ?? sym.w; const w2 = sym.w2 ?? sym.w;
const midW = (w2 + sym.w) / 2; // width at vertical midpoint // Use the width at 40% from top (biased toward narrow end for safe fit)
cx = sym.x + midW / 2; const t = 0.4;
cy = sym.y + sym.h / 2; const widthAtT = w2 + t * (sym.w - w2);
availW = midW - pad * 2; cx = sym.x + widthAtT / 2;
cy = sym.y + sym.h * t;
// Use narrower of top/bottom edge with padding for safe text fit
availW = Math.min(w2, widthAtT) - pad * 2;
availH = sym.h - pad * 2; availH = sym.h - pad * 2;
} else { } else {
cx = sym.x + sym.w / 2; cx = sym.x + sym.w / 2;

View File

@ -44,9 +44,11 @@ function emitConveyanceLabelInner(lines: string[], sym: PlacedSymbol) {
textRotDeg = (textRotRad * 180) / Math.PI; textRotDeg = (textRotRad * 180) / Math.PI;
} else if (isSpurType(sym.symbolId)) { } else if (isSpurType(sym.symbolId)) {
const w2 = sym.w2 ?? sym.w; const w2 = sym.w2 ?? sym.w;
labelCx = sym.x + (w2 + sym.w) / 4; const t = 0.4;
labelCy = sym.y + sym.h / 2; const widthAtT = w2 + t * (sym.w - w2);
availH = sym.h - 4; labelCx = sym.x + widthAtT / 2;
labelCy = sym.y + sym.h * t;
availH = Math.min(sym.h - 4, widthAtT - 4);
} else if (isInductionType(sym.symbolId)) { } else if (isInductionType(sym.symbolId)) {
const stripTopY = sym.y + sym.h * INDUCTION_CONFIG.stripTopFrac; const stripTopY = sym.y + sym.h * INDUCTION_CONFIG.stripTopFrac;
const stripBottomY = sym.y + sym.h * INDUCTION_CONFIG.stripBottomFrac; const stripBottomY = sym.y + sym.h * INDUCTION_CONFIG.stripBottomFrac;