Skip to content

Open-source gym & body-weight tracker, now in the App Store (iPhone + Apple Watch) and as an Android APK. Plan routines, log workouts, see which muscles are trained, import from Strong/Hevy/FitNotes. Self-host it or use it on the phone alone.

feat: switch activity heatmap between time and volume

Space-Hermes6d004214c440
diff --git a/frontend/src/components/Heatmap.jsx b/frontend/src/components/Heatmap.jsx
index 03c617927..cb672c255 100644
--- a/frontend/src/components/Heatmap.jsx
+++ b/frontend/src/components/Heatmap.jsx
@@ -1,23 +1,48 @@
-import { useEffect, useRef } from 'react'
+import { useEffect, useRef, useState } from 'react'
import { fmtVol, isoOf, todayISO, MONTHS } from '../lib/format.js'
+import { workoutDay, workoutDuration, workoutVolume } from '../lib/history.js'
import { t } from '../lib/i18n.js'
import { tappable } from '../lib/use-sheet-keyboard.js'
+import { Segmented } from './ui.jsx'
-// GitHub-style activity heatmap, shaded by time trained per day.
-export default function Heatmap({ S, onDay }) {
+const normalizeMetric = value => value === 'vol' ? 'vol' : 'time'
+
+// Legacy records without entries only have the cached volume available. Current records are
+// always recomputed from their completed sets so unit changes and warm-up/per-side rules stay
+// authoritative.
+const volumeOf = w => {
+ if (Array.isArray(w?.entries)) return Math.max(0, Number(workoutVolume(w)) || 0)
+ const volume = Number(w?.vol)
+ return Number.isFinite(volume) ? Math.max(0, volume) : 0
+}
+
+// GitHub-style activity heatmap, shaded by the selected time or volume metric per day.
+export default function Heatmap({ S, onDay, metric: selectedMetric, onMetricChange }) {
const wrapRef = useRef(null)
+ const [localMetric, setLocalMetric] = useState(() => normalizeMetric(selectedMetric ?? S?.heatmapMetric))
useEffect(() => { if (wrapRef.current) wrapRef.current.scrollLeft = wrapRef.current.scrollWidth }, [])
+ const metric = normalizeMetric(selectedMetric ?? localMetric)
+ const metricValue = metric === 'vol' ? 'vol' : 'min'
+ const changeMetric = value => {
+ const next = normalizeMetric(value)
+ if (selectedMetric == null) setLocalMetric(next)
+ onMetricChange?.(next)
+ }
+
const agg = {}
- S.workouts.forEach(w => {
- const a = agg[w.d] = agg[w.d] || { n: 0, vol: 0, min: 0 }
- a.n++; a.vol += w.vol || 0
- a.min += Math.max(0, Math.round(((w.end || w.start) - w.start) / 60000))
+ ;(S.workouts || []).forEach(w => {
+ const day = workoutDay(w)
+ if (!day) return
+ const a = agg[day] = agg[day] || { n: 0, vol: 0, min: 0 }
+ a.n++
+ a.vol += volumeOf(w)
+ a.min += Math.max(0, Math.round(workoutDuration(w) / 60000))
})
- const mins = Object.values(agg).map(a => a.min).filter(v => v > 0).sort((a, b) => a - b)
- const q = p => (mins.length ? mins[Math.min(mins.length - 1, Math.floor(p * mins.length))] : 0)
+ const values = Object.values(agg).map(a => a[metricValue]).filter(v => v > 0).sort((a, b) => a - b)
+ const q = p => (values.length ? values[Math.min(values.length - 1, Math.floor(p * values.length))] : 0)
const t1 = q(0.25), t2 = q(0.5), t3 = q(0.75)
- const level = a => !a ? 0 : !a.min ? 1 : a.min >= t3 ? 4 : a.min >= t2 ? 3 : a.min >= t1 ? 2 : 1
+ const level = a => !a ? 0 : !a[metricValue] ? 1 : a[metricValue] >= t3 ? 4 : a[metricValue] >= t2 ? 3 : a[metricValue] >= t1 ? 2 : 1
const today = new Date(); today.setHours(12, 0, 0, 0)
const end = new Date(today); end.setDate(today.getDate() - ((today.getDay() + 6) % 7))
@@ -39,12 +64,14 @@ export default function Heatmap({ S, onDay }) {
const cls = 'hm-c l' + level(a) + (key === todayISO() ? ' today' : '') + (day > today ? ' future' : '')
cells.push(<div key={d} className={cls}
title={key + (a ? ` · ${t(a.n === 1 ? '{0} workout' : '{0} workouts', a.n)} · ${a.min} min · ${fmtVol(a.vol, S.unit)}` : '')}
- {...tappable(a ? () => onDay(key) : undefined)} />)
+ {...tappable(a ? () => onDay?.(key) : undefined)} />)
}
cols.push(<div key={wk} className="hm-col">{cells}</div>)
}
return <>
+ <Segmented value={metric} onChange={changeMetric}
+ options={[{ value: 'time', label: t('Time') }, { value: 'vol', label: t('Volume') }]} />
<div className="hm-wrap" ref={wrapRef}>
<div className="hm-months" style={{ marginLeft: 30 }}>{months}</div>
<div className="hm-body">
@@ -52,6 +79,6 @@ export default function Heatmap({ S, onDay }) {
<div className="hm-grid">{cols}</div>
</div>
</div>
- <div className="hm-legend">{t('Less time')} <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 time')}</div>
+ <div className="hm-legend">{t(metric === 'vol' ? 'Less volume' : 'Less time')} <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(metric === 'vol' ? 'More volume' : 'More time')}</div>
</>
}
diff --git a/frontend/src/components/Heatmap.test.jsx b/frontend/src/components/Heatmap.test.jsx
new file mode 100644
index 000000000..0ce9bd6b0
--- /dev/null
+++ b/frontend/src/components/Heatmap.test.jsx
@@ -0,0 +1,68 @@
+// @vitest-environment happy-dom
+import React, { act } from 'react'
+import { createRoot } from 'react-dom/client'
+import { afterEach, expect, it, vi } from 'vitest'
+import Heatmap from './Heatmap.jsx'
+import { isoOf } from '../lib/format.js'
+import { workoutDay } from '../lib/history.js'
+
+let root, host
+globalThis.IS_REACT_ACT_ENVIRONMENT = true
+afterEach(() => { act(() => root?.unmount()); host?.remove() })
+
+it('changes shading and legend by metric while retaining day actions and history', () => {
+ const now = new Date(), workouts = [1, 2, 3, 4].map((n, i) => {
+ const d = new Date(now); d.setDate(d.getDate() - n)
+ return { d: isoOf(d), start: +d, end: +d + n * 60000, vol: (4 - i) * 100 }
+ })
+ const S = { workouts, unit: 'kg' }, before = structuredClone(S), onDay = vi.fn(), onMetricChange = vi.fn()
+ host = document.createElement('div'); document.body.appendChild(host); root = createRoot(host)
+ act(() => root.render(<Heatmap S={S} onDay={onDay} onMetricChange={onMetricChange} />))
+ const first = () => [...host.querySelectorAll('.hm-c[title]')].find(e => e.title.startsWith(workouts[0].d))
+ expect(first().classList.contains('l1')).toBe(true)
+ act(() => [...host.querySelectorAll('button')].find(e => e.textContent === 'Volume').click())
+ expect(first().classList.contains('l4')).toBe(true); expect(host.textContent).toContain('More volume')
+ expect(onMetricChange).toHaveBeenCalledWith('vol')
+ act(() => first().click()); expect(onDay).toHaveBeenCalledWith(workouts[0].d)
+ expect(S).toEqual(before)
+})
+
+it('uses the local session day and canonical completed volume', () => {
+ const start = new Date(); start.setDate(start.getDate() - 1); start.setHours(8, 0, 0, 0)
+ const day = isoOf(start)
+ const workout = {
+ d: 'not-a-day', start: +start, end: +start + 15 * 60000, vol: 999,
+ entries: [{ sets: [
+ { w: 100, r: 10, done: true, phase: 'warmup' },
+ { w: 14, r: 16, done: true, sides: {
+ L: { w: 14, r: 10, done: true }, R: { w: 12.5, r: 6, done: true },
+ } },
+ ] }],
+ }
+ expect(workoutDay(workout)).toBe(day)
+ host = document.createElement('div'); document.body.appendChild(host); root = createRoot(host)
+ act(() => root.render(<Heatmap S={{ workouts: [workout], unit: 'lb' }} />))
+ const cell = () => [...host.querySelectorAll('.hm-c[title]')].find(e => e.title.startsWith(day))
+ expect(cell().title).toContain('15 min · 215 lb')
+ act(() => [...host.querySelectorAll('button')].find(e => e.textContent === 'Volume').click())
+ expect(cell().classList.contains('l4')).toBe(true)
+})
+
+it('keeps a valid saved day ahead of a mismatched timestamp', () => {
+ const timestamp = new Date(); timestamp.setDate(timestamp.getDate() - 2)
+ const savedDay = isoOf(new Date(timestamp)); timestamp.setDate(timestamp.getDate() - 1)
+ expect(workoutDay({ d: savedDay, start: +timestamp })).toBe(savedDay)
+})
+
+it('leaves malformed history out of the activity map', () => {
+ host = document.createElement('div'); document.body.appendChild(host); root = createRoot(host)
+ act(() => root.render(<Heatmap S={{ workouts: [{ d: 'not-a-day', start: NaN, end: NaN, vol: 100 }], unit: 'kg' }} />))
+ expect(host.querySelectorAll('.hm-grid .hm-c:not(.l0)')).toHaveLength(0)
+})
+
+it('honors a saved volume preference on the next render', () => {
+ host = document.createElement('div'); document.body.appendChild(host); root = createRoot(host)
+ act(() => root.render(<Heatmap S={{ workouts: [], unit: 'kg', heatmapMetric: 'vol' }} />))
+ expect(host.textContent).toContain('More volume')
+ expect([...host.querySelectorAll('button')].find(e => e.textContent === 'Volume').getAttribute('aria-pressed')).toBe('true')
+})
diff --git a/frontend/src/lib/history.js b/frontend/src/lib/history.js
index ce3e19b89..68e33c372 100644
--- a/frontend/src/lib/history.js
+++ b/frontend/src/lib/history.js
@@ -503,11 +503,43 @@ export function workoutVolume(w) {
// A per-side row's mirror is `w = max(L, R), r = L + R` (workout-model syncSideAggregate) —
// right for a headline, wrong for a product: 14×10 left and 12.5×6 right is 215, not 14×16.
// Each side is its own weight × reps, with its own drops and bursts.
- w.entries.forEach(e => e.sets.forEach(s => {
+ ;(Array.isArray(w?.entries) ? w.entries : []).forEach(e => (Array.isArray(e?.sets) ? e.sets : []).forEach(s => {
if (!isWarmupRow(s)) v += completedVolumeOf(s)
}))
return v
}
+// Finished sessions carry their canonical local calendar day in `d`. Keep it aligned with
+// History/calendar readers, and use the local start timestamp only for older records whose date
+// is missing or malformed. Invalid records stay out of the activity map.
+const timestampOf = value => {
+ if (typeof value === 'number') return Number.isFinite(value) ? value : null
+ if (typeof value === 'string' && value.trim()) {
+ const n = Number(value)
+ return Number.isFinite(n) ? n : null
+ }
+ return null
+}
+export function workoutDay(w) {
+ const day = String(w?.d || '')
+ if (/^\d{4}-\d{2}-\d{2}$/.test(day)) {
+ const date = new Date(day + 'T12:00:00')
+ if (isoOf(date) === day) return day
+ }
+ const start = timestampOf(w?.start)
+ if (start !== null) {
+ const date = new Date(start)
+ if (!Number.isNaN(date.getTime())) return isoOf(date)
+ }
+ return null
+}
+
+// Duration is derived from the completed session timestamps rather than a cached display value.
+export function workoutDuration(w) {
+ const start = timestampOf(w?.start)
+ const end = timestampOf(w?.end)
+ return start !== null && end !== null ? Math.max(0, end - start) : 0
+}
+
// A unilateral row counts as two toward the "x / y sets" progress — one per side — since each
// side is logged and ticked on its own (issue #60). Every other row counts as one.
export const setUnits = s => (isSideSet(s) ? 2 : 1)
diff --git a/frontend/src/lib/pt-br-locale.test.js b/frontend/src/lib/pt-br-locale.test.js
index f692c6095..c5a0f6b4a 100644
--- a/frontend/src/lib/pt-br-locale.test.js
+++ b/frontend/src/lib/pt-br-locale.test.js
@@ -28,10 +28,10 @@ describe('Brazilian Portuguese locale', () => {
const fingerprint = createHash('sha256').update(JSON.stringify(inherited)).digest('hex')
expect(Object.keys(PT_BR_OVERRIDES)).toHaveLength(644)
- expect(inherited).toHaveLength(647)
+ expect(inherited).toHaveLength(649)
// If this fails, review the changed keys and wording before accepting a new hash. From
// frontend/: node scripts/pt-br-inheritance-fingerprint.mjs --list
- expect(fingerprint, 'pt-PT inheritance changed; review the inherited pt-BR wording').toBe('185cca3dfbc438a4a2177956d1d18da2bbdc907281c5eb4c858ba34afaf9f38e')
+ expect(fingerprint, 'pt-PT inheritance changed; review the inherited pt-BR wording').toBe('b67cc1616ce4f805dba8c87315bb47a7ea28e1cc8a468ed9395b9fe378d0c848')
})
test('does not leak European Portuguese UI terms', () => {
diff --git a/frontend/src/locales/de.js b/frontend/src/locales/de.js
index fad9cba71..bf8daf4a0 100644
--- a/frontend/src/locales/de.js
+++ b/frontend/src/locales/de.js
@@ -262,6 +262,8 @@ export default {
'Recent workouts': 'Letzte Trainings',
'Less time': 'Weniger',
'More time': 'Mehr',
+ 'Less volume': 'Weniger Volumen',
+ 'More volume': 'Mehr Volumen',
'No data yet': 'Noch keine Daten',
// --- plan view ---
'Your weekly routine': 'Deine Wochenroutine',
diff --git a/frontend/src/locales/es.js b/frontend/src/locales/es.js
index 68e2144a4..4dc0ff737 100644
--- a/frontend/src/locales/es.js
+++ b/frontend/src/locales/es.js
@@ -252,6 +252,8 @@ export default {
'Recent workouts': 'Entrenamientos recientes',
'Less time': 'Menos',
'More time': 'Más',
+ 'Less volume': 'Menos volumen',
+ 'More volume': 'Más volumen',
'No data yet': 'Aún sin datos',
'Your weekly routine': 'Tu rutina semanal',
'Week schedule': 'Horario semanal',
diff --git a/frontend/src/locales/fr.js b/frontend/src/locales/fr.js
index ff4b17cfd..f424474bc 100644
--- a/frontend/src/locales/fr.js
+++ b/frontend/src/locales/fr.js
@@ -252,6 +252,8 @@ export default {
'Recent workouts': 'Séances récentes',
'Less time': 'Moins',
'More time': 'Plus',
+ 'Less volume': 'Moins de volume',
+ 'More volume': 'Plus de volume',
'No data yet': 'Pas encore de données',
'Your weekly routine': 'Ta routine hebdomadaire',
'Week schedule': 'Planning de la semaine',
diff --git a/frontend/src/locales/hi.js b/frontend/src/locales/hi.js
index da466b3f2..f939ad2fe 100644
--- a/frontend/src/locales/hi.js
+++ b/frontend/src/locales/hi.js
@@ -252,6 +252,8 @@ export default {
'Recent workouts': 'हाल के वर्कआउट',
'Less time': 'कम',
'More time': 'ज़्यादा',
+ 'Less volume': 'कम वॉल्यूम',
+ 'More volume': 'ज़्यादा वॉल्यूम',
'No data yet': 'अभी डेटा नहीं',
'Your weekly routine': 'आपका साप्ताहिक रूटीन',
'Week schedule': 'हफ़्ते का कार्यक्रम',
diff --git a/frontend/src/locales/hu.js b/frontend/src/locales/hu.js
index f99fa4ff9..a0eee2e47 100644
--- a/frontend/src/locales/hu.js
+++ b/frontend/src/locales/hu.js
@@ -253,6 +253,8 @@ export default {
'Recent workouts': 'Legutóbbi edzések',
'Less time': 'Kevesebb',
'More time': 'Több',
+ 'Less volume': 'Kevesebb volumen',
+ 'More volume': 'Több volumen',
'No data yet': 'Még nincs adat',
// --- plan view ---
'Your weekly routine': 'A heti rutinod',
diff --git a/frontend/src/locales/it.js b/frontend/src/locales/it.js
index 3c8c8415f..693c5fe51 100644
--- a/frontend/src/locales/it.js
+++ b/frontend/src/locales/it.js
@@ -252,6 +252,8 @@ export default {
'Recent workouts': 'Allenamenti recenti',
'Less time': 'Meno',
'More time': 'Più',
+ 'Less volume': 'Meno volume',
+ 'More volume': 'Più volume',
'No data yet': 'Ancora nessun dato',
'Your weekly routine': 'La tua routine settimanale',
'Week schedule': 'Programma settimanale',
diff --git a/frontend/src/locales/ko.js b/frontend/src/locales/ko.js
index 48ea492ff..24593b430 100644
--- a/frontend/src/locales/ko.js
+++ b/frontend/src/locales/ko.js
@@ -252,6 +252,8 @@ export default {
'Recent workouts': '최근 운동',
'Less time': '적음',
'More time': '많음',
+ 'Less volume': '적은 볼륨',
+ 'More volume': '많은 볼륨',
'No data yet': '데이터 없음',
'Your weekly routine': '주간 루틴',
'Week schedule': '주간 일정',
diff --git a/frontend/src/locales/pl.js b/frontend/src/locales/pl.js
index 213baab72..f9747e1a1 100644
--- a/frontend/src/locales/pl.js
+++ b/frontend/src/locales/pl.js
@@ -252,6 +252,8 @@ export default {
'Recent workouts': 'Ostatnie treningi',
'Less time': 'Mniej',
'More time': 'Więcej',
+ 'Less volume': 'Mniejsza objętość',
+ 'More volume': 'Większa objętość',
'No data yet': 'Brak danych',
'Your weekly routine': 'Twój plan tygodnia',
'Week schedule': 'Harmonogram tygodnia',
diff --git a/frontend/src/locales/pt.js b/frontend/src/locales/pt.js
index ea44d465c..6c26e5f98 100644
--- a/frontend/src/locales/pt.js
+++ b/frontend/src/locales/pt.js
@@ -252,6 +252,8 @@ export default {
'Recent workouts': 'Treinos recentes',
'Less time': 'Menos',
'More time': 'Mais',
+ 'Less volume': 'Menos volume',
+ 'More volume': 'Mais volume',
'No data yet': 'Ainda sem dados',
'Your weekly routine': 'A tua rotina semanal',
'Week schedule': 'Horário semanal',
diff --git a/frontend/src/locales/ru.js b/frontend/src/locales/ru.js
index 46ce8efb2..d052a46b0 100644
--- a/frontend/src/locales/ru.js
+++ b/frontend/src/locales/ru.js
@@ -252,6 +252,8 @@ export default {
'Recent workouts': 'Недавние тренировки',
'Less time': 'Меньше',
'More time': 'Больше',
+ 'Less volume': 'Меньше объёма',
+ 'More volume': 'Больше объёма',
'No data yet': 'Данных пока нет',
'Your weekly routine': 'Твой недельный план',
'Week schedule': 'Расписание недели',
diff --git a/frontend/src/locales/th.js b/frontend/src/locales/th.js
index f2b372dbd..ed227c89d 100644
--- a/frontend/src/locales/th.js
+++ b/frontend/src/locales/th.js
@@ -253,6 +253,8 @@ export default {
'Recent workouts': 'การออกกำลังกายล่าสุด',
'Less time': 'เวลาน้อย',
'More time': 'เวลามาก',
+ 'Less volume': 'ปริมาณน้อย',
+ 'More volume': 'ปริมาณมาก',
'No data yet': 'ยังไม่มีข้อมูล',
// --- plan view ---
'Your weekly routine': 'รูทีนรายสัปดาห์ของคุณ',
diff --git a/frontend/src/locales/tr.js b/frontend/src/locales/tr.js
index 95720d15e..ec851b812 100644
--- a/frontend/src/locales/tr.js
+++ b/frontend/src/locales/tr.js
@@ -252,6 +252,8 @@ export default {
'Recent workouts': 'Son antrenmanlar',
'Less time': 'Az',
'More time': 'Çok',
+ 'Less volume': 'Daha az hacim',
+ 'More volume': 'Daha çok hacim',
'No data yet': 'Henüz veri yok',
'Your weekly routine': 'Haftalık rutinin',
'Week schedule': 'Hafta programı',
diff --git a/frontend/src/locales/zh.js b/frontend/src/locales/zh.js
index f45110eec..17fdd3aec 100644
--- a/frontend/src/locales/zh.js
+++ b/frontend/src/locales/zh.js
@@ -252,6 +252,8 @@ export default {
'Recent workouts': '最近训练',
'Less time': '少',
'More time': '多',
+ 'Less volume': '较少总量',
+ 'More volume': '较多总量',
'No data yet': '暂无数据',
'Your weekly routine': '你的每周安排',
'Week schedule': '每周日程',
diff --git a/frontend/src/store/useStore.js b/frontend/src/store/useStore.js
index 79451dfd8..7e25d500b 100644
--- a/frontend/src/store/useStore.js
+++ b/frontend/src/store/useStore.js
@@ -25,6 +25,8 @@ export const DEF = {
theme: 'dark', accent: 'lime', body: 'male', targetW: null,
bodyweight: [], routines: [], week: {}, dayPlan: {},
exWeights: {}, workouts: [], active: null, customEx: [], gifSize: 'full',
+ // Stats activity heatmap metric. Profiles without this key continue to open on time.
+ heatmapMetric: 'time',
// How the active workout is laid out — 'cards' (one exercise at a time with Prev/Next),
// 'list' (every exercise stacked and scrollable) or 'compact' (that stack stripped to just
// names and set rows — no media, tags, notes, last-time or progression line). Purely
@@ -612,4 +614,4 @@ export const useStore = create((set, get) => {
}
})
-export { hasData }
\ No newline at end of file
+export { hasData }
diff --git a/frontend/src/views/Stats.jsx b/frontend/src/views/Stats.jsx
index 636e26640..17c432565 100644
--- a/frontend/src/views/Stats.jsx
+++ b/frontend/src/views/Stats.jsx
@@ -2,7 +2,7 @@ import { useEffect, useMemo, useState } from 'react'
import { useNavigate } from 'react-router-dom'
import { useStore } from '../store/useStore.js'
import { EXIDX, matchExercise } from '../lib/exercises.js'
-import { lastBW, streakWeeks, setLabel, modeOf, effortOf, metricModeForEntry, metricRowsForEntry, bestWeightForEntry } from '../lib/history.js'
+import { lastBW, streakWeeks, setLabel, modeOf, effortOf, metricModeForEntry, metricRowsForEntry, bestWeightForEntry, workoutDay } from '../lib/history.js'
import { fmtNum, fmtDate, fmtVol, todayISO, weekStartOf } from '../lib/format.js'
import { t, exerciseNameFor, getLang } from '../lib/i18n.js'
import { bwSheet, goalSheet, calendarSheet, workoutDetailSheet, WorkoutRow, bwDeltaColor } from '../sheets.jsx'
@@ -441,8 +441,13 @@ export default function Stats() {
</div>
<div className="card">
- <h2>{t('Activity — last 12 months')} <span className="dim" style={{ textTransform: 'none', letterSpacing: 0 }}>· {t('by time trained')}</span></h2>
- <Heatmap S={S} onDay={iso => { const ws = workouts.filter(w => w.d === iso); if (ws.length === 1) workoutDetailSheet(ws[0]); else if (ws.length) calendarSheet(iso) }} />
+ <h2>{t('Activity — last 12 months')}</h2>
+ <Heatmap
+ S={S}
+ metric={S.heatmapMetric === 'vol' ? 'vol' : 'time'}
+ onMetricChange={metric => useStore.getState().update(s => { s.heatmapMetric = metric })}
+ onDay={iso => { const ws = workouts.filter(w => workoutDay(w) === iso); if (ws.length === 1) workoutDetailSheet(ws[0]); else if (ws.length) calendarSheet(iso) }}
+ />
</div>
{workouts.length > 0 && <MuscleBalance S={S} />}