From a7852dfbe90c065357f9f42ed2f0dac3dc8be049 Mon Sep 17 00:00:00 2001 From: Pierre MARTIN Date: Mon, 23 Nov 2026 06:37:10 +0100 Subject: [PATCH] =?UTF-8?q?Recette=201l=20:=20courbe=20redessin=C3=A9e=20s?= =?UTF-8?q?ur=20sa=20taille=20rendue,=20anneau=20du=20moment=20d=C3=A9cisi?= =?UTF-8?q?f=20seul=20pr=C3=A8s=20de=20la=20fin?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit La courbe se redessine deux images après chaque changement de taille, sans garder de taille en mémoire : en paysage, un tracé dessiné sur une largeur périmée ramenait les libellés à 7 px. Deux marques à moins de 16 px à l'écran n'en font qu'une, l'anneau or, et la légende le dit. Le test mesure la courbe rendue avant et après chaque capture. Co-Authored-By: Claude Opus 5.5 --- app/src/ui/match-summary-view.ts | 113 +++++++++++++++++-------------- tests/browser/match-bilan.mjs | 53 ++++++++++++--- 2 files changed, 106 insertions(+), 60 deletions(-) diff --git a/app/src/ui/match-summary-view.ts b/app/src/ui/match-summary-view.ts index 0e6d7d1..2390deb 100644 --- a/app/src/ui/match-summary-view.ts +++ b/app/src/ui/match-summary-view.ts @@ -77,6 +77,9 @@ const SVG_NS = "http://www.w3.org/2000/svg"; const CURVE_HEIGHT = 196; const PAD = { left: 40, right: 12, top: 26, bottom: 26 }; const BUBBLE = { width: 210, height: 44 }; +/** Deux marques plus proches que ceci à l'écran (en x et en y) n'en font + * qu'une : l'anneau du moment décisif (charte, « Bilan du match »). */ +const MERGE_DISTANCE = 16; function element( parent: HTMLElement, @@ -127,9 +130,12 @@ export function createMatchSummaryView(options: MatchSummaryViewOptions): MatchS const { section } = options; let drawn = ""; let redrawCurve: (() => void) | null = null; + // Après un changement de taille de la fenêtre, la mise en page (une + // ou deux colonnes) n'est finie qu'aux images suivantes : la courbe se + // redessine après deux images, sur sa taille rendue. window.addEventListener("resize", () => { if (!section.hidden) { - redrawCurve?.(); + afterLayout(() => redrawCurve?.()); } }); @@ -278,23 +284,33 @@ export function createMatchSummaryView(options: MatchSummaryViewOptions): MatchS svg.setAttribute("tabindex", "0"); card.append(svg); const legend = element(card, "ul", { className: "match-legend" }); - // Le moment décisif sur la fin du match : l'anneau or seul. - const marks: [string, string][] = decisiveAtEnd(summary) - ? [ - ["decisive", T.legendDecisiveEnd], - ["review", T.legendReview], - ] - : [ - ["decisive", T.legendDecisive], - ["review", T.legendReview], - [summary.match.winner === "player" ? "end won" : "end", T.legendEnd], - ]; - for (const [mark, text] of marks) { - const item = element(legend, "li"); - const dot = element(item, "span", { className: `match-mark ${mark}` }); - dot.setAttribute("aria-hidden", "true"); - item.append(text); - } + // La légende suit le tracé : quand l'anneau du moment décisif et le + // point de fin se touchent à l'écran, l'anneau or seul (charte). + let legendKey = ""; + const renderLegend = (merged: boolean) => { + const marks: [string, string][] = merged + ? [ + ["decisive", T.legendDecisiveEnd], + ["review", T.legendReview], + ] + : [ + ["decisive", T.legendDecisive], + ["review", T.legendReview], + [summary.match.winner === "player" ? "end won" : "end", T.legendEnd], + ]; + const key = String(merged); + if (key === legendKey) { + return; + } + legendKey = key; + legend.replaceChildren(); + for (const [mark, text] of marks) { + const item = element(legend, "li"); + const dot = element(item, "span", { className: `match-mark ${mark}` }); + dot.setAttribute("aria-hidden", "true"); + item.append(text); + } + }; const points = summary.curve; const known = points.filter((p) => p.chance !== null); if (known.length < points.length) { @@ -315,23 +331,16 @@ export function createMatchSummaryView(options: MatchSummaryViewOptions): MatchS ); svg.dataset.points = JSON.stringify(points.map((p) => [p.game, p.turn, p.chance])); let selected: number | null = null; - const draw = () => drawCurve(svg, summary, selected); + const draw = () => renderLegend(drawCurve(svg, summary, selected)); redrawCurve = draw; draw(); - // Le tracé suit la taille réelle de la courbe (une unité du viewBox - // pour un pixel, les libellés à leur taille) : il se redessine dès - // qu'elle change, quand la page devient visible ou tourne. + // Le tracé suit la taille rendue de la courbe (une unité du viewBox + // pour un pixel, les libellés à leur taille) : il se redessine à + // chaque changement de taille, après la mise en page. if (typeof ResizeObserver !== "undefined") { - let size = ""; - new ResizeObserver(() => { - const box = svg.getBoundingClientRect(); - const now = `${Math.round(box.width)}x${Math.round(box.height)}`; - if (box.width > 0 && now !== size) { - size = now; - draw(); - } - }).observe(svg); + new ResizeObserver(() => afterLayout(draw)).observe(svg); } + afterLayout(draw); // Lecture au doigt : glisser choisit le point sous le doigt (une // vibration légère à chaque changement de partie) ; lâcher garde la @@ -624,7 +633,7 @@ export function createMatchSummaryView(options: MatchSummaryViewOptions): MatchS * pointillés ; trois marques (moment décisif, décision à revoir, fin) ; la * bulle du point choisi. */ -function drawCurve(svg: SVGSVGElement, summary: MatchSummary, selected: number | null): void { +function drawCurve(svg: SVGSVGElement, summary: MatchSummary, selected: number | null): boolean { const box = svg.getBoundingClientRect(); const width = Math.round(box.width || 360); const height = Math.round(box.height || CURVE_HEIGHT); @@ -707,24 +716,38 @@ function drawCurve(svg: SVGSVGElement, summary: MatchSummary, selected: number | } const indexOf = (game: number, turn: number) => points.findIndex((p) => p.game === game && p.turn === turn); - const mark = (i: number, cls: string, r: number) => { + const at = (i: number): { x: number; y: number } | null => { const c = points[i]?.chance; - if (i >= 0 && c !== null && c !== undefined) { - svgElement(svg, "circle", { cx: x(i), cy: y(c), r, class: cls }).setAttribute( + return i >= 0 && c !== null && c !== undefined ? { x: x(i), y: y(c) } : null; + }; + const mark = (i: number, cls: string, r: number) => { + const p = at(i); + if (p !== null) { + svgElement(svg, "circle", { cx: p.x, cy: p.y, r, class: cls }).setAttribute( "aria-hidden", "true", ); } }; const decisive = summary.decisive; + const decisiveIndex = decisive === null ? -1 : indexOf(decisive.game, decisive.turn); if (decisive !== null) { - mark(indexOf(decisive.game, decisive.turn), "match-mark-ring", 8); + mark(decisiveIndex, "match-mark-ring", 8); } const reviewed = summary.toReview; if (reviewed !== null) { mark(indexOf(reviewed.game, reviewed.turn), "match-mark-review", 5); } - if (summary.match.over && !decisiveAtEnd(summary)) { + // Le moment décisif et la fin du match à moins de MERGE_DISTANCE l'un + // de l'autre à l'écran : l'anneau or seul tient lieu des deux marques. + const ring = at(decisiveIndex); + const end = summary.match.over ? at(points.length - 1) : null; + const merged = + ring !== null && + end !== null && + Math.abs(ring.x - end.x) < MERGE_DISTANCE && + Math.abs(ring.y - end.y) < MERGE_DISTANCE; + if (end !== null && !merged) { mark( points.length - 1, summary.match.winner === "player" ? "match-mark-end won" : "match-mark-end", @@ -744,20 +767,12 @@ function drawCurve(svg: SVGSVGElement, summary: MatchSummary, selected: number | }); bubble(svg, summary, point, x(selected), width); } + return merged; } -/** Le moment décisif est le dernier tour du match fini : sa marque (l'anneau - * or) tient lieu de marque de fin. */ -function decisiveAtEnd(summary: MatchSummary): boolean { - const decisive = summary.decisive; - const last = summary.curve.at(-1); - return ( - summary.match.over && - decisive !== null && - last !== undefined && - last.game === decisive.game && - last.turn === decisive.turn - ); +/** Lance fn après deux images : la mise en page en cours est finie. */ +function afterLayout(fn: () => void): void { + requestAnimationFrame(() => requestAnimationFrame(fn)); } /** La bulle du point choisi : partie, coup, score, chances ; un lien SVG diff --git a/tests/browser/match-bilan.mjs b/tests/browser/match-bilan.mjs index e660088..3dc7397 100644 --- a/tests/browser/match-bilan.mjs +++ b/tests/browser/match-bilan.mjs @@ -99,13 +99,19 @@ async function until(what, fn, arg, ms = 180_000) { /** Une capture de la recette en portrait et en paysage (Chromium * seulement), après les règles communes. */ -async function capture(name, before = async () => {}) { +/** Deux images de plus : la mise en page et ce qui se redessine après elle + * (la courbe du match) sont finis. */ +const frames = () => + page.evaluate(() => new Promise((resolve) => requestAnimationFrame(() => requestAnimationFrame(resolve)))); + +async function capture(name, before = async () => {}, after = async () => {}) { if (!full) { return; } for (const size of SIZES) { await page.setViewportSize(size); await sleep(300); + await frames(); await before(); const hidden = await hiddenUnderActionBar(page); check(hidden.length === 0, @@ -113,6 +119,8 @@ async function capture(name, before = async () => {}) { const tall = await tallButtons(page); check(tall.length === 0, `${name} ${size.width}x${size.height} : boutons étirés : ${tall.join(", ")}`); await page.screenshot({ path: `${dir}/${name}-${size.width}x${size.height}.png`, fullPage: true }); + await frames(); + await after(); captures++; } await page.setViewportSize(PORTRAIT); @@ -315,27 +323,50 @@ async function curveTextsReadable(where) { const box = svg.getBoundingClientRect(); const view = svg.viewBox.baseVal; const scale = Math.min(box.width / view.width, box.height / view.height); - return [...svg.querySelectorAll("text")] + const found = [...svg.querySelectorAll("text")] .map((t) => ({ text: t.textContent, px: parseFloat(getComputedStyle(t).fontSize) * scale })) .filter((t) => t.px < 11.95) .map((t) => `« ${t.text} » ${t.px.toFixed(1)} px`); + // Le tracé remplit la courbe : le viewBox a la taille rendue, sans + // bande vide sous le tracé ni à côté. + if (Math.abs(box.width - view.width) > 2 || Math.abs(box.height - view.height) > 2) { + found.push(`viewBox ${view.width}x${view.height} pour ${Math.round(box.width)}x${Math.round(box.height)} rendus`); + } + return found; }); - check(small.length === 0, `${where} : libellés de la courbe trop petits : ${small.join(", ")}`); + check(small.length === 0, `${where} : courbe mal dessinée : ${small.join(", ")}`); } await curveTextsReadable("portrait"); // Le moment décisif sur la fin du match : l'anneau or seul, et la légende // le dit. -const legend = await page.evaluate(() => ({ - items: [...document.querySelectorAll(".match-legend li")].map((li) => li.textContent), - endDot: document.querySelector("#match-curve .match-mark-end") !== null, -})); -const decisiveAtEnd = legend.items.includes("Moment décisif, fin du match"); -check(decisiveAtEnd ? !legend.endDot && legend.items.length === 2 : legend.endDot && legend.items.length === 3, - `légende de la courbe : ${JSON.stringify(legend)}`); +// Dans ce match, le moment décisif (le 2-1 de l'ordinateur, jusqu'à +// 100 %) touche le point de fin à l'écran : l'anneau or seul, et la légende +// le dit (charte : deux marques à moins de 16 px n'en font qu'une). +async function mergedMarks(where) { + const legend = await page.evaluate(() => ({ + items: [...document.querySelectorAll(".match-legend li")].map((li) => li.textContent), + endDot: document.querySelector("#match-curve .match-mark-end") !== null, + ring: document.querySelector("#match-curve .match-mark-ring") !== null, + })); + check(legend.ring && !legend.endDot && + JSON.stringify(legend.items) === JSON.stringify(["Moment décisif, fin du match", "Décision à revoir"]), + `${where} : marques et légende de la courbe : ${JSON.stringify(legend)}`); +} +/** La courbe telle qu'elle est rendue : libellés lisibles, marques. */ +async function curveChecks(where) { + await curveTextsReadable(where); + await mergedMarks(where); +} +await frames(); +await mergedMarks("portrait"); // Les tuiles : le chiffre seul, l'unité en une ligne dessous. check((await page.textContent("#match-tiles-caption")).startsWith("Taux d'erreur, en millièmes par décision"), "légende des tuiles"); -await capture("1-bilan-du-match", () => curveTextsReadable("capture")); +await capture( + "1-bilan-du-match", + () => curveChecks("avant la capture"), + () => curveChecks("après la capture"), +); // La courbe touchée : la bulle (partie, coup, score, chances), un lien vers // la décision.