`;
function renderChart(factorScores) {
if (factorsChart) factorsChart.destroy();
factorsChart = new Chart(document.getElementById('factors-chart'), {
type: 'bar',
data: {
labels: ['Payment History', 'Credit Utilization', 'Credit Age', 'Credit Mix', 'New Credit'],
datasets: [{ label: 'Impact Points', data: factorScores, backgroundColor: '#0ea5e9' }]
},
options: { indexAxis: 'y', plugins: { legend: { display: false } } }
});
}
// --- PDF GENERATION ---
async function generatePdfReport() {
if (!state.analysisResult) return alert("Please run an analysis first.");
downloadPdfBtn.disabled = true;
downloadPdfBtn.textContent = 'Generating...';
const chartImg = factorsChart.toBase64Image();
const { score, rating, kpis } = state.analysisResult;
const reportHtml = `
`;
const pdfTemplate = document.getElementById('pdf-template');
pdfTemplate.innerHTML = reportHtml;
pdfTemplate.classList.remove('invisible');
try {
const { jsPDF } = window.jspdf;
const canvas = await html2canvas(pdfTemplate.querySelector('.pdf-report-container'), { scale: 2 });
const imgData = canvas.toDataURL('image/png');
const pdf = new jsPDF({ orientation: 'p', unit: 'pt', format: 'a4' });
pdf.addImage(imgData, 'PNG', 0, 0, pdf.internal.pageSize.getWidth(), (canvas.height * pdf.internal.pageSize.getWidth()) / canvas.width);
pdf.save(`Simulated_Credit_Report.pdf`);
} catch(e) { console.error('PDF Generation Error:', e);
} finally {
downloadPdfBtn.disabled = false;
downloadPdfBtn.textContent = 'Download Credit Report';
pdfTemplate.classList.add('invisible');
}
}
downloadPdfBtn.addEventListener('click', generatePdfReport);
// --- INITIALIZATION ---
populateProfileInputs();
renderItemLists();
attachDataListeners();
runAnalysis();
switchTab(0);
});
Personal Credit Report
Simulated report as of ${new Date().toLocaleDateString()}
${score}
Key Credit Factors
Credit Utilization
${kpis.utilization.toFixed(1)}%
On-Time Payments
${kpis.onTimePayments.toFixed(1)}%
Avg. Account Age
${kpis.accountAge} yrs
Hard Inquiries
${kpis.hardInquiries}
