From 9b517b5bf6ec9c975dd02335f5da102da26036d7 Mon Sep 17 00:00:00 2001 From: Jens Mohrmann Date: Sat, 27 Dec 2025 19:27:18 +0100 Subject: [PATCH] Fix piano graphics --- src/components/PianoKeys.tsx | 62 ++++++++++++++++++++++-------------- 1 file changed, 38 insertions(+), 24 deletions(-) diff --git a/src/components/PianoKeys.tsx b/src/components/PianoKeys.tsx index 1386931..cbf26f5 100644 --- a/src/components/PianoKeys.tsx +++ b/src/components/PianoKeys.tsx @@ -206,15 +206,6 @@ export function PianoKeys({ } const stroke = '#000'; - - // Height needs to be converted if in px mode? No, SVG viewBox handles scale for Y if we used 100... - // But wait. - // If viewMode is 'zoomed', viewBox is `0 0 totalWidthVal 100`. - // So Y coordinates are 0-100. - // If viewMode is 'full', viewBox is `0 0 100 100`. - // So Y coordinates are 0-100. - // Perfect. - const rectHeight = k.isBlack ? BLACK_KEY_HEIGHT_PERCENT * 100 : 100; return ( @@ -227,35 +218,58 @@ export function PianoKeys({ fill={fill} stroke={stroke} strokeWidth={0.5} + vectorEffect="non-scaling-stroke" rx={k.isBlack ? 0 : 2} ry={k.isBlack ? 0 : 2} /> - {/* Labels for C notes on white keys */} - {!k.isBlack && k.label && ( - - {k.label} - - )} - {/* Marker dot if hinted? Existing marker logic just changes color, maybe dot is better? */} + {isMarked && ( )} ); })} + + {/* Overlay for Labels to avoid distortion */} +
+ {keyRects.map(k => { + if (k.isBlack || !k.label) return null; + // Calculate left position as percentage or pixel + const left = viewMode === 'full' + ? `${k.x + (k.width / 2)}%` + : `${k.x + (k.width / 2)}px`; + + return ( +
+ {k.label} +
+ ); + })} +