Total Fees Paid Over ${years} Yrs
${formatCurrency(res.totalFeesPaid)}
`;
container.appendChild(card);
});
// Render Chart
const labels = Array.from({ length: years + 1 }, (_, i) => `Year ${i}`);
const ctx = document.getElementById('comparison-chart').getContext('2d');
if (chartInstance) chartInstance.destroy();
chartInstance = new Chart(ctx, {
type: 'line',
data: {
labels: labels,
datasets: chartDatasets
},
options: {
responsive: true,
plugins: { tooltip: { callbacks: { label: c => `${c.dataset.label}: ${formatCurrency(c.raw)}` }}},
scales: { y: { ticks: { callback: v => formatCurrency(v) }}}
}
});
};
// --- PDF DOWNLOAD ---
window.downloadPDF = async () => {
const btn = document.getElementById('pdf-button-container').querySelector('button');
btn.disabled = true; btn.textContent = 'Generating...';
const { jsPDF } = window.jspdf;
const content = document.getElementById('summary-for-pdf');
try {
const canvas = await html2canvas(content, { scale: 2 });
const imgData = canvas.toDataURL('image/png');
const pdf = new jsPDF({ orientation: 'p', unit: 'mm', format: 'a4' });
const pdfWidth = pdf.internal.pageSize.getWidth();
let imgWidth = pdfWidth - 20;
let imgHeight = canvas.height * imgWidth / canvas.width;
pdf.addImage(imgData, 'PNG', 10, 10, imgWidth, imgHeight);
pdf.save(`Robo_Comparison_${new Date().toISOString().slice(0, 10)}.pdf`);
} finally {
btn.disabled = false; btn.textContent = 'Download Results as PDF';
}
};
// --- INITIALIZATION ---
const init = () => {
createAdvisorCard(0, 'Wealthfront');
createAdvisorCard(1, 'Betterment');
createAdvisorCard(2, 'Schwab');
// Set initial values for all cards
updateFees(0);
updateFees(1);
updateFees(2);
};
init();
});