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.
JavaScript apple-watchbodyweightdockerfitnessfitness-trackergymhealthiosmcpnodejspasskeysprogressive-web-applicationspwareactself-hostedself-hostingvitewebauthnweightliftingworkout-tracker
feat(stats): Exercise progress gets the 1M / 3M / 1Y / All range of the Body weight card (#511)
Duarte Santosad70c603e979
diff --git a/frontend/src/locales/ar.js b/frontend/src/locales/ar.jsindex 92a675f91..1be569f95 100644--- a/frontend/src/locales/ar.js+++ b/frontend/src/locales/ar.js@@ -488,6 +488,7 @@ export default {'Not trained in this period': 'غير مدربة في هذه الفترة','Every muscle group got some work in this period.': 'حصلت كل مجموعة عضلية على نصيبها من العمل في هذه الفترة.','No workouts in this period yet.': 'لا توجد تمارين في هذه الفترة بعد.',+ 'Fewer than two workouts in this period. Pick a longer one.': 'أقل من تمرينين في هذه الفترة. اختر فترة أطول.','What this session hits': 'ما الذي تستهدفه هذه الجلسة','What you just trained': 'العضلات التي درّبتها','Body diagram': 'خريطة الجسم',diff --git a/frontend/src/locales/bn.js b/frontend/src/locales/bn.jsindex 44c88cd52..6ad7a0339 100644--- a/frontend/src/locales/bn.js+++ b/frontend/src/locales/bn.js@@ -681,6 +681,7 @@ export default {'Not trained in this period': 'এই সময়ে ট্রেন করা হয়নি','Every muscle group got some work in this period.': 'এই সময়ে প্রতিটি পেশি গ্রুপ কিছুটা কাজ পেয়েছে।','No workouts in this period yet.': 'এই সময়ে এখনও কোনো ওয়ার্কআউট নেই।',+ 'Fewer than two workouts in this period. Pick a longer one.': 'এই সময়ে দুটির কম ওয়ার্কআউট। আরও লম্বা সময় বেছে নিন।','What this session hits': 'এই সেশন যেসব পেশিতে কাজ করে','What you just trained': 'এইমাত্র যা ট্রেন করলেন','Body diagram': 'শরীরের ডায়াগ্রাম',diff --git a/frontend/src/locales/de.js b/frontend/src/locales/de.jsindex 1593a8587..1a9cdb60a 100644--- a/frontend/src/locales/de.js+++ b/frontend/src/locales/de.js@@ -617,6 +617,7 @@ export default {'Not trained in this period': 'In diesem Zeitraum nicht trainiert','Every muscle group got some work in this period.': 'Jede Muskelgruppe hat in diesem Zeitraum etwas abbekommen.','No workouts in this period yet.': 'Noch keine Trainings in diesem Zeitraum.',+ 'Fewer than two workouts in this period. Pick a longer one.': 'Weniger als zwei Trainings in diesem Zeitraum. Wähle einen längeren.','What this session hits': 'Was dieses Training trifft','What you just trained': 'Was du gerade trainiert hast','Body diagram': 'Körperdiagramm',diff --git a/frontend/src/locales/es.js b/frontend/src/locales/es.jsindex db601873f..660464b3c 100644--- a/frontend/src/locales/es.js+++ b/frontend/src/locales/es.js@@ -598,6 +598,7 @@ export default {'Not trained in this period': 'Sin entrenar en este periodo','Every muscle group got some work in this period.': 'Todos los grupos musculares recibieron algo de trabajo en este periodo.','No workouts in this period yet.': 'Aún no hay entrenamientos en este periodo.',+ 'Fewer than two workouts in this period. Pick a longer one.': 'Menos de dos entrenamientos en este periodo. Elige uno más largo.','What this session hits': 'Qué trabaja esta sesión','What you just trained': 'Lo que acabas de entrenar','Body diagram': 'Diagrama corporal',diff --git a/frontend/src/locales/fr.js b/frontend/src/locales/fr.jsindex cb58c8e6b..fb06833e3 100644--- a/frontend/src/locales/fr.js+++ b/frontend/src/locales/fr.js@@ -598,6 +598,7 @@ export default {'Not trained in this period': 'Non travaillé sur cette période','Every muscle group got some work in this period.': 'Chaque groupe musculaire a été sollicité sur cette période.','No workouts in this period yet.': 'Pas encore d\'entraînement sur cette période.',+ 'Fewer than two workouts in this period. Pick a longer one.': 'Moins de deux entraînements sur cette période. Choisis-en une plus longue.','What this session hits': 'Ce que cette séance sollicite','What you just trained': 'Ce que tu viens de travailler','Body diagram': 'Schéma du corps',diff --git a/frontend/src/locales/hi.js b/frontend/src/locales/hi.jsindex 7e16c39e1..2de04e8cf 100644--- a/frontend/src/locales/hi.js+++ b/frontend/src/locales/hi.js@@ -598,6 +598,7 @@ export default {'Not trained in this period': 'इस अवधि में प्रशिक्षित नहीं','Every muscle group got some work in this period.': 'इस अवधि में हर मांसपेशी समूह पर काम हुआ।','No workouts in this period yet.': 'इस अवधि में अभी कोई वर्कआउट नहीं।',+ 'Fewer than two workouts in this period. Pick a longer one.': 'इस अवधि में दो से कम वर्कआउट हैं। लंबी अवधि चुनें।','What this session hits': 'यह सत्र क्या ट्रेन करता है','What you just trained': 'आपने अभी क्या ट्रेन किया','Body diagram': 'शरीर आरेख',diff --git a/frontend/src/locales/hu.js b/frontend/src/locales/hu.jsindex 1c83bb636..42247c680 100644--- a/frontend/src/locales/hu.js+++ b/frontend/src/locales/hu.js@@ -599,6 +599,7 @@ export default {'Not trained in this period': 'Ebben az időszakban nincs edzve','Every muscle group got some work in this period.': 'Minden izomcsoport kapott valamennyi munkát ebben az időszakban.','No workouts in this period yet.': 'Ebben az időszakban még nincs edzés.',+ 'Fewer than two workouts in this period. Pick a longer one.': 'Ebben az időszakban kevesebb mint két edzés van. Válassz hosszabbat.','What this session hits': 'Mit érint ez az edzés','What you just trained': 'Mit edzettél az imént','Body diagram': 'Testábra',diff --git a/frontend/src/locales/it.js b/frontend/src/locales/it.jsindex 496ab1b7f..fe8f5ec5c 100644--- a/frontend/src/locales/it.js+++ b/frontend/src/locales/it.js@@ -598,6 +598,7 @@ export default {'Not trained in this period': 'Non allenati in questo periodo','Every muscle group got some work in this period.': 'Ogni gruppo muscolare ha lavorato in questo periodo.','No workouts in this period yet.': 'Ancora nessun allenamento in questo periodo.',+ 'Fewer than two workouts in this period. Pick a longer one.': 'Meno di due allenamenti in questo periodo. Scegline uno più lungo.','What this session hits': 'Cosa allena questa sessione','What you just trained': 'Cosa hai appena allenato','Body diagram': 'Diagramma del corpo',diff --git a/frontend/src/locales/ko.js b/frontend/src/locales/ko.jsindex 37b4ed4ff..651cbf52c 100644--- a/frontend/src/locales/ko.js+++ b/frontend/src/locales/ko.js@@ -598,6 +598,7 @@ export default {'Not trained in this period': '이 기간에 훈련하지 않음','Every muscle group got some work in this period.': '이 기간에 모든 근육군을 훈련했습니다.','No workouts in this period yet.': '이 기간에 아직 운동이 없습니다.',+ 'Fewer than two workouts in this period. Pick a longer one.': '이 기간에는 운동이 두 번 미만입니다. 더 긴 기간을 선택하세요.','What this session hits': '이 세션이 자극하는 부위','What you just trained': '방금 훈련한 부위','Body diagram': '신체 도해',diff --git a/frontend/src/locales/pl.js b/frontend/src/locales/pl.jsindex 7a7ece30e..b072d2def 100644--- a/frontend/src/locales/pl.js+++ b/frontend/src/locales/pl.js@@ -598,6 +598,7 @@ export default {'Not trained in this period': 'Nietrenowane w tym okresie','Every muscle group got some work in this period.': 'Każda grupa mięśniowa była trenowana w tym okresie.','No workouts in this period yet.': 'Brak treningów w tym okresie.',+ 'Fewer than two workouts in this period. Pick a longer one.': 'Mniej niż dwa treningi w tym okresie. Wybierz dłuższy.','What this session hits': 'Co trenuje ta sesja','What you just trained': 'Co obejmował ten trening','Body diagram': 'Diagram ciała',diff --git a/frontend/src/locales/pt-BR.js b/frontend/src/locales/pt-BR.jsindex 4d941e328..32c590e4d 100644--- a/frontend/src/locales/pt-BR.js+++ b/frontend/src/locales/pt-BR.js@@ -1401,6 +1401,7 @@ export const PT_BR_OVERRIDES = {'Your sports watch, calling you back.': 'Seu relógio esportivo chamando você de volta.','Coach wants you back on the bar.': 'O coach quer você de volta na barra.','Gentle, for headphones or a quiet room.': 'Suave, para fones de ouvido ou um lugar silencioso.',+ 'Fewer than two workouts in this period. Pick a longer one.': 'Menos de dois treinos neste período. Escolha um mais longo.',}export default { ...pt, ...PT_BR_OVERRIDES }diff --git a/frontend/src/locales/pt.js b/frontend/src/locales/pt.jsindex 9a47676f3..90b166963 100644--- a/frontend/src/locales/pt.js+++ b/frontend/src/locales/pt.js@@ -598,6 +598,7 @@ export default {'Not trained in this period': 'Sem treino neste período','Every muscle group got some work in this period.': 'Todos os grupos musculares foram trabalhados neste período.','No workouts in this period yet.': 'Ainda sem treinos neste período.',+ 'Fewer than two workouts in this period. Pick a longer one.': 'Menos de dois treinos neste período. Escolhe um mais longo.','What this session hits': 'O que esta sessão trabalha','What you just trained': 'O que acabaste de treinar','Body diagram': 'Diagrama do corpo',diff --git a/frontend/src/locales/ru.js b/frontend/src/locales/ru.jsindex c4a804e8e..870adabb1 100644--- a/frontend/src/locales/ru.js+++ b/frontend/src/locales/ru.js@@ -588,6 +588,7 @@ export default {'Not trained in this period': 'Не тренировались за этот период','Every muscle group got some work in this period.': 'За этот период поработали все группы мышц.','No workouts in this period yet.': 'В этом периоде ещё нет тренировок.',+ 'Fewer than two workouts in this period. Pick a longer one.': 'В этом периоде меньше двух тренировок. Выберите период подлиннее.','What this session hits': 'Что задействует эта тренировка','What you just trained': 'Что вы только что тренировали','Body diagram': 'Схема тела',diff --git a/frontend/src/locales/th.js b/frontend/src/locales/th.jsindex ae70913e6..e0ffccc9c 100644--- a/frontend/src/locales/th.js+++ b/frontend/src/locales/th.js@@ -599,6 +599,7 @@ export default {'Not trained in this period': 'ยังไม่ได้ฝึกในช่วงนี้','Every muscle group got some work in this period.': 'ทุกกลุ่มกล้ามเนื้อได้รับการฝึกในช่วงนี้แล้ว','No workouts in this period yet.': 'ยังไม่มีการออกกำลังกายในช่วงนี้',+ 'Fewer than two workouts in this period. Pick a longer one.': 'ช่วงนี้มีการออกกำลังกายน้อยกว่าสองครั้ง ลองเลือกช่วงที่ยาวขึ้น','What this session hits': 'ท่านี้ฝึกกล้ามเนื้อส่วนไหนบ้าง','What you just trained': 'สิ่งที่เพิ่งฝึกไป','Body diagram': 'แผนภาพร่างกาย',diff --git a/frontend/src/locales/tr.js b/frontend/src/locales/tr.jsindex c7812e763..cfebb52e3 100644--- a/frontend/src/locales/tr.js+++ b/frontend/src/locales/tr.js@@ -598,6 +598,7 @@ export default {'Not trained in this period': 'Bu dönemde çalışılmadı','Every muscle group got some work in this period.': 'Bu dönemde her kas grubu çalıştı.','No workouts in this period yet.': 'Bu dönemde henüz antrenman yok.',+ 'Fewer than two workouts in this period. Pick a longer one.': 'Bu dönemde ikiden az antrenman var. Daha uzun bir dönem seç.','What this session hits': 'Bu antrenman neyi çalıştırıyor','What you just trained': 'Az önce ne çalıştın','Body diagram': 'Vücut diyagramı',diff --git a/frontend/src/locales/uk.js b/frontend/src/locales/uk.jsindex 51371cd55..15e561678 100644--- a/frontend/src/locales/uk.js+++ b/frontend/src/locales/uk.js@@ -424,6 +424,7 @@ export default {'Not trained in this period': 'Не тренувалися за цей період','Every muscle group got some work in this period.': 'За цей період попрацювали всі групи м’язів.','No workouts in this period yet.': 'У цьому періоді ще немає тренувань.',+ 'Fewer than two workouts in this period. Pick a longer one.': 'У цьому періоді менше двох тренувань. Обери довший.','What this session hits': 'Що задіює це тренування','What you just trained': 'Що ти щойно тренував','Body diagram': 'Схема тіла',diff --git a/frontend/src/locales/zh-TW.js b/frontend/src/locales/zh-TW.jsindex e56ce48fe..eaed2d6e5 100644--- a/frontend/src/locales/zh-TW.js+++ b/frontend/src/locales/zh-TW.js@@ -587,6 +587,7 @@ export default {'Not trained in this period': '此期間未訓練','Every muscle group got some work in this period.': '在此期間內,所有肌群皆已獲得適度刺激。','No workouts in this period yet.': '此期間尚無任何訓練紀錄。',+ 'Fewer than two workouts in this period. Pick a longer one.': '此期間的訓練少於兩次,請選擇更長的期間。','What this session hits': '本次訓練主要刺激肌群','What you just trained': '剛才完成的鍛鍊肌群','Body diagram': '身體肌群分佈圖',diff --git a/frontend/src/locales/zh.js b/frontend/src/locales/zh.jsindex 27b039eb5..134fd4544 100644--- a/frontend/src/locales/zh.js+++ b/frontend/src/locales/zh.js@@ -598,6 +598,7 @@ export default {'Not trained in this period': '此期间未训练','Every muscle group got some work in this period.': '此期间每个肌群都得到了训练。','No workouts in this period yet.': '此期间还没有训练。',+ 'Fewer than two workouts in this period. Pick a longer one.': '此期间的训练少于两次,请选择更长的期间。','What this session hits': '这次训练练到哪里','What you just trained': '你刚刚练了什么','Body diagram': '身体图示',diff --git a/frontend/src/views/Stats.ex-range.test.jsx b/frontend/src/views/Stats.ex-range.test.jsxnew file mode 100644index 000000000..0089eba67--- /dev/null+++ b/frontend/src/views/Stats.ex-range.test.jsx@@ -0,0 +1,92 @@+// @vitest-environment happy-dom+// Issue #511: the Exercise progress card gets the Body weight card's 1M / 3M / 1Y / All range.+// It cuts every chart mode to the range, starts on All, keeps "Best:" all-time, and says so when+// the range holds fewer than two workouts instead of drawing a lone dot.+import React, { act } from 'react'+import { createRoot } from 'react-dom/client'+import { afterEach, describe, expect, it, vi } from 'vitest'+import Stats from './Stats.jsx'++const mocks = vi.hoisted(() => ({ charts: [], S: null }))+vi.mock('../store/useStore.js', () => ({ useStore: selector => selector({ S: mocks.S }) }))+vi.mock('react-router-dom', () => ({ useNavigate: () => () => {} }))+vi.mock('../sheets.jsx', () => ({+ bwSheet: () => {}, goalSheet: () => {}, calendarSheet: () => {}, workoutDetailSheet: () => {}, exerciseHistorySheet: () => {},+ WorkoutRow: () => null, bwDeltaColor: () => 'inherit',+}))+vi.mock('../components/LineChart.jsx', () => ({ default: props => { mocks.charts.push(props); return null } }))+vi.mock('../components/Heatmap.jsx', () => ({ default: () => null }))+vi.mock('../components/BodyMap.jsx', () => ({ default: () => null, BodyMapLegend: () => null }))++globalThis.IS_REACT_ACT_ENVIRONMENT = true+const BENCH = '0025'+const DAY = 86400000+// A bench session `ago` days back, two working sets at weight w.+const session = (ago, w) => {+ const start = Date.now() - ago * DAY+ return {+ id: 'w' + ago, d: new Date(start).toISOString().slice(0, 10), start, end: start + 3600000, name: 'Push',+ entries: [{ id: BENCH, target: { id: BENCH, sets: 2, reps: 5 }, sets: [{ w, r: 5, done: true }, { w, r: 4, done: true }] }],+ }+}+let root, host+afterEach(() => { act(() => root.unmount()); host.remove(); mocks.charts = [] })++function mount(workouts) {+ mocks.S = { body: 'male', effort: 'none', unit: 'kg', targetW: null, bodyweight: [], routines: [], exWeights: {}, workouts }+ host = document.createElement('div')+ document.body.appendChild(host)+ root = createRoot(host)+ act(() => root.render(<Stats />))+}+// The exercise card's chart is the last one drawn; the body weight chart has no colour of its own.+const exChart = () => mocks.charts.filter(c => c.color === 'var(--blue)' || c.series).at(-1)+const exCard = () => [...host.querySelectorAll('.card')].find(c => c.querySelector('h2')?.textContent === 'Exercise progress')+const press = (scope, label) => act(() => [...scope.querySelectorAll('.seg button')].find(b => b.textContent === label).click())++describe('Stats: exercise progress date range', () => {+ it('starts on All and cuts the top-set line to the picked range, Best staying all-time', () => {+ mount([session(400, 100), session(200, 90), session(60, 70), session(10, 75), session(3, 80)])+ const card = exCard()+ expect([...card.querySelectorAll('.seg button.on')].map(b => b.textContent)).toEqual(['Top set', 'All'])+ expect(exChart().points.map(p => p.y)).toEqual([100, 90, 70, 75, 80])++ press(card, '1M')+ expect(exChart().points.map(p => p.y)).toEqual([75, 80])+ press(card, '3M')+ expect(exChart().points.map(p => p.y)).toEqual([70, 75, 80])+ expect(card.textContent).toContain('Best: 100 kg')+ })++ it('applies to the other chart modes too', () => {+ mount([session(400, 100), session(200, 90), session(60, 70), session(10, 75), session(3, 80)])+ const card = exCard()+ press(card, 'Est. 1RM')+ const all = exChart().points.length+ press(card, '1M')+ expect(all).toBe(5)+ expect(exChart().points).toHaveLength(2)+ press(card, 'Per set')+ const chart = exChart()+ expect(chart.points).toHaveLength(2)+ expect(chart.series.every(s => s.points.length === 2)).toBe(true)+ })++ it('shows a hint instead of the chart when the range holds fewer than two workouts', () => {+ mount([session(400, 100), session(200, 90), session(5, 80)])+ const card = exCard()+ press(card, '1M')+ expect(card.textContent).toContain('Fewer than two workouts in this period. Pick a longer one.')+ mocks.charts = []+ press(card, '1Y')+ expect(card.textContent).not.toContain('Fewer than two workouts')+ expect(exChart().points.map(p => p.y)).toEqual([90, 80])+ })++ it('leaves the body weight range alone', () => {+ mount([session(400, 100), session(200, 90), session(5, 80)])+ const bwCard = [...host.querySelectorAll('.card')].find(c => c.querySelector('h2')?.textContent === 'Body weight')+ press(exCard(), '1M')+ expect([...bwCard.querySelectorAll('.seg button.on')].map(b => b.textContent)).toEqual(['3M'])+ })+})diff --git a/frontend/src/views/Stats.jsx b/frontend/src/views/Stats.jsxindex a5151d089..28fa2910d 100644--- a/frontend/src/views/Stats.jsx+++ b/frontend/src/views/Stats.jsx@@ -31,6 +31,13 @@ import { isWarmupRow } from '../lib/workout-model.js'// Set 1 to 5 on the per-set chart — system colours, so each line keeps its hue in dark mode.const SET_COLORS = ['var(--blue)', 'var(--green)', 'var(--orange)', 'var(--purple)', 'var(--pink)']+// The date range buttons under Body weight, and since issue #511 under Exercise progress too.+// In days, 0 = everything; a function because the labels follow the current language.+const rangeOptions = () => [{ value: 30, label: '1M' }, { value: 90, label: '3M' }, { value: 365, label: '1Y' }, { value: 0, label: t('All') }]+// Where a range starts, in ms. Worked out once per pick rather than from each render's clock, so+// the memoised chart arrays below keep their identity (LineChart drops its hover on a new one).+const rangeStart = days => (days ? Date.now() - days * 86400000 : 0)+// 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 latestMuscleTraining(workouts) {@@ -411,6 +418,11 @@ export default function Stats() {}, [])const [exId, setExId] = useState(null)const [exMetric, setExMetric] = useState('top')+ // Exercise progress over a date range (issue #511), All by default. Only the chart follows it:+ // "Best:" and the recent sessions under it stay all-time.+ const [exRange, setExRange] = useState(0)+ const exFrom = useMemo(() => rangeStart(exRange), [exRange])+ const inExRange = p => p.t >= exFromconst now = Date.now()const kind = displayScale(S)const hd = scaleName(kind)@@ -549,7 +561,7 @@ export default function Stats() {() => (curEx && curMode === 'reps' ? e1rmSeries(S, curEx) : []),[S, curEx, curMode],)- const e1ChartPts = useMemo(() => e1Pts.map(p => ({ t: p.t, y: p.y, d: p.d })), [e1Pts])+ const e1ChartPts = useMemo(() => e1Pts.filter(p => p.t >= exFrom).map(p => ({ t: p.t, y: p.y, d: p.d })), [e1Pts, exFrom])const e1Best = curEx && curMode === 'reps' ? best1RM(S, curEx) : nullconst showE1 = e1Pts.length > 0// Effort on this exercise, per session. It rides on the top-set curve as well as having a@@ -557,7 +569,7 @@ export default function Stats() {// with more left in the tank is progress a weight-only chart draws as a flat line.const exRir = exPts.map(p => avgRir(p.sets))const showEff = exRir.filter(v => v != null).length >= 3- const effPts = exPts.map((p, i) => (exRir[i] == null ? null : { t: p.t, y: toScale(kind, exRir[i]), d: p.d })).filter(Boolean)+ const effPts = exPts.map((p, i) => (exRir[i] == null ? null : { t: p.t, y: toScale(kind, exRir[i]), d: p.d })).filter(p => p && inExRange(p))// Pyramid sets' Max sets: the most reps in one, per workout — the point of a Max set is seeing// that number climb, which the top-set weight line does not show.const maxPts = useMemo(@@ -566,6 +578,7 @@ export default function Stats() {)const showMax = maxPts.length > 0const maxBest = showMax ? Math.max(...maxPts.map(p => p.y)) : 0+ const maxChartPts = useMemo(() => maxPts.filter(p => p.t >= exFrom), [maxPts, exFrom])// Per set (issue #145): one line per set number, to see which set you drop off on — often not// the last. Offered once two sessions are logged and one of them has two sets or more.// Memoised like e1Pts: LineChart drops its hover whenever `points` changes identity.@@ -583,7 +596,7 @@ export default function Stats() {const { lines, hidden } = perSetLines(sessions)const shown = new Set(lines.map(l => l.n))return {- series: lines.map(l => ({ points: l.points, color: SET_COLORS[l.n - 1] })),+ series: lines.map(l => ({ n: l.n, points: l.points, color: SET_COLORS[l.n - 1] })),anchors: sessions.map(s => ({t: s.t, d: s.d, y: Math.max(...s.sets.map(x => x.y)),note: s.sets.filter(x => shown.has(x.n)).map(x => x.n + ': ' + (repsOnly ? x.r : fmtNum(x.w) + '×' + x.r)).join(' · '),@@ -594,6 +607,12 @@ export default function Stats() {drop: dropOffSet(sessions),}}, [workouts, curEx, curMode, repsOnly, oneRmFormula])+ // The same sessions cut to the range; a set number with nothing left in it drops out of the legend.+ const perSetChart = useMemo(() => {+ if (!perSet) return null+ const series = perSet.series.map(s => ({ ...s, points: s.points.filter(p => p.t >= exFrom) })).filter(s => s.points.length)+ return { anchors: perSet.anchors.filter(p => p.t >= exFrom), series, ns: series.map(s => s.n) }+ }, [perSet, exFrom])const onSets = !!perSet && exMetric === 'sets'const onE1 = showE1 && exMetric === 'e1rm'const onEff = showEff && exMetric === 'effort'@@ -603,7 +622,10 @@ export default function Stats() {// 0 RIR (nothing left) is a full dot, 4+ a faint one; unrated sessions keep the plain line.m: exRir[i] == null ? null : 1 - Math.min(4, Math.max(0, exRir[i])) / 4,note: exRir[i] == null ? undefined : hd + ' ' + fmtNum(toScale(kind, exRir[i]))- }))+ })).filter(inExRange)+ const chartPts = onSets ? perSetChart.anchors : onMax ? maxChartPts : onEff ? effPts : onE1 ? e1ChartPts : topPts+ // A line needs two workouts. A range that holds fewer says so, instead of a lone dot or an empty box.+ const rangeTooShort = exRange !== 0 && chartPts.length < 2const exOpts = [{ value: 'top', label: t('Top set') }]if (perSet) exOpts.push({ value: 'sets', label: t('Per set') })if (showE1) exOpts.push({ value: 'e1rm', label: t('Est. 1RM') })@@ -663,7 +685,7 @@ export default function Stats() {</div></div><Segmented className="seg-range" value={range} onChange={setRange}- options={[{ value: 30, label: '1M' }, { value: 90, label: '3M' }, { value: 365, label: '1Y' }, { value: 0, label: t('All') }]} />+ options={rangeOptions()} /><div className="chart"><LineChart points={bwPts} h={160} unit={S.unit} goal={S.targetW} /></div>{/* every weigh-in, week by week with its average (Discord 'Weight') */}{S.bodyweight.length > 0 && <div className="row" style={{ justifyContent: 'flex-end', marginTop: 4 }}>@@ -685,17 +707,20 @@ export default function Stats() {}} /></div>{exOpts.length > 1 && <Segmented className="seg-range" value={onMax ? 'max' : onEff ? 'effort' : onE1 ? 'e1rm' : onSets ? 'sets' : 'top'} onChange={setExMetric} options={exOpts} />}+ <Segmented className="seg-range" value={exRange} onChange={setExRange} options={rangeOptions()} /><div className="chart">- {onSets- ? <LineChart points={perSet.anchors} series={perSet.series} h={150} unit={perSet.metric === 'reps' ? t('reps') : S.unit} />+ {rangeTooShort+ ? <div className="empty small">{t('Fewer than two workouts in this period. Pick a longer one.')}</div>+ : onSets+ ? <LineChart points={perSetChart.anchors} series={perSetChart.series} h={150} unit={perSet.metric === 'reps' ? t('reps') : S.unit} />: onMax- ? <LineChart points={maxPts} h={150} unit={t('reps')} color="var(--blue)" />+ ? <LineChart points={maxChartPts} h={150} unit={t('reps')} color="var(--blue)" />: onEff? <LineChart points={effPts} h={150} unit={hd} color="var(--yellow)" invert={kind === 'rir'} />- : <LineChart points={onE1 ? e1ChartPts : topPts} h={150} unit={exUnit} color="var(--blue)" />}+ : <LineChart points={chartPts} h={150} unit={exUnit} color="var(--blue)" />}</div>- {onSets && <div className="row small" style={{ gap: 12, flexWrap: 'wrap', marginTop: 6 }}>- {perSet.ns.map(n => <span key={n} className="row" style={{ gap: 5, alignItems: 'center' }}>+ {onSets && !rangeTooShort && <div className="row small" style={{ gap: 12, flexWrap: 'wrap', marginTop: 6 }}>+ {perSetChart.ns.map(n => <span key={n} className="row" style={{ gap: 5, alignItems: 'center' }}><span aria-hidden="true" style={{ width: 8, height: 8, borderRadius: 4, background: SET_COLORS[n - 1] }} />{t('Set {0}', n)}</span>)}</div>}