Skip to content

Commit

Permalink
Merge pull request #429 from xenharmonic-devs/fit-chord-wheel-text
Browse files Browse the repository at this point in the history
Adjust chord wheel text size dynamically to fit
  • Loading branch information
frostburn authored Nov 26, 2023
2 parents 64d7a7b + aa7a28c commit 1579ca2
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/components/ChordWheel.vue
Original file line number Diff line number Diff line change
Expand Up @@ -158,10 +158,19 @@ function draw(time: DOMHighResTimeStamp) {
// Render numbers indicating the implied enumerated chord.
ctx.font = `${size / 10}px sans-serif`;
ctx.fillStyle = props.textColor;
let text;
if (props.type === "otonal") {
ctx.fillText(chord.join(":"), size / 10, size / 10);
text = chord.join(":");
} else {
ctx.fillText("1/(" + chord.join(":") + ")", size / 5, size / 10);
text = "1/(" + chord.join(":") + ")";
}
const textWidth = ctx.measureText(text).width;
if (textWidth * 10 < width * 8) {
ctx.fillText(text, size / 10, size / 10);
} else {
const fontSize = (size / 11) * (width / textWidth);
ctx.font = `${fontSize}px sans-serif`;
ctx.fillText(text, size / 20, size / 10);
}
animationFrame = window.requestAnimationFrame(draw);
Expand Down

0 comments on commit 1579ca2

Please sign in to comment.