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

+71
View File
@@ -0,0 +1,71 @@
import { useEffect, useState } from 'react'
import { MUSCLES, INERT, MUSCLE_NAME, levelsOf } from '../lib/muscles.js'
import { t } from '../lib/i18n.js'
// Front and back views of a body, each muscle shaded by how hard it was worked.
//
// The five shade steps are the same ones the activity heatmap uses (.hm-c.l0…l4), so
// "more accent = more training" means one thing everywhere in the app rather than two.
//
// The geometry is ~90 KB and only some screens show a map, so it is fetched on first
// render instead of riding along in the main bundle. Until it lands the component
// renders nothing but keeps its height, so nothing below it jumps on arrival.
let CACHE = null // shared across every mounted map
let PENDING = null
function useBodyPaths() {
const [paths, setPaths] = useState(CACHE)
useEffect(() => {
if (CACHE) return
let alive = true
PENDING = PENDING || import('../lib/body-paths.js').then(m => (CACHE = m.default))
PENDING.then(p => { if (alive) setPaths(p) }).catch(() => {})
return () => { alive = false }
}, [])
return paths
}
function View({ view, levels, onMuscle, selected }) {
return (
<svg className="bm-v" viewBox={view.vb} role="img">
{INERT.map(slug => (view.p[slug] || []).map((d, i) =>
<path key={slug + i} className="bm-sil" d={d} />))}
{MUSCLES.map(slug => (view.p[slug] || []).map((d, i) =>
<path
key={slug + i}
className={'bm-m l' + (levels[slug] || 0) + (selected === slug ? ' sel' : '')}
d={d}
onClick={onMuscle ? () => onMuscle(slug) : undefined}
>
<title>{t(MUSCLE_NAME[slug])}</title>
</path>))}
</svg>
)
}
/**
* <BodyMap load={{ chest: 12, … }} body="male" />
* `load` is effective sets per muscle (see lib/muscles.js); shading is relative to
* the hardest-worked muscle in that same load, so it always reads as a balance.
*/
export default function BodyMap({ load = {}, body = 'male', onMuscle, selected, className = '' }) {
const paths = useBodyPaths()
const levels = levelsOf(load)
const g = paths && (paths[body] || paths.male)
return (
<div className={'bodymap ' + className}>
{g ? <>
<View view={g.front} levels={levels} onMuscle={onMuscle} selected={selected} />
<View view={g.back} levels={levels} onMuscle={onMuscle} selected={selected} />
</> : <div className="bm-ph" aria-hidden="true" />}
</div>
)
}
export function BodyMapLegend() {
return <div className="hm-legend">
{t('Less')} <div className="hm-c l0" /><div className="hm-c l1" /><div className="hm-c l2" />
<div className="hm-c l3" /><div className="hm-c l4" /> {t('More')}
</div>
}