Pastille du paysage : police de la consigne, jamais resserrée ; deux lignes s'il le faut

La consigne de la bande garde la taille de la consigne ordinaire (12 px
au moins, charte) ; trop longue, elle passe sur deux lignes, une phrase
par ligne. Le resserrement de la police est supprimé. Test navigateur :
même police que la consigne ordinaire, dans la pastille, sans chevaucher
de pion.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Pierre MARTIN
2026-11-23 13:01:57 +01:00
co-authored by Claude Opus 5.5
parent a4a38954bd
commit 9927d405dc
2 changed files with 97 additions and 28 deletions
+53 -19
View File
@@ -614,33 +614,67 @@ function addRing(
function drawBand(svg: SVGSVGElement, g: Geometry, text: string, before = 0): void {
const middle = g.height / 2;
const width = 6 * g.pointWidth - 24 - before;
const height = Math.max(44, g.bandFont + 20);
const x = g.x0 + 12 + before;
// Une consigne longue (« Partie Crawford · … ») tient dans la pastille :
// la police se resserre, sans descendre sous 13 px (charte). Largeur
// moyenne d'un caractère d'Alegreya Sans en gras : un peu moins de
// 0,45 em.
const fontSize = Math.max(13, Math.min(g.bandFont, (width - 24) / (0.45 * text.length)));
// La consigne garde toujours sa taille (12 px au moins, charte) : trop
// longue pour une ligne, elle passe sur deux, une phrase par ligne de
// préférence. Largeur moyenne d'un caractère d'Alegreya Sans en gras :
// un peu moins de 0,45 em.
const fontSize = g.bandFont;
const lines = bandLines(text, (width - 24) / (0.45 * fontSize));
const lineHeight = fontSize * 1.2;
const height = Math.max(44, fontSize + 20, lines.length * lineHeight + 16);
add(svg, "rect", {
class: "band-pill",
x,
y: middle - height / 2,
width,
height,
rx: height / 2,
rx: Math.min(height / 2, 22),
});
add(
svg,
"text",
{
class: "band-text",
id: "band-text",
x: x + width / 2,
y: middle + fontSize * 0.35,
"font-size": fontSize,
},
text,
);
const label = add(svg, "text", {
class: "band-text",
id: "band-text",
x: x + width / 2,
y: middle + fontSize * 0.35 - ((lines.length - 1) * lineHeight) / 2,
"font-size": fontSize,
});
lines.forEach((line, i) => {
add(
label,
"tspan",
{ x: x + width / 2, dy: i === 0 ? 0 : lineHeight },
// L'espace entre les deux lignes reste dans le texte (lecteurs
// d'écran, tests) : à la fin de la première.
i < lines.length - 1 ? `${line} ` : line,
);
});
}
/** Une consigne en une ligne, ou en deux si elle dépasse capacity
* caractères : coupée après la première phrase quand les deux tiennent,
* sinon à l'espace le plus proche du milieu. */
function bandLines(text: string, capacity: number): string[] {
if (text.length <= capacity) {
return [text];
}
const sentence = text.indexOf(". ");
if (sentence > 0) {
const first = text.slice(0, sentence + 1);
const second = text.slice(sentence + 2);
if (first.length <= capacity && second.length <= capacity) {
return [first, second];
}
}
let cut = -1;
for (let i = 0; i < text.length; i++) {
if (
text[i] === " " &&
(cut < 0 || Math.abs(i - text.length / 2) < Math.abs(cut - text.length / 2))
) {
cut = i;
}
}
return cut < 0 ? [text] : [text.slice(0, cut), text.slice(cut + 1)];
}
/** Largeur de la pastille du conseil : pictogramme, mot (estimé à 0,55 em