From cb9e04c49ab19790c2fd51d64f2f7566436c904c Mon Sep 17 00:00:00 2001 From: Salim <99040857+salim4n@users.noreply.github.com> Date: Fri, 27 Nov 2026 10:02:32 +0100 Subject: [PATCH] RL 2 : les deux moyennes restent visibles quand elles se superposent (#136) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Contrôle visuel Fulgrim, critère 2. Co-authored-by: OpenBot <335604065+openbotgit[bot]@users.noreply.github.com> --- .../demo-target-chasing/src/locales/en.json | 1 + .../demo-target-chasing/src/locales/fr.json | 1 + .../demo-target-chasing/src/rl2/Rl2App.tsx | 57 ++++++++++++++++++- 3 files changed, 57 insertions(+), 2 deletions(-) diff --git a/packages/demo-target-chasing/src/locales/en.json b/packages/demo-target-chasing/src/locales/en.json index 38efde2..fdeeab5 100644 --- a/packages/demo-target-chasing/src/locales/en.json +++ b/packages/demo-target-chasing/src/locales/en.json @@ -90,6 +90,7 @@ "chartReturns": "Episode return, read from the logs", "binNote": "mean of the episodes that end in each {bin}-step bin; no other smoothing", "band": "band: min–max over 3 seeds · thin line: one seed", + "overlapNote": "alternating line: both means overlap", "xAxis": "environment steps", "tooltipSteps": "steps {from} to {to}", "tooltipEpisodes": "episodes {from} to {to}", diff --git a/packages/demo-target-chasing/src/locales/fr.json b/packages/demo-target-chasing/src/locales/fr.json index daa6408..fc99ade 100644 --- a/packages/demo-target-chasing/src/locales/fr.json +++ b/packages/demo-target-chasing/src/locales/fr.json @@ -90,6 +90,7 @@ "chartReturns": "Retour par épisode, lu dans les journaux", "binNote": "moyenne des épisodes terminés dans chaque tranche de {bin} pas ; aucun autre lissage", "band": "bande : min–max sur 3 graines · trait fin : une graine", + "overlapNote": "trait alterné : les deux moyennes se superposent", "xAxis": "pas d’environnement", "tooltipSteps": "pas {from} à {to}", "tooltipEpisodes": "épisodes {from} à {to}", diff --git a/packages/demo-target-chasing/src/rl2/Rl2App.tsx b/packages/demo-target-chasing/src/rl2/Rl2App.tsx index c2fb075..b27ffce 100644 --- a/packages/demo-target-chasing/src/rl2/Rl2App.tsx +++ b/packages/demo-target-chasing/src/rl2/Rl2App.tsx @@ -4,6 +4,7 @@ import { Component, useCallback, useEffect, + useId, useMemo, useRef, useState, @@ -19,6 +20,7 @@ import { ReferenceLine, ResponsiveContainer, Tooltip, + usePlotArea, XAxis, YAxis, } from 'recharts'; @@ -590,9 +592,56 @@ function Legend2() { ); } +/** + * Where the two mean lines overlap, the last one drawn would hide the other. + * Both stay solid and each is clipped to alternating vertical stripes in screen + * coordinates (first variant: even stripes, second: odd ones), so an overlap + * reads as one line alternating both colours, whatever the path length. + */ +const STRIPE_PX = 8; +const STRIPE_PX_NARROW = 6; +/** Vertical margin so the clip never trims a stroke lying on the plot edge. */ +const STRIPE_PAD = 4; + +/** One clip-path id per variant, unique per chart. */ +function useStripeIds(): Record { + const uid = useId().replace(/[^a-zA-Z0-9_-]/g, ''); + return useMemo(() => Object.fromEntries(RL2_ALGOS.map((algo) => [algo, `rl2-stripes-${uid}-${algo}`])) as Record, [uid]); +} + +/** Rendered inside the chart: stripe clip paths sized on the plot area. */ +function StripeClips({ ids, stripe }: { ids: Record; stripe: number }) { + const plot = usePlotArea(); + if (!plot || plot.width <= 0) return null; + const count = Math.ceil(plot.width / stripe); + return ( + + {RL2_ALGOS.map((algo, parity) => ( + + {Array.from({ length: count }, (_, i) => i) + .filter((i) => i % 2 === parity % 2) + .map((i) => ( + + ))} + + ))} + + ); +} + +/** + * Line props for a mean line clipped to its stripes. Line overrides a plain + * clipPath prop with its plot-area clip; a shape object is merged last, so the + * stripes (bounded by the plot area) replace that clip. + */ +function stripedLine(ids: Record, algo: Rl2Algo) { + return { strokeWidth: 2, shape: { clipPath: `url(#${ids[algo]})` } }; +} + function ReturnsChart({ rows, budget, narrow, lang, num, noisy }: { rows: ChartRow[]; budget: number; narrow: boolean; lang: Language; num: BenchViewProps['num']; noisy: boolean }) { const seedKeys = (algo: Rl2Algo) => Object.keys(rows[0] ?? {}).filter((k) => k.startsWith(seriesKey(algo, 's'))); const domain = sharedDomain(rows, RL2_ALGOS.flatMap((algo) => [seriesKey(algo, 'band'), ...seedKeys(algo)])); + const stripeIds = useStripeIds(); return (

{t('rl2.chartReturns')}

@@ -612,14 +661,16 @@ function ReturnsChart({ rows, budget, narrow, lang, num, noisy }: { rows: ChartR )), )} + {RL2_ALGOS.map((algo) => ( - + ))}

{t('rl2.xAxis')}

{t('rl2.band')}

+

{t('rl2.overlapNote')}

); } @@ -672,6 +723,7 @@ function QBlock({ rows, budget, gamma, narrow, lang, num, noisy }: { rows: Chart const gapDomain = sharedDomain(rows, RL2_ALGOS.map((algo) => seriesKey(algo, 'gap')), 0.1); const gapDomainWithZero: [number, number] = [Math.min(gapDomain[0], 0), Math.max(gapDomain[1], 0)]; const height = narrow ? 180 : 200; + const stripeIds = useStripeIds(); return (

{t('rl2.chartQ', { gamma: num(gamma, 2) })}

@@ -733,8 +785,9 @@ function QBlock({ rows, budget, gamma, narrow, lang, num, noisy }: { rows: Chart } /> + {RL2_ALGOS.map((algo) => ( - + ))}