Geopolitical Tensions & Market Risk Simulator

Geopolitical Tensions & Market Risk Simulator

Define Scenario

Primary Affected Region(s): (Select all applicable)

Asset Classes to Analyze: (Select all applicable)

Key Risk Factors:

${riskFactorsHTML}

Potential Safe Havens/Considerations:

${safeHavensHTML} `; resultsDisplayAreaEl.appendChild(card); } function displayMessage(text, type) { messageArea.textContent = text; messageArea.className = type === 'error' ? 'message-error' : (type === 'info' ? 'message-info' : ''); } // PDF Download Functionality downloadPdfButton.addEventListener('click', function () { const pdfExportContent = document.getElementById('pdfExportContent'); if (!pdfExportContent) { displayMessage('Error: PDF content area not found.', 'error'); return; } // Ensure section is visible for capture const originalDisplay = pdfExportContent.style.display; pdfExportContent.style.display = 'block'; html2canvas(pdfExportContent, { scale: 2, useCORS: true, logging: false }).then(canvas => { const imgData = canvas.toDataURL('image/png'); const { jsPDF } = window.jspdf; const pdf = new jsPDF({ orientation: 'p', unit: 'mm', format: 'a4' }); const pdfWidth = pdf.internal.pageSize.getWidth(); const pdfHeight = pdf.internal.pageSize.getHeight(); const canvasWidth = canvas.width; const canvasHeight = canvas.height; // Calculate aspect ratio const contentAspectRatio = canvasWidth / canvasHeight; const margin = 15; // 15mm margin on all sides const usableWidth = pdfWidth - (2 * margin); const usableHeight = pdfHeight - (2 * margin); let imgWidth = usableWidth; let imgHeight = imgWidth / contentAspectRatio; // If calculated height is too much, scale by height if (imgHeight > usableHeight) { imgHeight = usableHeight; imgWidth = imgHeight * contentAspectRatio; } // If after scaling by height, width is too much (shouldn't happen if logic is right, but good check) if (imgWidth > usableWidth) { imgWidth = usableWidth; imgHeight = imgWidth / contentAspectRatio; } const x = margin + (usableWidth - imgWidth) / 2; // Center within usable area const y = margin; // Add a title to the PDF pdf.setFontSize(18); pdf.text("Geopolitical Risk Simulation Report", pdfWidth / 2, margin / 1.5 , { align: "center" }); pdf.addImage(imgData, 'PNG', x, y, imgWidth, imgHeight); pdf.save('geopolitical-risk-simulation.pdf'); // Restore original display if it was none pdfExportContent.style.display = originalDisplay; }).catch(error => { console.error('Error generating PDF:', error); displayMessage('Failed to generate PDF. See console for details.', 'error'); pdfExportContent.style.display = originalDisplay; }); }); });
Scroll to Top