stats: keep the e1RM chart's points stable, and note where stackedValue stops
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.
This commit is contained in:
1 parent
651b03cbd1
commit
fa879a8b40
2 files changed
+15
-3
No files matched your search
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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() {
|
||||
<div className="chart">
|
||||
{onEff
|
||||
? <LineChart points={effPts} h={150} unit={hd} color="var(--yellow)" invert={kind === 'rir'} />
|
||||
: <LineChart points={onE1 ? e1Pts.map(p => ({ t: p.t, y: p.y, d: p.d })) : topPts} h={150} unit={exUnit} color="var(--blue)" />}
|
||||
: <LineChart points={onE1 ? e1ChartPts : topPts} h={150} unit={exUnit} color="var(--blue)" />}
|
||||
</div>
|
||||
<div style={{ marginTop: 8 }}>{exList.map((p, i) => <div key={i} className="row between small" style={{ padding: '6px 0', borderBottom: 'var(--hair) solid var(--sep)' }}>
|
||||
<span className="muted">{fmtDate(p.d, true)}</span><span>{p.sets.map(s => setLabel(curEx, s, p.target)).join(' ')}</span></div>)}</div>
|
||||
|
||||
Reference in new issue
Block a user