`;
const colors = ['#4f46e5', '#a5b4fc', '#d1d5db']; // Indigo, Light Indigo, Gray
let colorIndex = 0;
for (const [asset, percentage] of Object.entries(result.allocation)) {
tableHtml += `
`;
}
tableHtml += `
`;
tableContainer.innerHTML = tableHtml;
const ctx = document.getElementById('allocation-chart').getContext('2d');
if (allocationChart) allocationChart.destroy();
allocationChart = new Chart(ctx, {
type: 'doughnut',
data: {
labels: Object.keys(result.allocation),
datasets: [{
data: Object.values(result.allocation),
backgroundColor: colors,
borderColor: '#f9fafb',
borderWidth: 4,
hoverOffset: 8
}]
},
options: {
responsive: true,
maintainAspectRatio: false,
plugins: {
legend: { display: false }
},
cutout: '65%'
}
});
pdfButtonContainer.classList.remove('hidden');
}
/**
* Handles PDF Download
*/
async function handlePdfDownload() {
if (!lastResult) return;
const { jsPDF } = window.jspdf;
// 1. Populate the hidden PDF template
document.getElementById('pdf-report-date').textContent = `Generated: ${new Date().toLocaleDateString()}`;
document.getElementById('pdf-profile-name').textContent = lastResult.name;
document.getElementById('pdf-profile-desc').textContent = lastResult.desc;
const chartImgData = allocationChart.toBase64Image();
document.getElementById('pdf-chart-container').innerHTML = `${asset}
${percentage}%
| Asset Class | Percentage |
|---|---|
| ${asset} | ${percentage}% |
