Breastfeeding Nutrition Tracker

Breastfeeding Nutrition & Feeding Tracker

Monitor your nutrition and your baby's feeding schedule.

Log Your Intake

Log Baby's Feeding

Today's Log

Nutrition

No food logged yet.

Feedings

No feedings logged yet.

Daily Summary

No feedings logged yet.

'; return; } feedingLog.innerHTML = ''; feedingLogData.forEach(item => { const el = document.createElement('div'); el.className = 'flex justify-between items-center bg-gray-100 p-2 rounded-lg'; el.innerHTML = `${item.time} (${item.duration} min)`; el.querySelector('.remove-btn').onclick = () => removeFeedingItem(item.id); feedingLog.appendChild(el); }); } function renderSummary() { const totals = nutritionLogData.reduce((acc, item) => { acc.calories += item.calories; acc.protein += item.protein; acc.calcium += item.calcium; acc.iron += item.iron; acc.hydration += item.hydration; return acc; }, { calories: 0, protein: 0, calcium: 0, iron: 0, hydration: 0 }); const percentages = { calories: Math.min((totals.calories / nutrientTargets.calories) * 100, 100), protein: Math.min((totals.protein / nutrientTargets.protein) * 100, 100), calcium: Math.min((totals.calcium / nutrientTargets.calcium) * 100, 100), iron: Math.min((totals.iron / nutrientTargets.iron) * 100, 100), hydration: Math.min((totals.hydration / nutrientTargets.hydration) * 100, 100), }; summaryStats.innerHTML = `
Calories: ${totals.calories.toFixed(0)} / ${nutrientTargets.calories} kcal
Protein: ${totals.protein.toFixed(1)} / ${nutrientTargets.protein} g
Calcium: ${totals.calcium.toFixed(0)} / ${nutrientTargets.calcium} mg
Iron: ${totals.iron.toFixed(1)} / ${nutrientTargets.iron} mg
Hydration: ${totals.hydration.toFixed(0)} / ${nutrientTargets.hydration} ml
`; // Chart const ctx = document.getElementById('summaryChart').getContext('2d'); if (summaryChart) summaryChart.destroy(); summaryChart = new Chart(ctx, { type: 'bar', data: { labels: ['Calories', 'Protein', 'Calcium', 'Iron', 'Hydration'], datasets: [{ label: '% of Daily Target', data: Object.values(percentages), backgroundColor: [ 'rgba(59, 130, 246, 0.6)', 'rgba(236, 72, 153, 0.6)', 'rgba(16, 185, 129, 0.6)', 'rgba(249, 115, 22, 0.6)', 'rgba(14, 165, 233, 0.6)' ], borderColor: [ '#3B82F6', '#EC4899', '#10B981', '#F97316', '#0EA5E9' ], borderWidth: 1 }] }, options: { indexAxis: 'y', responsive: true, maintainAspectRatio: false, scales: { x: { max: 100, beginAtZero: true, ticks: { callback: value => value + '%' } } }, plugins: { legend: { display: false } } } }); } // --- PDF DOWNLOAD LOGIC --- async function downloadPDF() { pdfLoader.classList.remove('hidden'); pdfDownloadBtn.disabled = true; const { jsPDF } = window.jspdf; const pdfExportContent = document.getElementById('pdf-export-area'); const totals = nutritionLogData.reduce((acc, item) => { acc.calories += item.calories; acc.protein += item.protein; acc.calcium += item.calcium; acc.iron += item.iron; acc.hydration += item.hydration; return acc; }, { calories: 0, protein: 0, calcium: 0, iron: 0, hydration: 0 }); let nutritionHtml = nutritionLogData.map(item => `
  • ${item.name}
  • `).join(''); let feedingHtml = feedingLogData.map(item => `
  • ${item.time} (${item.duration} min)
  • `).join(''); pdfExportContent.innerHTML = `

    Daily Nutrition & Feeding Report

    Generated on: ${new Date().toLocaleDateString('en-US', { year: 'numeric', month: 'long', day: 'numeric' })}

    Nutritional Summary

    Calories: ${totals.calories.toFixed(0)} kcal
    Protein: ${totals.protein.toFixed(1)} g
    Calcium: ${totals.calcium.toFixed(0)} mg
    Iron: ${totals.iron.toFixed(1)} mg
    Hydration: ${totals.hydration.toFixed(0)} ml

    Nutrition Log

      ${nutritionHtml || '
    • No items logged.
    • '}

    Feeding Log

      ${feedingHtml || '
    • No feedings logged.
    • '}
    `; await new Promise(resolve => setTimeout(resolve, 100)); try { const canvas = await html2canvas(pdfExportContent, { scale: 2 }); const imgData = canvas.toDataURL('image/png'); const pdf = new jsPDF({ orientation: "portrait", unit: "pt", format: "a4" }); const pageWidth = pdf.internal.pageSize.getWidth(); const margin = 40; const imgProps = pdf.getImageProperties(imgData); const pdfImageWidth = pageWidth - (margin * 2); const pdfImageHeight = (imgProps.height * pdfImageWidth) / imgProps.width; pdf.addImage(imgData, 'PNG', margin, margin, pdfImageWidth, pdfImageHeight); pdf.save(`Breastfeeding-Report-${new Date().toISOString().slice(0,10)}.pdf`); } catch (error) { console.error("Error generating PDF:", error); alert("Sorry, there was an error creating the PDF."); } finally { pdfLoader.classList.add('hidden'); pdfDownloadBtn.disabled = false; pdfExportContent.innerHTML = ''; } } // --- START THE APP --- initialize(); });
    Scroll to Top