From 83ff9ae6e41105d168976f71bba883ecf4852e49 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=98=D0=B2=D0=B0=D0=BD=20=D0=9E=D0=B2=D1=87=D0=B8=D0=BD?= =?UTF-8?q?=D0=BD=D0=B8=D0=BA=D0=BE=D0=B2?= Date: Fri, 20 Nov 2026 00:57:37 +0300 Subject: [PATCH] =?UTF-8?q?feat(chart):=20=D0=BA=D0=BD=D0=BE=D0=BF=D0=BA?= =?UTF-8?q?=D0=B0=20=D0=B3=D1=80=D0=B0=D1=84=D0=B8=D0=BA=D0=B0=20=D0=BF?= =?UTF-8?q?=D1=80=D0=BE=D0=B3=D1=80=D0=B5=D1=81=D1=81=D0=B8=D0=B8=20=D1=83?= =?UTF-8?q?=D0=BF=D1=80=D0=B0=D0=B6=D0=BD=D0=B5=D0=BD=D0=B8=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit SVG-график максимального веса по завершённым тренировкам с объединением вариантов одной группы, подсказками на точках и списком последних результатов. --- frontend/js/app.js | 1 + frontend/js/logic/exercise.js | 35 ++++++++++++++ frontend/js/modals/chart-modal.js | 71 +++++++++++++++++++++++++++++ frontend/js/render/exercise-card.js | 3 ++ frontend/styles/components.css | 15 ++++++ 5 files changed, 125 insertions(+) create mode 100644 frontend/js/modals/chart-modal.js diff --git a/frontend/js/app.js b/frontend/js/app.js index 76757ef..edc2bf5 100644 --- a/frontend/js/app.js +++ b/frontend/js/app.js @@ -21,6 +21,7 @@ import './modals/client-select-modal.js'; import './modals/edit-exercise-modal.js'; import './modals/edit-workout-date-modal.js'; import './modals/group-modal.js'; +import './modals/chart-modal.js'; function renderHeader() { const modeLabel = state.mode === 'trainer' ? '👨‍🏫 Тренер' : '👤 Личный'; diff --git a/frontend/js/logic/exercise.js b/frontend/js/logic/exercise.js index 28323c8..80aa3ed 100644 --- a/frontend/js/logic/exercise.js +++ b/frontend/js/logic/exercise.js @@ -151,6 +151,41 @@ export function getExerciseHistory(exerciseName, clientId = null, excludeWorkout return history.slice(0, 5); } +/** + * Полная история для графика (без среза в 5 записей): варианты из одной + * группы складывают в одну прогрессию. + */ +export function getExerciseChart(exerciseName, clientId = null) { + const variantNames = refVariantNames(exerciseName); + const targetClient = normalizeClientId(clientId); + const points = []; + + for (const w of state.workouts) { + if (!isSameClient(w.client_id, targetClient)) continue; + if (!w.endTime) continue; // активная тренировка ещё не результат + + for (const ex of w.exercises || []) { + if (!variantNames.has(normalizeName(ex.name))) continue; + let maxWeight = 0, totalReps = 0; + for (const s of ex.sets || []) { + const wgt = s.isDropset && s.subSets?.length + ? Math.max(...s.subSets.map(x => parseFloat(x.weight) || 0)) + : (parseFloat(s.weight) || 0); + if (wgt > maxWeight) maxWeight = wgt; + totalReps += s.isDropset && s.subSets?.length + ? s.subSets.reduce((a, x) => a + (parseInt(x.reps) || 0), 0) + : (parseInt(s.reps) || 0); + } + if (maxWeight > 0 || totalReps > 0) { + points.push({ date: w.startTime, name: ex.name, maxWeight, totalReps }); + } + } + } + + points.sort((a, b) => new Date(a.date) - new Date(b.date)); + return points; +} + window.EL = { addExercise, toggleExercise, diff --git a/frontend/js/modals/chart-modal.js b/frontend/js/modals/chart-modal.js new file mode 100644 index 0000000..b3ecb0e --- /dev/null +++ b/frontend/js/modals/chart-modal.js @@ -0,0 +1,71 @@ +import { state } from '../state.js'; +import { escapeHtml } from '../utils.js'; +import { showModal, closeModal } from './modal-base.js'; +import { getExerciseChart } from '../logic/exercise.js'; + +/** + * График прогрессии упражнения: максимальный вес (или повторения, если вес + * не используется) по завершённым тренировкам. Варианты из одной группы + * справочника складываются в одну линию. + */ +export function showChartDialog(exerciseName, clientId = null) { + const points = getExerciseChart(exerciseName, clientId); + + if (points.length === 0) { + showModal(` + +
Нет завершённых тренировок с этим упражнением — график появится после первых результатов.
+ `); + return; + } + + const byWeight = points.some(p => p.maxWeight > 0); + const values = points.map(p => byWeight ? p.maxWeight : p.totalReps); + const label = byWeight ? 'вес, кг' : 'повторы'; + + const W = 320, H = 170, padL = 30, padR = 12, padT = 14, padB = 24; + const t0 = new Date(points[0].date).getTime(); + const t1 = new Date(points[points.length - 1].date).getTime(); + const span = Math.max(1, t1 - t0); + const vMax = Math.max(...values), vMin = Math.min(...values); + const vSpan = Math.max(1e-6, vMax - vMin); + const x = t => padL + (W - padL - padR) * (new Date(t).getTime() - t0) / span; + const y = v => padT + (H - padT - padB) * (1 - (v - vMin) / vSpan); + + const pts = points.map(p => `${x(p.date).toFixed(1)},${y(byWeight ? p.maxWeight : p.totalReps).toFixed(1)}`); + const circles = points.map((p, i) => + `${new Date(p.date).toLocaleDateString('ru-RU')} — ${escapeHtml(p.name)}: ${values[i]} ${label === 'вес, кг' ? 'кг' : 'повт.'}` + ).join(''); + + const fmt = d => new Date(d).toLocaleDateString('ru-RU', { day: '2-digit', month: '2-digit' }); + const maxIdx = values.indexOf(vMax); + + showModal(` + +
${points.length} трен. · ${label} · варианты одной группы сложены вместе
+ + + + ${vMax} + ${vMin} + ${points.length > 1 ? `` : ''} + ${circles} + ${fmt(points[0].date)} + ${points.length > 1 && new Date(points[points.length - 1].date) - new Date(points[0].date) > 864e5 + ? `${fmt(points[points.length - 1].date)}` : ''} + ${points.length > 0 ? `макс ${values[maxIdx]}` : ''} + +
${points.slice(-5).reverse().map(p => + `
${new Date(p.date).toLocaleDateString('ru-RU')}${escapeHtml(p.name)}${byWeight ? p.maxWeight + ' кг' : p.totalReps + ' повт.'}
` + ).join('')}
+ `); +} + +// Клик с кнопки в карточке: имя берём из data-атрибута (без экранирования в JS-строке) +export function showChartFromBtn(btn) { + const name = btn.dataset.ex; + const w = state.workouts.find(w => (w.exercises || []).some(e => e.name === name)); + showChartDialog(name, w ? w.client_id : null); +} + +window.CM = { showChartDialog, showChartFromBtn }; diff --git a/frontend/js/render/exercise-card.js b/frontend/js/render/exercise-card.js index 6d42f2a..dbd3ef3 100644 --- a/frontend/js/render/exercise-card.js +++ b/frontend/js/render/exercise-card.js @@ -1,4 +1,5 @@ import { state } from '../state.js'; +import { escapeHtml } from '../utils.js'; import { renderSetRow } from './set-row.js'; export function renderExercise(w, ex, isReadOnly = false) { @@ -15,6 +16,8 @@ export function renderExercise(w, ex, isReadOnly = false) { ${ex.name} ${summary} + › `; diff --git a/frontend/styles/components.css b/frontend/styles/components.css index 1a4c6b1..8a436b7 100644 --- a/frontend/styles/components.css +++ b/frontend/styles/components.css @@ -130,3 +130,18 @@ textarea { resize: vertical; min-height: 60px; } border-color: var(--text); box-shadow: 0 0 0 2px var(--bg), 0 0 0 4px var(--text); } + +/* === Progress chart === */ +.chart-btn { flex: 0 0 auto; font-size: 0.95rem; opacity: 0.75; } +.chart-svg { width: 100%; height: auto; display: block; margin: 8px 0 4px; } +.chart-line { fill: none; stroke: var(--accent); stroke-width: 2; stroke-linejoin: round; } +.chart-svg circle { fill: var(--accent); stroke: var(--card-bg, #fff); stroke-width: 1.5; } +.chart-axis { stroke: var(--border); stroke-width: 1; } +.chart-label { font-size: 9px; fill: var(--text-secondary, #888); } +.chart-max { fill: var(--accent); font-weight: 700; } +.chart-sub { font-size: 0.72rem; color: var(--text-secondary, #888); } +.chart-list { display: flex; flex-direction: column; gap: 2px; margin-top: 8px; } +.chart-row { display: flex; justify-content: space-between; gap: 8px; font-size: 0.78rem; } +.chart-date { color: var(--text-secondary, #888); flex: 0 0 auto; } +.chart-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; } +.chart-val { font-weight: 600; flex: 0 0 auto; }