From fa879a8b40bd198045ca9aeee66f12a71c92a08c Mon Sep 17 00:00:00 2001 From: Duarte Santos Date: Tue, 25 Aug 2026 22:02:32 +0200 Subject: [PATCH] stats: keep the e1RM chart's points stable, and note where stackedValue stops MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Two follow-ups to !24 and !25, both about the same screen. !25 makes LineChart drop its hover whenever `points` changes identity, which is right — a new dataset has different coordinates and the old marker describes nothing. But the e1RM branch built its array inline with .map(), so every render of Stats handed the chart a brand-new array and cleared the tooltip out from under the pointer. Hovering itself only re-renders LineChart, so it survives that; anything else touching this screen did not. Memoising the .map() alone would not have fixed it, because e1rmSeries was itself called fresh on every render, so the memo's own dependency changed identity every time. Both are memoised now, which also stops walking the whole workout history on every render. !24's grid is two columns, label/value and chevron, and does not place .lrow-i. On a row that has an icon it would auto-place and shove the layout around. The one call site has no icon, so this is latent rather than live — written down in the rule so the next person to reach for stackedValue sees the limit first. --- frontend/src/index.css | 6 +++++- frontend/src/views/Stats.jsx | 12 ++++++++++-- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/frontend/src/index.css b/frontend/src/index.css index 3259df5..a348459 100644 --- a/frontend/src/index.css +++ b/frontend/src/index.css @@ -241,7 +241,11 @@ h4.sec{ .lrow-c{color:var(--label);font-size:15px;flex:none;--icon-stroke:2.4} .lrow-k{color:var(--acc);font-size:17px;flex:none;--icon-stroke:2.4} .lrow.danger,.lrow.danger .lrow-t{color:var(--red)} -/* The Stats exercise name gets its own line so long names cannot run into the title. */ +/* The Stats exercise name gets its own line so long names cannot run into the title. + Two columns only — label/value on the left, chevron on the right — so this is for rows + WITHOUT an icon. `.lrow-i` is not placed here; on a row that has one it would auto-place + into the grid and push the layout around. Give it a leading column before using this + anywhere else. */ .lrow.lrow-stack-value{ display:grid;grid-template-columns:minmax(0,1fr) auto;grid-template-rows:auto auto; } diff --git a/frontend/src/views/Stats.jsx b/frontend/src/views/Stats.jsx index a7de297..3622b7b 100644 --- a/frontend/src/views/Stats.jsx +++ b/frontend/src/views/Stats.jsx @@ -360,7 +360,15 @@ export default function Stats() { } // Estimated 1RM (issue #18) — only reps-mode training produces one, so cardio and timed // work simply have no points and the toggle stays hidden. - const e1Pts = curEx && curMode === 'reps' ? e1rmSeries(S, curEx) : [] + // Both memoised on the same inputs, and it has to start at e1rmSeries: LineChart clears its + // hover whenever `points` changes identity, so a chart array rebuilt on every render made the + // tooltip vanish under your finger the moment anything else on this screen re-rendered. + // Memoising only the .map() would not have helped — its dependency was itself rebuilt each time. + const e1Pts = useMemo( + () => (curEx && curMode === 'reps' ? e1rmSeries(S, curEx) : []), + [S, curEx, curMode], + ) + const e1ChartPts = useMemo(() => e1Pts.map(p => ({ t: p.t, y: p.y, d: p.d })), [e1Pts]) const e1Best = curEx && curMode === 'reps' ? best1RM(S, curEx) : null const showE1 = e1Pts.length > 0 // Effort on this exercise, per session. It rides on the top-set curve as well as having a @@ -426,7 +434,7 @@ export default function Stats() {
{onEff ? - : ({ t: p.t, y: p.y, d: p.d })) : topPts} h={150} unit={exUnit} color="var(--blue)" />} + : }
{exList.map((p, i) =>
{fmtDate(p.d, true)}{p.sets.map(s => setLabel(curEx, s, p.target)).join(' ')}
)}