feat(dashboard): график прогресса по каждому подходу с линией максимального веса и счётчиком подходов
This commit is contained in:
@@ -24,7 +24,7 @@ export function renderDashboard() {
|
|||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
<canvas id="chart-exercise" width="400" height="200" style="width:100%; background:#1e1e1e; border-radius:8px;"></canvas>
|
<canvas id="chart-exercise" width="400" height="200" style="width:100%; background:#1e1e1e; border-radius:8px;"></canvas>
|
||||||
<p class="text-muted text-small mt-10">Показаны макс. вес и повторения за последние 10 тренировок.</p>
|
<p class="text-muted text-small mt-10">Точка — подход (размер = повторения), линия — макс. вес за тренировку, «×N» — число подходов. Последние 10 тренировок.</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- Секция 2: Динамика тела -->
|
<!-- Секция 2: Динамика тела -->
|
||||||
|
|||||||
+102
-116
@@ -4,7 +4,9 @@ import { state } from '../state.js';
|
|||||||
import { formatDate } from '../utils.js';
|
import { formatDate } from '../utils.js';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Рисует линейный график прогресса упражнения
|
* Рисует график прогресса упражнения: каждая точка — подход (вес по вертикали,
|
||||||
|
* размер — повторения), фиолетовая линия — максимальный вес за тренировку
|
||||||
|
* (силовая прогрессия), «×N» под осью — количество подходов (выносливость).
|
||||||
* @param {HTMLCanvasElement} canvas
|
* @param {HTMLCanvasElement} canvas
|
||||||
* @param {string} exerciseName
|
* @param {string} exerciseName
|
||||||
*/
|
*/
|
||||||
@@ -15,33 +17,119 @@ export function drawExerciseProgress(canvas, exerciseName) {
|
|||||||
|
|
||||||
ctx.clearRect(0, 0, width, height);
|
ctx.clearRect(0, 0, width, height);
|
||||||
|
|
||||||
const history = getCumulativeExerciseHistory(exerciseName);
|
const days = getExerciseProgressData(exerciseName);
|
||||||
|
|
||||||
if (history.length < 2) {
|
if (days.length === 0) {
|
||||||
drawEmptyState(ctx, width, height, "Недостаточно данных\nНужно минимум 2 тренировки");
|
drawEmptyState(ctx, width, height, "Нет завершённых тренировок\nс этим упражнением");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Находим максимальный ИТОГОВЫЙ объем для масштабирования оси Y
|
const maxWeight = Math.max(...days.map(d => d.max), 1);
|
||||||
const maxVolume = Math.max(...history.map(h => h.totalVolume));
|
|
||||||
|
|
||||||
const padding = { top: 20, right: 20, bottom: 30, left: 40 };
|
const padding = { top: 26, right: 14, bottom: 34, left: 44 };
|
||||||
const chartW = width - padding.left - padding.right;
|
const chartW = width - padding.left - padding.right;
|
||||||
const chartH = height - padding.top - padding.bottom;
|
const chartH = height - padding.top - padding.bottom;
|
||||||
|
|
||||||
// Рисуем сетку (используем maxVolume для оси Y)
|
drawGridAndAxes(ctx, padding, chartW, chartH, maxWeight, 'Дата', 'Вес (кг)');
|
||||||
drawGridAndAxes(ctx, padding, chartW, chartH, maxVolume, 'Дата', 'Общий вес (кг)');
|
|
||||||
|
|
||||||
// Рисуем новый график со стеком
|
const n = days.length;
|
||||||
drawCumulativeVolumeChart(ctx, history, padding, chartW, chartH, maxVolume);
|
const x = i => n === 1 ? padding.left + chartW / 2
|
||||||
|
: padding.left + (chartW * i) / (n - 1);
|
||||||
|
const y = v => padding.top + chartH - (v / maxWeight) * chartH;
|
||||||
|
const maxReps = Math.max(1, ...days.flatMap(d => d.sets.map(s => s.reps)));
|
||||||
|
|
||||||
|
// Соединительная линия максимальных весов (силовая прогрессия)
|
||||||
|
if (n > 1) {
|
||||||
|
ctx.strokeStyle = '#bb86fc';
|
||||||
|
ctx.lineWidth = 2;
|
||||||
|
ctx.beginPath();
|
||||||
|
days.forEach((d, i) => {
|
||||||
|
const px = x(i), py = y(d.max);
|
||||||
|
i === 0 ? ctx.moveTo(px, py) : ctx.lineTo(px, py);
|
||||||
|
});
|
||||||
|
ctx.stroke();
|
||||||
|
}
|
||||||
|
|
||||||
|
days.forEach((d, i) => {
|
||||||
|
const px = x(i);
|
||||||
|
|
||||||
|
// Подходы дня: точки по весу, разнесены вокруг колонки дня
|
||||||
|
const spread = d.sets.length > 1 ? Math.min(11, chartW / (3 * n)) : 0;
|
||||||
|
d.sets.forEach((s, k) => {
|
||||||
|
const dx = d.sets.length > 1 ? -spread + (2 * spread * k) / (d.sets.length - 1) : 0;
|
||||||
|
const r = 2.2 + 3.2 * Math.min(1, s.reps / maxReps);
|
||||||
|
ctx.beginPath();
|
||||||
|
ctx.fillStyle = s.weight === d.max ? '#bb86fc' : 'rgba(187, 134, 252, 0.45)';
|
||||||
|
ctx.arc(px + dx, y(s.weight), r, 0, Math.PI * 2);
|
||||||
|
ctx.fill();
|
||||||
|
if (s.weight === d.max) {
|
||||||
|
ctx.strokeStyle = '#ffffff';
|
||||||
|
ctx.lineWidth = 1.2;
|
||||||
|
ctx.stroke();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// Количество подходов (выносливость)
|
||||||
|
if (n <= 12 || i % 2 === 0) {
|
||||||
|
ctx.fillStyle = '#b0b0b0';
|
||||||
|
ctx.font = '9px sans-serif';
|
||||||
|
ctx.textAlign = 'center';
|
||||||
|
ctx.fillText('×' + d.sets.length, px, height - padding.bottom + 12);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// Даты первой и последней тренировки
|
||||||
|
ctx.fillStyle = '#b0b0b0';
|
||||||
|
ctx.font = '10px sans-serif';
|
||||||
|
ctx.textAlign = 'left';
|
||||||
|
ctx.fillText(formatShortDate(days[0].date.toISOString()), padding.left, height - 6);
|
||||||
|
if (n > 1) {
|
||||||
|
ctx.textAlign = 'right';
|
||||||
|
ctx.fillText(formatShortDate(days[n - 1].date.toISOString()), width - padding.right, height - 6);
|
||||||
|
}
|
||||||
|
|
||||||
// Легенда (обновленная)
|
|
||||||
drawLegend(ctx, width, [
|
drawLegend(ctx, width, [
|
||||||
{ color: '#bb86fc', label: 'Итоговый объем' },
|
{ color: '#bb86fc', label: 'макс. вес за тренировку' },
|
||||||
{ color: 'rgba(187, 134, 252, 0.4)', label: 'Накопление по подходам' }
|
{ color: 'rgba(187, 134, 252, 0.45)', label: 'точка = подход (размер = повторы)' },
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Данные графика: по каждой завершённой тренировке — список подходов
|
||||||
|
* (дроп-сеты развёрнуты), максимальный вес и общий объём.
|
||||||
|
* @returns {{date: Date, sets: {weight:number, reps:number}[], max:number, totalVolume:number}[]}
|
||||||
|
*/
|
||||||
|
export function getExerciseProgressData(exerciseName) {
|
||||||
|
const normalized = exerciseName.trim().toLowerCase();
|
||||||
|
const days = [];
|
||||||
|
|
||||||
|
state.workouts.forEach(w => {
|
||||||
|
if (!w.endTime) return; // активная тренировка — не результат
|
||||||
|
(w.exercises || []).forEach(ex => {
|
||||||
|
if (ex.name.trim().toLowerCase() !== normalized) return;
|
||||||
|
const sets = [];
|
||||||
|
(ex.sets || []).forEach(s => {
|
||||||
|
const parts = s.isDropset && s.subSets?.length ? s.subSets : [s];
|
||||||
|
parts.forEach(p => {
|
||||||
|
const weight = parseFloat(p.weight) || 0;
|
||||||
|
const reps = parseInt(p.reps) || 0;
|
||||||
|
if (weight > 0 || reps > 0) sets.push({ weight, reps });
|
||||||
|
});
|
||||||
|
});
|
||||||
|
if (sets.length === 0) return;
|
||||||
|
days.push({
|
||||||
|
date: new Date(w.startTime),
|
||||||
|
sets,
|
||||||
|
max: Math.max(...sets.map(s => s.weight)),
|
||||||
|
totalVolume: sets.reduce((a, s) => a + s.weight * s.reps, 0),
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
days.sort((a, b) => a.date - b.date);
|
||||||
|
return days.slice(-10);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Рисует график динамики телесных замеров
|
* Рисует график динамики телесных замеров
|
||||||
* @param {HTMLCanvasElement} canvas
|
* @param {HTMLCanvasElement} canvas
|
||||||
@@ -137,46 +225,6 @@ export function drawBodyMetricsGraph(canvas, clientId, metricTypeId) {
|
|||||||
ctx.fillText(formatShortDate(dataPoints[dataPoints.length-1].date.toISOString()), width - padding.right, height - 10);
|
ctx.fillText(formatShortDate(dataPoints[dataPoints.length-1].date.toISOString()), width - padding.right, height - 10);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Собирает историю с накопительным весом по каждому подходу
|
|
||||||
*/
|
|
||||||
function getCumulativeExerciseHistory(name) {
|
|
||||||
const normalized = name.trim().toLowerCase();
|
|
||||||
const history = [];
|
|
||||||
|
|
||||||
state.workouts.forEach(w => {
|
|
||||||
w.exercises.forEach(ex => {
|
|
||||||
if (ex.name.trim().toLowerCase() === normalized && ex.sets.length > 0) {
|
|
||||||
let currentCumulativeWeight = 0;
|
|
||||||
const cumulativePoints = [];
|
|
||||||
|
|
||||||
ex.sets.forEach(s => {
|
|
||||||
// Учитываем вес подхода (для дроп-сетов можно брать средний или максимальный, здесь берем основной)
|
|
||||||
const setWeight = s.isDropset && s.subSets
|
|
||||||
? Math.max(...s.subSets.map(ss => ss.weight))
|
|
||||||
: s.weight;
|
|
||||||
|
|
||||||
// Объем подхода = вес * повторения (или просто вес, если вы считаете тоннаж)
|
|
||||||
// В вашем примере (15, 30, 45, 60) вы суммируете именно вес подходов.
|
|
||||||
// Если нужно суммировать тоннаж (вес * повторы), замените на: setWeight * s.reps
|
|
||||||
const volume = setWeight * s.reps;
|
|
||||||
|
|
||||||
currentCumulativeWeight += volume;
|
|
||||||
cumulativePoints.push(currentCumulativeWeight);
|
|
||||||
});
|
|
||||||
|
|
||||||
history.push({
|
|
||||||
date: new Date(w.startTime),
|
|
||||||
cumulativePoints: cumulativePoints, // [15, 30, 45, 60]
|
|
||||||
totalVolume: currentCumulativeWeight // 60
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
history.sort((a, b) => a.date - b.date);
|
|
||||||
return history.slice(-10); // Последние 10 тренировок
|
|
||||||
}
|
|
||||||
|
|
||||||
// --- Вспомогательные функции ---
|
// --- Вспомогательные функции ---
|
||||||
|
|
||||||
@@ -290,68 +338,6 @@ function drawLineChart(ctx, data, pad, cw, ch, maxY, getValueFn, color, lineWidt
|
|||||||
ctx.stroke();
|
ctx.stroke();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Рисует график прогресса с вертикальным стеком накопительного веса
|
|
||||||
*/
|
|
||||||
function drawCumulativeVolumeChart(ctx, data, pad, cw, ch, maxY) {
|
|
||||||
if (!data.length) return;
|
|
||||||
|
|
||||||
// 1. Сначала рисуем соединительную линию для ОБЩИХ итогов (тренд)
|
|
||||||
ctx.strokeStyle = '#bb86fc'; // Основной цвет (например, фиолетовый)
|
|
||||||
ctx.lineWidth = 2;
|
|
||||||
ctx.beginPath();
|
|
||||||
|
|
||||||
data.forEach((item, index) => {
|
|
||||||
const x = pad.left + (index / (data.length - 1 || 1)) * cw;
|
|
||||||
const y = pad.top + ch - (item.totalVolume / maxY) * ch;
|
|
||||||
|
|
||||||
if (index === 0) ctx.moveTo(x, y);
|
|
||||||
else ctx.lineTo(x, y);
|
|
||||||
});
|
|
||||||
ctx.stroke();
|
|
||||||
|
|
||||||
// 2. Рисуем вертикальные стеки точек для каждой даты
|
|
||||||
data.forEach((item, index) => {
|
|
||||||
const x = pad.left + (index / (data.length - 1 || 1)) * cw;
|
|
||||||
|
|
||||||
item.cumulativePoints.forEach((cumWeight, pointIndex) => {
|
|
||||||
const isLast = pointIndex === item.cumulativePoints.length - 1;
|
|
||||||
const y = pad.top + ch - (cumWeight / maxY) * ch;
|
|
||||||
|
|
||||||
ctx.beginPath();
|
|
||||||
|
|
||||||
if (isLast) {
|
|
||||||
// Финальная точка: крупная, непрозрачная, с белой обводкой для контраста
|
|
||||||
ctx.fillStyle = '#bb86fc';
|
|
||||||
ctx.arc(x, y, 5, 0, Math.PI * 2);
|
|
||||||
ctx.fill();
|
|
||||||
|
|
||||||
ctx.strokeStyle = '#ffffff';
|
|
||||||
ctx.lineWidth = 1.5;
|
|
||||||
ctx.stroke();
|
|
||||||
} else {
|
|
||||||
// Промежуточные точки: полупрозрачные, поменьше
|
|
||||||
ctx.fillStyle = 'rgba(187, 134, 252, 0.4)'; // Тот же цвет, но 40% непрозрачности
|
|
||||||
ctx.arc(x, y, 3, 0, Math.PI * 2);
|
|
||||||
ctx.fill();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// Опционально: провести бледную вертикальную линию от 0 до итоговой точки,
|
|
||||||
// чтобы визуально связать подходы в один "столбик"
|
|
||||||
if (item.cumulativePoints.length > 1) {
|
|
||||||
const bottomY = pad.top + ch; // Ось X
|
|
||||||
const topY = pad.top + ch - (item.totalVolume / maxY) * ch;
|
|
||||||
|
|
||||||
ctx.strokeStyle = 'rgba(187, 134, 252, 0.15)';
|
|
||||||
ctx.lineWidth = 1;
|
|
||||||
ctx.beginPath();
|
|
||||||
ctx.moveTo(x, bottomY);
|
|
||||||
ctx.lineTo(x, topY);
|
|
||||||
ctx.stroke();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function drawLegend(ctx, width, items) {
|
function drawLegend(ctx, width, items) {
|
||||||
ctx.font = '10px sans-serif';
|
ctx.font = '10px sans-serif';
|
||||||
|
|||||||
Reference in New Issue
Block a user