${entry.intensity}/10
${entry.notes}
` : ''} `; logHistoryContainer.appendChild(entryDiv); }); } function renderChart() { if (state.chart) { state.chart.destroy(); } if (state.entries.length === 0) { return; } const ctx = chartCanvas.getContext('2d'); state.chart = new Chart(ctx, { type: 'line', data: { datasets: [{ label: 'Pain Intensity', data: state.entries.map(e => ({ x: e.datetime, y: e.intensity })), borderColor: '#3b82f6', backgroundColor: 'rgba(59, 130, 246, 0.1)', tension: 0.1, fill: true, }] }, options: { responsive: true, maintainAspectRatio: false, scales: { x: { type: 'time', time: { unit: 'day', tooltipFormat: 'MMM d, yyyy h:mm a' }, title: { display: true, text: 'Date' } }, y: { beginAtZero: true, max: 10, title: { display: true, text: 'Intensity (0-10)' } } } } }); } // --- PDF Generation --- async function generatePDF() { if (state.entries.length === 0) { alert("No entries to report. Please add a pain log entry first."); return; } // Populate PDF data document.getElementById('pdf-report-date').textContent = new Date().toLocaleString(undefined, { dateStyle: 'long' }); // Render chart to an image for the PDF const chartContainer = document.getElementById('pdf-chart-container'); const chartImage = new Image(); chartImage.src = state.chart.toBase64Image(); chartContainer.innerHTML = ''; chartImage.style.width = '100%'; chartImage.style.height = '100%'; chartContainer.appendChild(chartImage); // Render log history for the PDF const pdfLogContainer = document.getElementById('pdf-log-history'); pdfLogContainer.innerHTML = `| Date & Time | Intensity | Location | Notes |
|---|---|---|---|
| ${entry.datetime.toLocaleString(undefined, { dateStyle: 'short', timeStyle: 'short' })} | ${entry.intensity} | ${entry.location || ''} | ${entry.notes || ''} |
