Private Equity Portfolio Diversification Tool

Add Private Equity Investment

Current Investments

No investments added yet.

Portfolio Diversification Summary

Diversification by Geography

Diversification by Sector

Diversification by Vintage Year

Investment Details

No data for vintage year chart.

'; return; } const geoData = aggregateData('geography'); const sectorData = aggregateData('sector'); const vintageData = aggregateData('vintageYear'); renderBarChart(geoChartContainer, geoData, totalCommitment, 'Geography'); renderBarChart(sectorChartContainer, sectorData, totalCommitment, 'Sector'); renderBarChart(vintageChartContainer, vintageData, totalCommitment, 'Vintage Year'); renderInvestmentsTable(); // Ensure summary table is also updated } function aggregateData(key) { const aggregation = {}; investments.forEach(inv => { const value = inv[key]; aggregation[value] = (aggregation[value] || 0) + inv.commitmentAmount; }); return Object.entries(aggregation).map(([name, amount]) => ({ name, amount })).sort((a,b) => b.amount - a.amount); } function renderBarChart(container, data, total, title) { container.innerHTML = ''; // Clear previous chart if (data.length === 0 || total === 0) { container.innerHTML = `

No data available for ${title}.

`; return; } data.forEach(item => { const percentage = (item.amount / total * 100); const barItem = document.createElement('div'); barItem.className = 'pedt-bar-item'; const label = document.createElement('div'); label.className = 'pedt-bar-label'; label.textContent = item.name; label.title = `${item.name}: $${item.amount.toLocaleString()}`; const bar = document.createElement('div'); bar.className = 'pedt-bar'; if (percentage === 0) bar.classList.add('empty'); bar.style.width = percentage > 0 ? `${percentage.toFixed(1)}%` : '100%'; bar.textContent = percentage > 0 ? `${percentage.toFixed(1)}%` : '0%'; if (percentage === 0) bar.textContent = `0% ($${item.amount.toLocaleString()})`; barItem.appendChild(label); barItem.appendChild(bar); container.appendChild(barItem); }); } if (downloadPdfButton) { downloadPdfButton.addEventListener('click', function () { const { jsPDF } = window.jspdf; const pdfOutputArea = document.getElementById('pedtPdfOutputArea'); if (!pdfOutputArea) { alert('Error: PDF output area not found.'); return; } if (investments.length === 0) { alert('Please add some investments before downloading PDF.'); return; } // Temporarily ensure the summary tab content is rendered for PDF capture const summaryTabWasActive = document.getElementById('summaryTab').classList.contains('active'); if (!summaryTabWasActive) { // Ensure summary is rendered if not already active for PDF generation renderSummary(); // This updates the #pedtPdfOutputArea } html2canvas(pdfOutputArea, { scale: 2, // Improve resolution useCORS: true, // For any external images if they were used (not in this case) backgroundColor: '#ffffff', // Ensure a white background onclone: (document) => { // Ensure styles are applied correctly in the cloned document for canvas rendering // This is particularly important for background colors in charts/tables // Forcing color application might be needed for some browsers if !important in CSS isn't enough } }).then(canvas => { const imgData = canvas.toDataURL('image/png'); const pdf = new jsPDF({ orientation: 'portrait', unit: 'pt', // points format: 'a4' }); const pdfWidth = pdf.internal.pageSize.getWidth(); const pdfHeight = pdf.internal.pageSize.getHeight(); const canvasWidth = canvas.width; const canvasHeight = canvas.height; const ratio = canvasWidth / canvasHeight; let imgWidth = pdfWidth - 40; // margins 20pt each side let imgHeight = imgWidth / ratio; if (imgHeight > pdfHeight - 40) { // check if it fits with margin imgHeight = pdfHeight - 40; imgWidth = imgHeight * ratio; } const x = (pdfWidth - imgWidth) / 2; const y = 20; // top margin pdf.addImage(imgData, 'PNG', x, y, imgWidth, imgHeight); pdf.save('PrivateEquity_Diversification_Summary.pdf'); // Restore previous state if needed (not strictly necessary here as we just read content) }).catch(err => { console.error("Error generating PDF:", err); alert("Sorry, there was an error generating the PDF. Please try again."); }); }); } function escapeHtml(unsafe) { if (typeof unsafe !== 'string') { if (typeof unsafe === 'number' || typeof unsafe === 'boolean') { return unsafe.toString(); } return ''; // Or handle other types as needed } return unsafe .replace(/&/g, "&") .replace(//g, ">") .replace(/"/g, """) .replace(/'/g, "'"); } // Initial render if there's any pre-existing data (not in this version, but good practice) renderInvestmentsTable(); // Set default tab switchTab('inputTab'); });
Scroll to Top