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
@@ -0,0 +1,16 @@
// Body geometry — the SVG outlines every muscle map in the app is drawn from.
//
// Converted from MuscleMap by Melih Colpan (MIT), whose path data ships as Swift
// source rather than .svg files; see NOTICE.md. Four views (male/female ×
// front/back), each a viewBox plus one path list per body part. Parts that are
// not muscles — head, hair, neck, hands, feet, knees, ankles — are drawn as the
// silhouette and never take a heat colour; see INERT in lib/muscles.js.
//
// MuscleMap's sub-groups (upper-abs, lower-chest, outer-quad, front-deltoid …)
// are dropped: the exercise dataset resolves to whole muscles, so shading a
// sub-region would imply a precision the data does not have.
//
// ~90 KB, so this module is imported dynamically and only lands in the bundle
// once a muscle map is actually shown. Generated — do not hand-edit.
export default {"male":{"front":{"vb":"0 95 727 1280","p":{"chest":["M272.91 422.84c-18.95-17.19-22-57-12.64-78.79 5.57-12.99 26.54-24.37 39.97-25.87q20.36-2.26 37.02.75c9.74 1.76 16.13 15.64 18.41 25.04 3.99 16.48 3.23 31.38 1.67 48.06q-1.35 14.35-2.05 16.89c-6.52 23.5-38.08 29.23-58.28 24.53-9.12-2.12-17.24-4.38-24.1-10.61z","M416.04 435c-15.12.11-34.46-6.78-41.37-21.48q-1.88-3.99-2.84-12.18c-2.89-24.41-5.9-53.65 8.44-74.79 4.26-6.26 10.49-7.93 18.36-8.56q11.66-.92 23.32-.35c10.58.53 18.02 2.74 26.62 7.87 12.81 7.65 19.73 14.52 22.67 29.75 4.94 25.57.24 64.14-28.21 74.97q-12.26 4.67-26.99 4.77z"],"abs":["M311.02 531.71a.23.23 0 01-.19-.21q-.39-10.47 1.9-20.76c1.26-5.69 7.66-9.9 13.1-12.9 9.09-5.01 18.93-11.15 28.56-14.92a1.24 1.21-42.6 01.94.03c3.28 1.52 4.78 3.87 4.82 7.68q.13 13.16-.15 26.31c-.08 3.85.78 8.39-.87 13.1q-.17.46-.59.72-2.65 1.65-4.29 1.82-21.06 2.22-43.23-.87z","M321 577.76c-5.17-.33-8.71-.44-10-6.26q-3.2-14.44-.59-27.83.11-.53.64-.63c7.58-1.44 13.62-2.45 22.45-4.56q11.5-2.76 23.94-1.88c3.67.26 3.3 3.46 3.4 6.21q.46 12.55-.33 26.94-.25 4.41-1.81 8.08-.21.49-.73.6-1.39.28-3.22.29-16.89.14-33.75-.96z","M347.73 429.25c7.46-3.61 10.5 6.27 10.99 11.52.48 5.06 3.46 30.61-2.78 32.93q-4.17 1.55-6.89 3.33-17.56 11.54-35.88 21.46a1.6 1.59-21.9 01-2.3-.98c-2.87-10.41-10.59-43.96 1.66-50.95 11.3-6.45 23.96-11.86 35.2-17.31z","M350.35 712.81c-29.15-9.93-37.98-100.69-39.47-126.61a.99.99 0 01.33-.8c3.58-3.26 27.61-1.47 34.62-.93 4.41.34 15.27 1.31 15.26 7.53-.05 40.77.64 82.05-1.96 122.72a1.29 1.29 0 01-1.86 1.08c-2.3-1.14-4.12-2.04-6.92-2.99z","M371.94 473.31c-5.46-2.59-2.97-24.26-2.77-29.56.25-6.8 2.41-18.63 12.64-13.8q16.26 7.67 32.34 15.72 6.18 3.1 7.13 10.05c.58 4.26 1.35 8.49 1.07 12.72q-.84 12.55-4.33 26.56-.54 2.16-1.1 3.44-.25.58-.81.31c-15.78-7.29-30.79-19.08-44.17-25.44z","M382.57 533.27c-4.17-.18-9.56-.3-13.15-2.69q-.17-.11-.24-.31c-1.82-5.55-.86-11.17-.96-15.66-.18-8.4-.78-17.36.06-25.71.29-2.85 1.88-4.42 4.15-5.79q.42-.26.91-.19 1.71.25 3.21 1.03 12.48 6.44 24.75 13.26c4.96 2.75 12.21 7.02 13.72 12.41q2.93 10.56 2.39 21.49a.77.76-1.8 01-.67.71q-16.89 2.18-34.17 1.45z","M373.75 578.69c-2.47 0-4.31.22-5-2.7-1.8-7.7-3.05-34.29-.19-38.81q.27-.43.77-.47 13.14-1.24 25.77 1.83c8.41 2.04 14.51 3.01 21.85 4.36a1.29 1.28.6 011.05 1.07q2.16 14.12-.73 28.07c-1.08 5.24-5.22 5.26-10.36 5.63q-14.26 1.04-33.16 1.02z","M416.32 584.73q1.14.41 1.07 1.62c-1.62 26.44-9.96 116.68-40.43 126.74-2.27.75-4.15 2.12-6.35 2.73q-1.18.33-1.3-.89-.86-9.2-1.06-17.75c-.83-35.67-.91-71.2-1.01-106.88q0-.5.31-.89c4.95-6.46 41.69-7.25 48.77-4.68z"],"biceps":["M189.52 492.51c-2.43.62-7.38.57-7.51-3.08-.56-16.01-.42-35.49 5.11-50.26 3.19-8.54 13.89-30.22 23.27-32.72 10.08-2.68 12.68 16.59 12.6 22.8-.22 15.98-7.51 34.79-15.05 48.71-4.29 7.94-9.95 12.38-18.42 14.55z","M526.69 486.31c-9.9-8.61-17.75-33.21-20.65-47.73-1.41-7.06-1.34-29.61 8.58-32.16 10.33-2.66 23.81 25.34 26.6 32.91q2.6 7.04 3.6 16.13 1.62 14.66 1.66 32.28c.03 11.04-16.45 1.48-19.79-1.43z"],"triceps":["M206.2 514.2c-5.41-.67-6.55-7.29-4.69-11.42 11.08-24.55 22.84-50.62 30.54-75.51 1.37-4.41 3.08-8.59 3.95-12.45q2.94-13.12 5.79-26.26.42-1.98 1.82-3.39a.52.52 0 01.81.1q1.04 1.69 1.94 4.56 4.63 14.65 5.15 24.92c.57 11.36-5.11 24.55-8.65 35.5q-7.69 23.78-20.25 45.39c-2.45 4.23-11.51 19.18-16.41 18.56z","M517.69 512.06c-20.07-22.12-28.95-51.73-38.01-79.03-3.27-9.87-3.58-19.18-1.34-29.38 1.29-5.88 2.49-13.03 5.61-18.52q.32-.57.72-.06 1.35 1.67 1.79 3.69c2.67 12.33 5.14 24.49 9.07 36.52 8.25 25.28 18.58 49.8 31.1 77.2q1.42 3.1 1.05 5.33c-.81 4.89-5.46 9.25-9.99 4.25z"],"deltoids":["M274.06 311.69q3.94 2.77 4.33 8.14.04.48-.38.73c-9.98 5.88-24.35 7.45-28.82 19.75-2.31 6.36-.97 17.35-1.43 23.68q-.55 7.51-5.73 14.07-10.37 13.11-13.81 16.67c-3.41 3.53-6.81 1.76-10.69-.47-15.42-8.87-24.95-25.45-22.52-43.22 2.05-14.92 12.71-25.79 24.06-35.02 16.99-13.82 35.58-17.99 54.99-4.33z","M450.39 320.75q-.95-.52-.7-1.58c1.57-6.61 5.8-9.1 12.14-11.9 24.99-11.03 43.76 3.33 60.17 20.74 20.73 21.99 11.81 56.44-14.82 68.19-4.41 1.94-6.79-1.03-9.81-4.51-5.81-6.7-13.46-14.12-15.99-22.8-3.93-13.43 4.32-27.54-9.64-37.62q-8.22-5.93-17.99-9.08-1.84-.59-3.36-1.44z"],"obliques":["M264.21 435.53c-4.88-3.13-5.75-12.11-5.39-17.36q.03-.53.51-.75 1.8-.84 3.43.85 10.05 10.45 22.57 16.9c3.64 1.89 5.54 3.62 4.79 7.8q-.42 2.35-2.82 1.87-12.45-2.49-23.09-9.31z","M287.33 452.44c-4.05 4.46-10.38 11.38-16.28 14.3a.84.83 51.1 01-.9-.1c-6.29-5.17-12.54-18.97-14.21-25.09q-.91-3.34.85-8.81.12-.39.35-.05c2.41 3.65 4.59 7.74 8.67 9.76q10.18 5.05 21.27 9.01a.61.61 0 01.25.98z","M297.3 487.82c-7.36-4.23-16.68-11.37-20.55-17.57q-.32-.5.09-.92 8.72-9.04 19.84-17.87 1.46-1.17 2.81-1.67a.44.44 0 01.59.43c-.28 10.08-.4 20.42.65 30.43q.34 3.26-.68 6.15a1.9 1.9 0 01-2.75 1.02z","M257.35 456.18l13.68 16.63a1.86 1.82 22.9 01.4.95c.59 5.4-2.02 12.71-3.8 17.56q-.3.84-.84.13-11.85-15.55-9.77-35.17.04-.45.33-.1z","M271.69 494.07a1.53 1.52-61.8 01-.49-1.64l4.2-13.58a.98.98 0 011.51-.5c3.2 2.32 21.89 14.05 22.26 16.7q1.15 8.32.66 16.79aLine truncated
+136
View File
@@ -0,0 +1,136 @@
// Which muscles an exercise trains, and how hard — the data behind every muscle map.
//
// The exercise dataset names muscles in free text and is not consistent about it:
// "shoulders", "deltoids" and "delts" are the same thing, so are "quads" and
// "quadriceps", "lats" and "latissimus dorsi", "core" and "abdominals". Nineteen
// primary and forty secondary spellings collapse onto the eighteen muscles the body
// map can actually draw, via ALIAS below. Anything genuinely undrawable (hands,
// ankles, "cardiovascular system") maps to null and is dropped rather than guessed at.
import { EXIDX } from './exercises.js'
// The muscles a map can shade, in head-to-toe order — also the order of any list
// built from them, so "what am I neglecting" reads top-down like a body.
export const MUSCLES = [
'trapezius', 'deltoids', 'chest', 'upper-back', 'serratus',
'biceps', 'triceps', 'forearm',
'abs', 'obliques', 'lower-back',
'gluteal', 'quadriceps', 'hamstring', 'adductors', 'hip-flexors',
'calves', 'tibialis',
]
// Drawn as the silhouette, never shaded: they carry no training load.
export const INERT = ['head', 'hair', 'neck', 'hands', 'feet', 'knees', 'ankles']
// English display names; these strings are the i18n keys (see lib/i18n.js).
export const MUSCLE_NAME = {
trapezius: 'Traps', deltoids: 'Shoulders', chest: 'Chest', 'upper-back': 'Upper back',
serratus: 'Serratus', biceps: 'Biceps', triceps: 'Triceps', forearm: 'Forearms',
abs: 'Abs', obliques: 'Obliques', 'lower-back': 'Lower back', gluteal: 'Glutes',
quadriceps: 'Quads', hamstring: 'Hamstrings', adductors: 'Adductors',
'hip-flexors': 'Hip flexors', calves: 'Calves', tibialis: 'Shins',
}
// Every spelling that occurs in the dataset's `tg` and `sm` fields. null = not drawable.
const ALIAS = {
// primaries
abs: 'abs', pectorals: 'chest', biceps: 'biceps', glutes: 'gluteal', delts: 'deltoids',
triceps: 'triceps', 'upper back': 'upper-back', lats: 'upper-back', calves: 'calves',
quads: 'quadriceps', forearms: 'forearm', hamstrings: 'hamstring', spine: 'lower-back',
traps: 'trapezius', adductors: 'adductors', 'serratus anterior': 'serratus',
abductors: 'gluteal', 'levator scapulae': 'trapezius', 'cardiovascular system': null,
// secondaries
shoulders: 'deltoids', deltoids: 'deltoids', 'rear deltoids': 'deltoids',
'rotator cuff': 'deltoids', quadriceps: 'quadriceps', core: 'abs', abdominals: 'abs',
'lower abs': 'abs', chest: 'chest', 'upper chest': 'chest', 'hip flexors': 'hip-flexors',
obliques: 'obliques', 'lower back': 'lower-back', rhomboids: 'upper-back',
trapezius: 'trapezius', back: 'upper-back', 'latissimus dorsi': 'upper-back',
brachialis: 'biceps', soleus: 'calves', shins: 'tibialis', wrists: 'forearm',
'wrist flexors': 'forearm', 'wrist extensors': 'forearm', 'grip muscles': 'forearm',
groin: 'adductors', 'inner thighs': 'adductors',
ankles: null, feet: null, hands: null, 'ankle stabilizers': null,
sternocleidomastoid: null,
}
// Custom exercises carry only a body part, so they fall back to it. Weights inside a
// group sum to 1 — "upper legs" spreads over three muscles rather than counting triple.
const BY_BODYPART = {
chest: { chest: 1 },
back: { 'upper-back': 0.75, 'lower-back': 0.25 },
shoulders: { deltoids: 1 },
'upper arms': { biceps: 0.5, triceps: 0.5 },
'lower arms': { forearm: 1 },
waist: { abs: 0.7, obliques: 0.3 },
'upper legs': { quadriceps: 0.4, hamstring: 0.35, gluteal: 0.25 },
'lower legs': { calves: 0.8, tibialis: 0.2 },
neck: { trapezius: 1 },
cardio: {},
}
const SECONDARY = 0.4 // a supporting muscle counts this much against a primary
/** Muscles one exercise trains: { slug: 0…1 }. */
export function musclesOf(ex) {
if (!ex) return {}
const out = {}
const add = (name, w) => {
const slug = ALIAS[String(name || '').toLowerCase().trim()]
if (slug) out[slug] = Math.max(out[slug] || 0, w)
}
add(ex.tg, 1)
;(ex.sm || []).forEach(m => add(m, SECONDARY))
// Nothing recognised (custom exercises, or a target we don't draw) — use the body part.
if (!Object.keys(out).length) Object.assign(out, BY_BODYPART[ex.bp] || {})
return out
}
/**
* Training load per muscle, in "effective sets".
* `items` is [{ id, sets }] — sets being a count, so a 4×8 bench press weighs four
* times a single set. Volume in kg is deliberately not used: 100 kg of leg press
* against 12 kg of lateral raise says nothing about which muscle worked harder.
*/
export function loadOf(items) {
const load = {}
items.forEach(({ id, sets }) => {
if (!sets) return
const m = musclesOf(EXIDX[id])
for (const slug in m) load[slug] = (load[slug] || 0) + m[slug] * sets
})
return load
}
/** Load for finished workouts (only sets actually ticked off count). */
export const loadOfWorkouts = workouts =>
loadOf((workouts || []).flatMap(w =>
(w.entries || []).map(e => ({ id: e.id, sets: (e.sets || []).filter(s => s.done).length }))))
/** Load a routine *would* produce, from its planned set counts. */
export const loadOfRoutine = routine =>
loadOf((routine?.ex || []).map(c => ({ id: c.id, sets: c.sets || 1 })))
/** Load for a workout still in progress — the sets ticked so far. */
export const loadOfActive = active =>
loadOf((active?.entries || []).map(e => ({ id: e.id, sets: (e.sets || []).filter(s => s.done).length })))
/**
* Shade buckets 0–4 per muscle, relative to the hardest-worked muscle in the same
* window. Relative rather than absolute on purpose: the map answers "is my training
* balanced", which only means anything as a comparison within one period.
*/
export function levelsOf(load) {
const max = Math.max(0, ...MUSCLES.map(m => load[m] || 0))
const lv = {}
MUSCLES.forEach(m => {
const v = load[m] || 0
lv[m] = !v ? 0 : max <= 0 ? 0 : Math.max(1, Math.min(4, Math.ceil(v / max * 4)))
})
return lv
}
/** Muscles sorted hardest-worked first; untrained ones last, in body order. */
export function rankOf(load) {
const worked = MUSCLES.filter(m => (load[m] || 0) > 0).sort((a, b) => load[b] - load[a])
const missed = MUSCLES.filter(m => !(load[m] > 0))
return { worked, missed }
}