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

+16
View File
@@ -10,6 +10,8 @@ import { glyphPicker, exercisePicker, exConfigSheet, confirmSheet } from '../she
import Icon from '../components/Icon.jsx'
import { glyphOf } from '../lib/glyphs.js'
import { Button } from '../components/ui.jsx'
import BodyMap from '../components/BodyMap.jsx'
import { loadOfRoutine, rankOf, MUSCLE_NAME } from '../lib/muscles.js'
export default function RoutineEdit() {
const nav = useNavigate()
@@ -65,6 +67,20 @@ export default function RoutineEdit() {
</div>
})}</div> : <div className="empty"><div className="ico"><Icon name="dumbbell" /></div>{t('No exercises yet — add your first one.')}</div>}
{/* Coverage of the routine as planned, so a gap shows up while you're building it
rather than after a month of training around it. */}
{r.ex.length > 0 && (() => {
const load = loadOfRoutine(r)
const { worked } = rankOf(load)
return <div className="card" style={{ marginTop: 12 }}>
<h2>{t('What this session hits')}</h2>
<BodyMap load={load} body={S.body} />
<div className="mchips">
{worked.slice(0, 6).map(m => <span key={m} className="mchip">{t(MUSCLE_NAME[m])}</span>)}
</div>
</div>
})()}
<div className="small dim row" style={{ margin: '10px 2px', gap: 5 }}><Icon name="link" style={{ fontSize: 13 }} />{t('Tap the link button on an exercise to superset it with the one above — you’ll do them back-to-back.')}</div>
<Button variant="primary" onClick={() => exercisePicker(ex => exConfigSheet(ex, null, cfg => edit(x => { x.push({ id: ex.id, ...cfg }) })))} icon="plus">{t('Add exercise')}</Button>
<div style={{ height: 10 }} />
+9
View File
@@ -87,6 +87,15 @@ export default function Settings() {
onChange={v => update(s => { s.theme = v })}
/>
</Row>
{/* Purely how the muscle map is drawn — nothing else in the app reads this. */}
<Row icon="figureStrength" iconTint="var(--teal)" title={t('Body diagram')}>
<Segmented
className="seg-inline"
options={[{ value: 'male', label: t('Male') }, { value: 'female', label: t('Female') }]}
value={S.body === 'female' ? 'female' : 'male'}
onChange={v => update(s => { s.body = v })}
/>
</Row>
<div className="lrow" style={{ flexDirection: 'column', alignItems: 'stretch', gap: 12, paddingTop: 13, paddingBottom: 14 }}>
<span className="lrow-t">{t('Accent color')}</span>
<div className="swatches">
+48 -1
View File
@@ -3,14 +3,59 @@ import { useNavigate } from 'react-router-dom'
import { useStore } from '../store/useStore.js'
import { EXIDX, isCardio } from '../lib/exercises.js'
import { bestWeightFor, lastBW, streakWeeks, setLabel } from '../lib/history.js'
import { fmtNum, fmtDate, fmtVol, todayISO } from '../lib/format.js'
import { fmtNum, fmtDate, fmtVol, todayISO, weekKey } from '../lib/format.js'
import { t } from '../lib/i18n.js'
import { bwSheet, goalSheet, calendarSheet, workoutDetailSheet, WorkoutRow, bwDeltaColor } from '../sheets.jsx'
import LineChart from '../components/LineChart.jsx'
import Heatmap from '../components/Heatmap.jsx'
import Icon from '../components/Icon.jsx'
import BodyMap, { BodyMapLegend } from '../components/BodyMap.jsx'
import { loadOfWorkouts, rankOf, MUSCLE_NAME } from '../lib/muscles.js'
import { Button, Segmented, SelectRow } from '../components/ui.jsx'
// Which muscles the training in a window actually hit — and, the point of the card,
// which ones it keeps missing. Shading is relative within the window (lib/muscles.js).
function MuscleBalance({ S }) {
const [win, setWin] = useState(7)
const [sel, setSel] = useState(null)
const now = Date.now()
const inWin = S.workouts.filter(w =>
win === 0 ? true
: win === 7 ? weekKey(w.d) === weekKey(todayISO())
: (w.start || new Date(w.d).getTime()) > now - win * 86400000)
const load = loadOfWorkouts(inWin)
const { worked, missed } = rankOf(load)
const top = worked.slice(0, 4)
const max = worked.length ? load[worked[0]] : 0
const sets = m => Math.round((load[m] || 0) * 10) / 10
return <div className="card">
<h2>{t('Muscle balance')} <span className="dim" style={{ textTransform: 'none', letterSpacing: 0 }}>· {t('by sets worked')}</span></h2>
<Segmented className="seg-range" value={win} onChange={v => { setWin(v); setSel(null) }}
options={[{ value: 7, label: t('Week') }, { value: 30, label: '30d' }, { value: 90, label: '90d' }, { value: 0, label: t('All') }]} />
{inWin.length ? <>
<BodyMap className="tappable" load={load} body={S.body} selected={sel}
onMuscle={m => setSel(s => (s === m ? null : m))} />
<BodyMapLegend />
{sel && <div className="mrow" style={{ borderTop: 'var(--hair) solid var(--sep)', marginTop: 4, paddingTop: 10 }}>
<span className="nm"><b>{t(MUSCLE_NAME[sel])}</b></span>
<span className="v">{sets(sel) ? t('{0} sets', sets(sel)) : t('not trained')}</span>
</div>}
{!sel && top.map(m => <div key={m} className="mrow">
<span className="nm">{t(MUSCLE_NAME[m])}</span>
<span className="bar"><i style={{ width: Math.round(load[m] / max * 100) + '%' }} /></span>
<span className="v">{t('{0} sets', sets(m))}</span>
</div>)}
{missed.length > 0 && <>
<h4 className="sec" style={{ marginTop: 12 }}>{t('Not trained in this period')}</h4>
<div className="mchips">{missed.map(m => <span key={m} className="mchip miss">{t(MUSCLE_NAME[m])}</span>)}</div>
</>}
{!missed.length && worked.length > 0 &&
<div className="muted small" style={{ marginTop: 10 }}>{t('Every muscle group got some work in this period.')}</div>}
</> : <div className="muted small">{t('No workouts in this period yet.')}</div>}
</div>
}
// Stats = the analytics hub: all charts, progress and history live here.
export default function Stats() {
const nav = useNavigate()
@@ -55,6 +100,8 @@ export default function Stats() {
<Heatmap S={S} onDay={iso => { const ws = S.workouts.filter(w => w.d === iso); if (ws.length === 1) workoutDetailSheet(ws[0]); else if (ws.length) calendarSheet(iso) }} />
</div>
{S.workouts.length > 0 && <MuscleBalance S={S} />}
<div className="cols">
<div className="card">
<div className="row between" style={{ marginBottom: 8 }}>