Total Deals (YTD)
${formatNumber(totalDeals)}
Average Deal Size
${new Intl.NumberFormat('en-US', { style: 'currency', currency: 'USD', notation: 'compact', compactDisplay: 'short' }).format(avgDealSize)}
Top Sector by Deals
${topSector}
Quarterly Funding Volume (USA)
`;
renderCharts();
document.getElementById('download-pdf-btn').addEventListener('click', generatePdf);
};
const renderCharts = () => {
// Quarterly Funding Chart
const qfcCtx = document.getElementById('quarterlyFundingChart').getContext('2d');
if(charts.quarterly) charts.quarterly.destroy();
charts.quarterly = new Chart(qfcCtx, {
type: 'line',
data: {
labels: appData.quarterlyFunding.map(d => d.quarter),
datasets: [{ label: 'Funding ($B)', data: appData.quarterlyFunding.map(d => d.amount), borderColor: '#7c3aed', backgroundColor: 'rgba(124, 58, 237, 0.1)', fill: true, tension: 0.3 }]
},
options: { responsive: true, maintainAspectRatio: false, scales: { y: { ticks: { callback: value => `$${value}B` }}}}
});
// Funding Stage Chart
const fscCtx = document.getElementById('fundingStageChart').getContext('2d');
if(charts.stage) charts.stage.destroy();
charts.stage = new Chart(fscCtx, {
type: 'bar',
data: {
labels: appData.fundingByStage.map(d => d.stage),
datasets: [{ label: 'Amount ($B)', data: appData.fundingByStage.map(d => d.amount), backgroundColor: ['#60a5fa', '#34d399', '#facc15', '#f87171'] }]
},
options: { responsive: true, maintainAspectRatio: false, indexAxis: 'y', plugins: { legend: { display: false } }, scales: { x: { ticks: { callback: value => `$${value}B` }}}}
});
};
const renderDataConfig = () => {
const configContent = document.getElementById('content-data-config');
if (!configContent) return;
let stageHtml = appData.fundingByStage.map((item, index) => `
`).join('');
let sectorHtml = appData.dealsBySector.map((item, index) => `
`).join('');
configContent.innerHTML = `
`;
document.getElementById('data-config-form').addEventListener('submit', handleConfigUpdate);
};
const handleConfigUpdate = (e) => {
e.preventDefault();
document.querySelectorAll('#data-config-form input').forEach(input => {
const { type, index, field } = input.dataset;
const value = input.type === 'number' ? parseFloat(input.value) : input.value;
if(appData[type] && appData[type][index]) {
appData[type][index][field] = value;
}
});
alert('Market data updated!');
renderDashboard(); // Re-render dashboard with new data
};
const generatePdf = () => {
loadingOverlay.style.display = 'flex';
const { jsPDF } = window.jspdf;
const pdfContent = document.getElementById('pdf-content-area');
const pdfHeader = document.getElementById('pdf-header');
document.getElementById('pdf-generated-date').textContent = new Date().toLocaleDateString('en-US', { year: 'numeric', month: 'long', day: 'numeric' });
pdfHeader.classList.remove('hidden');
html2canvas(pdfContent, { scale: 2, useCORS: true, logging: false })
.then(canvas => {
pdfHeader.classList.add('hidden');
const imgData = canvas.toDataURL('image/jpeg', 0.95);
const pdf = new jsPDF({ orientation: 'landscape', unit: 'px', format: 'a4' });
const pdfWidth = pdf.internal.pageSize.getWidth();
const imgProps = pdf.getImageProperties(imgData);
const imgHeight = (imgProps.height * pdfWidth) / imgProps.width;
pdf.addImage(imgData, 'JPEG', 0, 0, pdfWidth, imgHeight);
pdf.save('VC-Market-Analysis-Report.pdf');
loadingOverlay.style.display = 'none';
}).catch(err => {
console.error("PDF generation failed:", err);
pdfHeader.classList.add('hidden');
loadingOverlay.style.display = 'none';
alert('An error occurred generating the PDF.');
});
};
// --- TAB NAVIGATION & INITIALIZATION ---
const switchTab = (tabIndex) => {
activeTabIndex = tabIndex;
document.querySelectorAll('.tab-btn').forEach((btn, i) => btn.classList.toggle('active', i === tabIndex));
document.querySelectorAll('.tab-content').forEach((content, i) => content.classList.toggle('hidden', i !== tabIndex));
updateNavButtons();
};
const updateNavButtons = () => {
prevTabBtn.disabled = activeTabIndex === 0;
nextTabBtn.disabled = activeTabIndex === tabIdentifiers.length - 1;
};
const initializeUI = () => {
const tabs = [
{ name: 'VC Market Dashboard', id: 'dashboard' },
{ name: 'Data Configuration', id: 'data-config' }
];
tabIdentifiers = tabs.map(t => t.id);
tabsContainer.innerHTML = tabs.map(tab => `
`).join('');
mainContent.innerHTML = tabs.map(tab => `
`).join('');
tabs.forEach((tab, index) => {
document.getElementById(`tab-${tab.id}`).addEventListener('click', () => switchTab(index));
});
renderDashboard();
renderDataConfig();
switchTab(0);
};
initializeUI();
lucide.createIcons();
prevTabBtn.addEventListener('click', () => { if (activeTabIndex > 0) switchTab(activeTabIndex - 1); });
nextTabBtn.addEventListener('click', () => { if (activeTabIndex < tabIdentifiers.length - 1) switchTab(activeTabIndex + 1); });
});