Muscle map: see which muscles your training actually reaches

A front-and-back body diagram, shaded with the same accent ramp as the
activity heatmap, in three places: Stats gets a Muscle balance card over
a week / 30d / 90d / all-time window, the routine editor previews what a
session hits while you build it, and the finish screen shows what you
just trained. Settings switches between a male and female figure.

The Stats card's real job is the list underneath: the muscles that got
nothing in the period. Load is counted in effective sets — full weight
for an exercise's target muscle, partial for its supporting ones — not
kilograms, since 100 kg of leg press and 12 kg of lateral raise say
nothing about which muscle worked harder. Shading is relative within the
window, so it always reads as a balance rather than an absolute.

The dataset spells muscles inconsistently ('delts', 'deltoids' and
'shoulders' are one muscle); all 50 spellings it uses are normalised onto
the 18 the diagram draws, verified against the full catalogue so nothing
is dropped silently. Custom exercises fall back to their body part.

Geometry is converted from MuscleMap (MIT, see NOTICE.md), which ships
its paths as Swift source rather than .svg. At ~90 kB it is imported
dynamically, so the initial bundle is unchanged.

Also fixes a crash this surfaced but did not cause: finishing a workout
from its last exercise blanked the whole app, because the per-exercise
weight sheet read the running workout without checking it was still
there and finishing clears it while that sheet is on screen.
This commit is contained in:
Duarte Santos committed 2026-07-23 12:51:24 +02:00
1 parent e9bf38f39b
commit cd77cfdd84
23 files changed
+777 -21

No files matched your search

+20 -8
View File
@@ -13,6 +13,8 @@ import Stepper from './components/Stepper.jsx'
import Icon from './components/Icon.jsx'
import { Button, Slider } from './components/ui.jsx'
import { glyphOf, GLYPH_GROUPS, DEFAULT_GLYPH } from './lib/glyphs.js'
import BodyMap from './components/BodyMap.jsx'
import { loadOfWorkouts } from './lib/muscles.js'
const S = () => useStore.getState().S
const update = (...a) => useStore.getState().update(...a)
@@ -514,17 +516,24 @@ export function beginWorkout(routineId, bw) {
function TopWeight({ entryIdx, close }) {
const st = useStore(s => s.S)
const A = st.active
const entry = A.entries[entryIdx]
const ex = EXIDX[entry.id]
const maxSet = Math.max(0, ...entry.sets.filter(s => s.done).map(s => s.w || 0))
const prevBest = Math.max((st.exWeights[entry.id] || {}).w || 0, bestWeightFor(st, entry.id))
const [v, setV] = useState(Math.max(maxSet, prevBest) || entry.target.weight || 0)
// The workout can end underneath this sheet: finishing from the last exercise clears
// `active`, and this re-renders before the sheet is torn down. Everything below is
// read defensively and the sheet dismisses itself — reading A.entries straight took
// the whole app down with it. Hooks still run unconditionally, so the bail-out has
// to sit after every one of them.
const entry = A ? A.entries[entryIdx] : null
const ex = entry && EXIDX[entry.id]
const maxSet = entry ? Math.max(0, ...entry.sets.filter(s => s.done).map(s => s.w || 0)) : 0
const prevBest = entry ? Math.max((st.exWeights[entry.id] || {}).w || 0, bestWeightFor(st, entry.id)) : 0
const [v, setV] = useState(entry ? (Math.max(maxSet, prevBest) || entry.target.weight || 0) : 0)
useEffect(() => { if (!entry) close() }, [!entry])
const units = supersetUnits(A.entries)
const unit = unitOf(units, entryIdx)
const unitDone = unit.every(i => A.entries[i].sets.every(s => s.done))
const units = supersetUnits(A ? A.entries : [])
const unit = entry ? unitOf(units, entryIdx) : []
const unitDone = !!entry && unit.every(i => A.entries[i].sets.every(s => s.done))
const unitIdx = units.findIndex(u => u === unit)
const isLastUnit = unitIdx === units.length - 1
if (!entry || !ex) return null
const commit = advance => {
const n = Math.round((v || 0) * 10) / 10
@@ -579,6 +588,9 @@ function FinishSummary({ w, prs, close }) {
<div className="tile"><div className="l">{t('PRs')}</div><div className="v" style={{ fontSize: 20 }}>{prs.length || '—'}</div></div>
</div>
{prs.length > 0 && <div style={{ textAlign: 'left', marginBottom: 12 }}>{prs.map(id => <div key={id} className="small accent capitalize row" style={{ gap: 5 }}><Icon name="trophy" style={{ fontSize: 13 }} />{t('New PR:')} {(EXIDX[id] || {}).n || id}</div>)}</div>}
<h4 className="sec" style={{ textAlign: 'left' }}>{t('What you just trained')}</h4>
<BodyMap load={loadOfWorkouts([w])} body={st.body} />
<div style={{ height: 14 }} />
<Button variant="primary" onClick={() => { close(); nav('/home') }}>{t('Nice!')}</Button>
</div>
}