diff --git a/app/app.js b/app/app.js
index aa5a240..0049046 100644
--- a/app/app.js
+++ b/app/app.js
@@ -14,6 +14,7 @@ const KEY = 'gym_state_v1';
const DEF = {
unit: 'kg', restSec: 90, sound: true,
theme: 'dark', accent: 'lime', // appearance — synced with the profile
+ targetW: null, // goal body weight (drawn through the charts)
bodyweight: [], // {d:'YYYY-MM-DD', w:Number, t:ms}
routines: [], // {id, name, emoji, ex:[{id, sets, reps, weight}]}
week: {}, // weekday(0-6, JS getDay) -> routineId
@@ -382,6 +383,7 @@ function lineChart(points, opts) {
if (single) points = [points[0], points[0]];
const ys = points.map(p => p.y);
let ymin = Math.min(...ys), ymax = Math.max(...ys);
+ if (o.goal != null && isFinite(o.goal)) { ymin = Math.min(ymin, o.goal); ymax = Math.max(ymax, o.goal); }
if (ymin === ymax) { ymin -= 1; ymax += 1; }
const pad = (ymax - ymin) * 0.12; ymin -= pad; ymax += pad;
const t0 = points[0].t, t1 = points[points.length-1].t || t0 + 1;
@@ -438,6 +440,9 @@ function lineChart(points, opts) {
${axes}
+ ${o.goal != null && isFinite(o.goal) ? `
+
+ 🎯 ${fmtNum(o.goal)}` : ''}
@@ -638,7 +643,7 @@ function viewHome(app) {
const plannedPerWeek = Object.keys(S.week).filter(k => S.week[k]).length;
const lastW = S.workouts[S.workouts.length-1];
- const bwSpark = lineChart(S.bodyweight.slice(-30).map(b => ({t: b.t || new Date(b.d).getTime(), y: b.w, d: b.d})), {h: 130, unit: S.unit});
+ const bwSpark = lineChart(S.bodyweight.slice(-30).map(b => ({t: b.t || new Date(b.d).getTime(), y: b.w, d: b.d})), {h: 130, unit: S.unit, goal: S.targetW});
app.innerHTML = `
@@ -690,14 +695,18 @@ function viewHome(app) {
Body weight
-
+
+
+
+
${bw ? `
${fmtNum(bw.w)} ${S.unit}
- ${delta !== null ? `
${delta > 0 ? '▲' : delta < 0 ? '▼' : '•'} ${fmtNum(Math.abs(delta))}` : ''}
+ ${delta !== null ? `
${delta > 0 ? '▲' : delta < 0 ? '▼' : '•'} ${fmtNum(Math.abs(delta))}` : ''}
${fmtDate(bw.d, true)}
+ ${S.targetW ? `
🎯 Goal ${fmtNum(S.targetW)} ${S.unit} · ${Math.abs(S.targetW - bw.w) < 0.05 ? 'reached! 🎉' : fmtNum(Math.abs(S.targetW - bw.w)) + ' ' + S.unit + ' to ' + (S.targetW > bw.w ? 'gain' : 'lose')}
` : ''}
${bwSpark}
`
: `
No entries yet — log your weight to start the curve. It's also asked automatically before every workout.
`}
@@ -721,6 +730,7 @@ function viewHome(app) {
$('#btn-settings').onclick = () => nav('#settings');
$('#btn-logbw').onclick = () => bwSheet();
+ const bg = $('#btn-goal'); if (bg) bg.onclick = () => goalSheet();
$('#wk-prev').onclick = () => { weekOffset--; route(); };
$('#wk-next').onclick = () => { weekOffset++; route(); };
app.querySelectorAll('[data-date]').forEach(el => el.addEventListener('click', () => dayOverrideSheet(el.dataset.date)));
@@ -778,13 +788,14 @@ function calendarSheet(startDate) {
}
const monthWs = S.workouts.filter(w => w.d.startsWith(y + '-' + String(mo + 1).padStart(2, '0')));
const monthVol = monthWs.reduce((a, w) => a + (w.vol || 0), 0);
+ const monthMs = monthWs.reduce((a, w) => a + Math.max(0, (w.end || w.start) - w.start), 0);
wrap.innerHTML = `
${MONTHS_LONG[mo]} ${y}
-
${monthWs.length ? monthWs.length + ' workout' + (monthWs.length > 1 ? 's' : '') + ' · ' + fmtVol(monthVol) : 'No workouts this month'}
+
${monthWs.length ? monthWs.length + ' workout' + (monthWs.length > 1 ? 's' : '') + ' · ' + fmtDur(monthMs) + ' · ' + fmtVol(monthVol) : 'No workouts this month'}
${['Mo','Tu','We','Th','Fr','Sa','Su'].map(l => `
${l}
`).join('')}${cells}
Trained
@@ -836,6 +847,36 @@ function dayOverrideSheet(iso) {
}));
}
+/* ---------- target weight ---------- */
+/* delta is "good" (accent) when it moves toward the goal, red when away; neutral without a goal */
+function bwDeltaColor(delta, currentW) {
+ if (!delta) return 'var(--mut)';
+ if (!S.targetW) return 'var(--txt)';
+ const wantUp = S.targetW > currentW;
+ return (delta > 0) === wantUp ? 'var(--acc)' : 'var(--red)';
+}
+function goalSheet() {
+ const bw = lastBW();
+ const m = openModal(`
+
Target weight 🎯
+
Your goal is drawn as a line through the weight charts, and gains/losses are colored by whether they move toward it.
+
${S.unit}
+
+ ${S.targetW ? '
' : ''}
+ `);
+ const inp = m.el.querySelector('#gw-in');
+ setTimeout(() => { inp.focus(); inp.select(); }, 250);
+ m.el.querySelector('#gw-save').onclick = () => {
+ const v = parseFloat(inp.value);
+ if (!v || v <= 0 || v > 400) { toast('Enter a valid weight'); return; }
+ S.targetW = v; save(); m.close(); route();
+ const bw2 = lastBW();
+ toast('Goal set: ' + fmtNum(v) + ' ' + S.unit + (bw2 ? ' (' + fmtNum(Math.abs(v - bw2.w)) + ' to go)' : ''));
+ };
+ const del = m.el.querySelector('#gw-del');
+ if (del) del.onclick = () => { S.targetW = null; save(); m.close(); route(); toast('Goal removed'); };
+}
+
/* ============================================================
BODY WEIGHT SHEET
============================================================ */
@@ -1395,15 +1436,16 @@ function finishWorkout() {
/* ---------- activity heatmap (GitHub-style) ---------- */
function heatmapHTML() {
- const agg = {}; // iso -> {n, vol}
+ // intensity = time spent training that day (minutes) — more intuitive than volume
+ const agg = {}; // iso -> {n, vol, min}
S.workouts.forEach(w => {
- const a = agg[w.d] = agg[w.d] || { n: 0, vol: 0 };
- a.n++; a.vol += w.vol || 0;
+ 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));
});
- const vols = Object.values(agg).map(a => a.vol).filter(v => v > 0).sort((a, b) => a - b);
- const q = p => vols.length ? vols[Math.min(vols.length - 1, Math.floor(p * vols.length))] : 0;
+ 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 t1 = q(0.25), t2 = q(0.5), t3 = q(0.75);
- const level = a => !a ? 0 : !a.vol ? 1 : a.vol >= t3 ? 4 : a.vol >= t2 ? 3 : a.vol >= t1 ? 2 : 1;
+ const level = a => !a ? 0 : !a.min ? 1 : a.min >= t3 ? 4 : a.min >= t2 ? 3 : a.min >= t1 ? 2 : 1;
const today = new Date(); today.setHours(12, 0, 0, 0);
const iso = d => d.getFullYear() + '-' + String(d.getMonth()+1).padStart(2,'0') + '-' + String(d.getDate()).padStart(2,'0');
@@ -1424,7 +1466,7 @@ function heatmapHTML() {
const a = agg[key];
const isToday = key === todayISO();
const future = day > today;
- cells += `
`;
+ cells += `
`;
}
cols += `
${cells}
`;
}
@@ -1436,7 +1478,7 @@ function heatmapHTML() {
${cols}
- `;
+ `;
}
function bindHeatmap(root) {
const wrap = root.querySelector('#hm-wrap');
@@ -1495,11 +1537,11 @@ function viewStats(app) {
Workouts
${S.workouts.length}
Week streak
${streakWeeks()} 🔥
- Weight 30d
${bwDelta30 === null ? '—' : (bwDelta30 > 0 ? '+' : '') + fmtNum(bwDelta30) + ' ' + S.unit}
+ Weight 30d
${bwDelta30 === null ? '—' : (bwDelta30 > 0 ? '+' : '') + fmtNum(bwDelta30) + ' ' + S.unit}
-
Activity — last 12 months
+ Activity — last 12 months · by time trained
${heatmapHTML()}
@@ -1507,13 +1549,16 @@ function viewStats(app) {
Body weight
-
+
+
+
+
${[[30,'1M'],[90,'3M'],[365,'1Y'],[0,'All']].map(([d, l]) =>
``).join('')}
-
${lineChart(bwPts, { h: 160, unit: S.unit })}
+
${lineChart(bwPts, { h: 160, unit: S.unit, goal: S.targetW })}
@@ -1539,6 +1584,7 @@ function viewStats(app) {
$('#btn-hist').onclick = () => nav('#history');
$('#st-logbw').onclick = () => bwSheet();
+ $('#st-goal').onclick = () => goalSheet();
app.querySelectorAll('[data-range]').forEach(c => c.addEventListener('click', () => { statsRange = +c.dataset.range; route(); }));
const sel = $('#st-ex'); if (sel) sel.addEventListener('change', () => { statsEx = sel.value; route(); });
const ha = $('#st-histall'); if (ha) ha.onclick = () => nav('#history');
diff --git a/app/index.html b/app/index.html
index cd7f892..089216c 100644
--- a/app/index.html
+++ b/app/index.html
@@ -13,7 +13,7 @@
-
+
@@ -45,7 +45,7 @@
-
-
+
+