${lastExercise.volume.toLocaleString()} lbs
`; exerciseLogDiv.prepend(item); } /** * Resets the entire workout log. */ window.resetLog = function() { exercises = []; updateLog(); updateAnalysis(); analysisBox.classList.add('hidden'); } /** * Calculates and displays the workout analysis. */ function updateAnalysis() { if (exercises.length === 0) { analysisBox.classList.add('hidden'); return; } analysisBox.classList.remove('hidden'); let compoundVolume = 0; let isolationVolume = 0; exercises.forEach(ex => { if (ex.type === 'compound') { compoundVolume += ex.volume; } else { isolationVolume += ex.volume; } }); compoundVolumeDisplay.textContent = `${compoundVolume.toLocaleString()} lbs`; isolationVolumeDisplay.textContent = `${isolationVolume.toLocaleString()} lbs`; renderChart(compoundVolume, isolationVolume); } /** * Renders or updates the analysis chart. */ function renderChart(compoundVolume, isolationVolume) { const ctx = document.getElementById('typeChart').getContext('2d'); const chartData = { labels: ['Compound Volume', 'Isolation Volume'], datasets: [{ data: [compoundVolume, isolationVolume], backgroundColor: ['#3b82f6', '#10b981'], borderColor: ['#ffffff'], borderWidth: 2, }] }; if (typeChart) { typeChart.data = chartData; typeChart.update(); } else { typeChart = new Chart(ctx, { type: 'doughnut', data: chartData, options: { responsive: true, plugins: { legend: { position: 'top', }, title: { display: true, text: 'Total Volume Distribution' } } }, }); } } /** * Clears the input fields after adding an exercise. */ function clearInputs() { exerciseNameInput.value = ''; setsInput.value = ''; repsInput.value = ''; weightInput.value = ''; exerciseNameInput.focus(); } /** * Generates and downloads a PDF of the analysis. */ window.downloadPDF = async function() { if (exercises.length === 0) { statusMessage.textContent = "Please log exercises before downloading."; statusMessage.classList.add('text-red-600'); return; } if (typeof jspdf === 'undefined' || typeof html2canvas === 'undefined') { statusMessage.textContent = "PDF library failed to load."; statusMessage.classList.add('text-red-600'); return; } statusMessage.textContent = "Generating Report..."; statusMessage.classList.add('text-gray-600'); const downloadBtn = document.getElementById('downloadPdfBtn'); downloadBtn.disabled = true; const { jsPDF } = window.jspdf; const pdfContent = document.getElementById('pdf-content'); const reportDate = new Date().toLocaleDateString('en-US', { year: 'numeric', month: 'long', day: 'numeric' }); const chartCanvas = document.getElementById('typeChart'); const chartDataURL = chartCanvas.toDataURL('image/png', 1.0); const compoundExercises = exercises.filter(e => e.type === 'compound'); const isolationExercises = exercises.filter(e => e.type === 'isolation'); const totalCompoundVolume = compoundExercises.reduce((sum, ex) => sum + ex.volume, 0); const totalIsolationVolume = isolationExercises.reduce((sum, ex) => sum + ex.volume, 0); const createTableRows = (exArray) => exArray.map(ex => `Workout Analysis Report
Date: ${reportDate}
Volume Summary
Compound Volume
${totalCompoundVolume.toLocaleString()} lbs
Isolation Volume
${totalIsolationVolume.toLocaleString()} lbs
Exercise Details
Compound Lifts
| Exercise | Sets/Reps | Weight | Volume |
|---|
Isolation Lifts
| Exercise | Sets/Reps | Weight | Volume |
|---|
