feat(dashboard): даты по всей оси X, легенда вниз, крупнее шрифты, запоминаемый выбор упражнения, сводка по упражнению с синергичными

This commit is contained in:
Иван Овчинников
2026-11-20 07:47:39 +03:00
parent 97176ed90e
commit 7343a950f8
8 changed files with 244 additions and 39 deletions
+20 -3
View File
@@ -1,7 +1,11 @@
// frontend/js/render/dashboard-screen.js
import { state } from '../state.js';
import { escapeHtml } from '../utils.js';
import { drawExerciseProgress, drawBodyMetricsGraph } from './dashboard.js';
import { showExerciseSummary } from '../modals/exercise-summary.js';
const CHART_EX_KEY = 'gym_dash_char…ise';
export function renderDashboard() {
const app = document.getElementById('app');
@@ -20,10 +24,13 @@ export function renderDashboard() {
<label>Выберите упражнение</label>
<select id="dash-ex-select" onchange="DashboardLogic.updateExerciseChart()">
<option value="">— Выберите —</option>
${getUniqueExercises().map(ex => `<option value="${ex}">${ex}</option>`).join('')}
${getUniqueExercises().map(ex => `<option value="${escapeHtml(ex)}">${escapeHtml(ex)}</option>`).join('')}
</select>
</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="250" style="width:100%; background:#1e1e1e; border-radius:8px;"></canvas>
<div style="margin-top:8px">
<button class="btn btn-small btn-secondary" onclick="DashboardLogic.showExSummary()">📋 Сводка по упражнению</button>
</div>
<p class="text-muted text-small mt-10">Главное — рабочий максимум «вес × повторы»: зелёный — прогресс (вес выше или тот же вес и больше повторов), красный — откат. Тусклые точки — остальные подходы, «×N» — их число. Последние 10 тренировок.</p>
</div>
@@ -53,6 +60,8 @@ export function renderDashboard() {
updateExerciseChart: () => {
const select = document.getElementById('dash-ex-select');
const canvas = document.getElementById('chart-exercise');
// Выбор упражнения запоминается и восстанавливается при следующем открытии
localStorage.setItem(CHART_EX_KEY, select.value);
if (select.value) {
drawExerciseProgress(canvas, select.value);
} else {
@@ -63,6 +72,11 @@ export function renderDashboard() {
ctx.fillText('Выберите упражнение выше', canvas.width/2, canvas.height/2);
}
},
showExSummary: () => {
const select = document.getElementById('dash-ex-select');
if (!select.value) { alert('Сначала выберите упражнение'); return; }
showExerciseSummary(select.value);
},
updateBodyChart: () => {
const clientSel = document.getElementById('dash-client-select');
const metricSel = document.getElementById('dash-metric-select');
@@ -77,7 +91,10 @@ export function renderDashboard() {
}
};
// Первичная отрисовка (пустые состояния)
// Первичная отрисовка: восстанавливаем закреплённый выбор упражнения
const saved = localStorage.getItem(CHART_EX_KEY);
const exSelect = document.getElementById('dash-ex-select');
if (saved && Array.from(exSelect.options).some(o => o.value === saved)) exSelect.value = saved;
DashboardLogic.updateExerciseChart();
if(state.metricTypes.length > 0) {
document.getElementById('dash-metric-select').value = state.metricTypes[0].id;
+20 -25
View File
@@ -27,7 +27,7 @@ export function drawExerciseProgress(canvas, exerciseName) {
const maxWeight = Math.max(...days.map(d => d.max), 1);
const padding = { top: 26, right: 14, bottom: 34, left: 44 };
const padding = { top: 14, right: 14, bottom: 58, left: 44 };
const chartW = width - padding.left - padding.right;
const chartH = height - padding.top - padding.bottom;
@@ -88,34 +88,28 @@ export function drawExerciseProgress(canvas, exerciseName) {
ctx.stroke();
if (n <= 10 || i >= n - 4 || classes[i] !== 'flat') {
ctx.fillStyle = COLORS[classes[i]];
ctx.font = 'bold 11px sans-serif';
ctx.font = 'bold 12px sans-serif';
ctx.textAlign = 'center';
ctx.fillText(`${d.max}×${d.topReps || ''}`, px, y(d.max) - 7);
ctx.fillText(`${d.max}×${d.topReps || ''}`, px, y(d.max) - 8);
}
// Количество подходов (выносливость)
if (n <= 12 || i % 2 === 0) {
ctx.fillStyle = '#b0b0b0';
ctx.font = '9px sans-serif';
// Дата под каждой точкой оси X и количество подходов (выносливость)
if (n <= 10 || i % 2 === 0) {
ctx.fillStyle = '#d5d5d5';
ctx.font = '10px sans-serif';
ctx.textAlign = 'center';
ctx.fillText('×' + d.sets.length, px, height - padding.bottom + 12);
ctx.fillText(formatShortDate(d.date.toISOString()), px, height - padding.bottom + 15);
ctx.fillStyle = '#b0b0b0';
ctx.font = '10px sans-serif';
ctx.fillText('×' + d.sets.length, px, height - padding.bottom + 29);
}
});
// Даты первой и последней тренировки
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, [
{ color: '#3ddc55', label: 'рабочий максимум: зелёный — прогресс, красный — откат' },
{ color: 'rgba(199, 146, 255, 0.55)', label: 'тусклая точка = подход (размер = повторы)' },
]);
], height - 8);
}
/**
@@ -291,8 +285,8 @@ function drawGridAndAxes(ctx, pad, cw, ch, maxY, maxXAxisLabel, yAxisLabel) {
ctx.stroke();
// Подписи Y
ctx.fillStyle = '#b0b0b0';
ctx.font = '10px sans-serif';
ctx.fillStyle = '#c9c9c9';
ctx.font = '11px sans-serif';
ctx.textAlign = 'right';
for(let i=0; i<=4; i++) {
const val = (maxY * i / 4).toFixed(0);
@@ -339,15 +333,16 @@ function drawLineChart(ctx, data, pad, cw, ch, maxY, getValueFn, color, lineWidt
}
function drawLegend(ctx, width, items) {
ctx.font = '10px sans-serif';
function drawLegend(ctx, width, items, y) {
// y — базовая линия текста (легенда внизу); квадрат чуть выше текста
ctx.font = '11px sans-serif';
ctx.textAlign = 'left';
let xOffset = 10;
items.forEach(item => {
ctx.fillStyle = item.color;
ctx.fillRect(xOffset, 10, 10, 10);
ctx.fillRect(xOffset, y - 9, 10, 10);
ctx.fillStyle = '#fff';
ctx.fillText(item.label, xOffset + 15, 19);
ctx.fillText(item.label, xOffset + 15, y);
xOffset += ctx.measureText(item.label).width + 30;
});
}