Monthly Cost Breakdown (per unit)
${breakdownHtml.replace(/\/ mo/g, '')}
`;
downloadBtn.classList.remove('hidden');
const ctx = document.getElementById('feeChart')?.getContext('2d');
if(ctx) {
if (feeChart) feeChart.destroy();
feeChart = new Chart(ctx, {
type: 'doughnut',
data: {
labels: Object.keys(results.breakdown),
datasets: [{
data: Object.values(results.breakdown),
backgroundColor: ['#15803d', '#16a34a', '#22c55e', '#f59e0b', '#fbbf24', '#fde047', '#6b7280'],
borderColor: '#ffffff',
borderWidth: 3
}]
},
options: {
responsive: true,
maintainAspectRatio: false,
plugins: {
legend: { position: 'bottom' },
tooltip: { callbacks: { label: (c) => `${c.label}: ${formatCurrency(c.raw)}/yr` } }
}
}
});
}
}
function downloadPDF() {
const { jsPDF } = window.jspdf;
const pdf = new jsPDF({ orientation: 'p', unit: 'mm', format: 'a4' });
const contentToPrint = document.getElementById('dashboard-content');
if (!contentToPrint) return;
html2canvas(contentToPrint, {
scale: 2,
useCORS: true,
onclone: (doc) => {
const chartCanvas = doc.getElementById('feeChart');
if (chartCanvas && feeChart) {
const img = new Image();
img.src = feeChart.toBase64Image();
img.style.maxWidth = '100%';
img.style.height = 'auto';
chartCanvas.parentNode.replaceChild(img, chartCanvas);
}
}
}).then(canvas => {
const imgData = canvas.toDataURL('image/png');
const pdfWidth = pdf.internal.pageSize.getWidth();
const pdfHeight = (canvas.height * pdfWidth) / canvas.width;
pdf.addImage(imgData, 'PNG', 10, 10, pdfWidth - 20, pdfHeight > 277 ? 277 : pdfHeight - 20);
pdf.save('Condo-Fee-Breakdown.pdf');
});
}