Stress Diary Generator

New Stress Entry

Relaxed Moderate Overwhelmed
Quick Select (Click to add):

Stress Trends

Recent History

Customize Selections

Manage the preset options available on your dashboard for faster logging.

Common Triggers


Common Symptoms

My Stress Diary

Generated Report

Date/Time Level Situation Symptoms Coping/Reaction

No entries logged yet.

'; return; } sorted.forEach(entry => { const dateObj = new Date(entry.date); const dateStr = dateObj.toLocaleDateString() + ' ' + dateObj.toLocaleTimeString([], {hour: '2-digit', minute:'2-digit'}); // Severity Class let sevClass = 'severity-low'; if(entry.level >= 4) sevClass = 'severity-med'; if(entry.level >= 8) sevClass = 'severity-high'; const div = document.createElement('div'); div.className = `log-item ${sevClass}`; div.innerHTML = `

Stress Level: ${entry.level}/10 | ${dateStr}

Trigger: ${entry.situation}
Symptoms: ${entry.symptoms.join(', ') || '-'}
Coping: ${entry.coping}
`; container.appendChild(div); }); } function renderChart() { const ctx = document.getElementById('stressChart').getContext('2d'); // Sort Ascending for Chart const sorted = [...state.entries].sort((a,b) => new Date(a.date) - new Date(b.date)); const labels = sorted.map(e => new Date(e.date).toLocaleDateString()); const dataPoints = sorted.map(e => e.level); if (chartInstance) chartInstance.destroy(); chartInstance = new Chart(ctx, { type: 'line', data: { labels: labels, datasets: [{ label: 'Stress Intensity', data: dataPoints, borderColor: '#6c5ce7', backgroundColor: 'rgba(108, 92, 231, 0.2)', borderWidth: 2, tension: 0.3, fill: true }] }, options: { responsive: true, maintainAspectRatio: false, scales: { y: { beginAtZero: true, max: 10, title: { display: true, text: 'Level (1-10)' } } } } }); } // --- Configuration Logic --- function renderConfigLists() { const tList = document.getElementById('config-triggers-list'); const sList = document.getElementById('config-symptoms-list'); const createTag = (text, type, idx) => { const s = document.createElement('span'); s.className = 'config-tag'; s.innerHTML = `${text} `; return s; }; tList.innerHTML = ''; state.config.triggers.forEach((t, i) => tList.appendChild(createTag(t, 'trigger', i))); sList.innerHTML = ''; state.config.symptoms.forEach((s, i) => sList.appendChild(createTag(s, 'symptom', i))); } function addConfigItem(type) { const inputId = type === 'trigger' ? 'new-trigger-input' : 'new-symptom-input'; const input = document.getElementById(inputId); const val = input.value.trim(); if(val) { if(type === 'trigger') state.config.triggers.push(val); else state.config.symptoms.push(val); input.value = ''; renderConfigLists(); renderChips(); // Update dashboard } } function removeConfigItem(type, idx) { if(type === 'trigger') state.config.triggers.splice(idx, 1); else state.config.symptoms.splice(idx, 1); renderConfigLists(); renderChips(); // Update dashboard } // --- PDF Logic --- function generatePDF() { const template = document.getElementById('stress-pdf-template'); const tableBody = document.getElementById('pdf-table-body'); // Populate Table tableBody.innerHTML = ''; const sorted = [...state.entries].sort((a,b) => new Date(a.date) - new Date(b.date)); // Chronological sorted.forEach(e => { const dateStr = new Date(e.date).toLocaleDateString() + ' ' + new Date(e.date).toLocaleTimeString([], {hour: '2-digit', minute:'2-digit'}); const row = ` ${dateStr} ${e.level}/10 ${e.situation} ${e.symptoms.join(', ')} ${e.coping} `; tableBody.insertAdjacentHTML('beforeend', row); }); // Capture Chart as Image const canvas = document.getElementById('stressChart'); const imgData = canvas.toDataURL('image/png'); const pdfChartContainer = document.getElementById('pdf-chart-container'); pdfChartContainer.innerHTML = ``; // Show template temporarily template.style.display = 'block'; const opt = { margin: 0.5, filename: 'Stress_Diary_Report.pdf', image: { type: 'jpeg', quality: 0.98 }, html2canvas: { scale: 2 }, jsPDF: { unit: 'in', format: 'letter', orientation: 'portrait' } }; html2pdf().set(opt).from(template).save().then(() => { template.style.display = 'none'; pdfChartContainer.innerHTML = ''; // Clean up }); } return { switchTab, updateSliderVal, addEntry, deleteEntry, generatePDF, addConfigItem, removeConfigItem }; })();
Scroll to Top