Central Bank Rate Decision Impact Model

Central Bank Rate Decision Impact Model

Input Parameters

Sectors/Economic Indicators to Analyze:

Impact Assessment

Please input parameters and click "Analyze Impact" to see results.

Rationale: ${impact.rationale}

`; resultsArea.appendChild(card); } /** * Displays a message in the messageArea. * @param {string} text - The message text. * @param {string} type - 'error' or 'info'. */ function displayMessage(text, type) { messageArea.textContent = text; messageArea.className = type === 'error' ? 'message-error' : 'message-info'; } /** * Handles PDF download functionality. */ downloadPdfButton.addEventListener('click', function () { const pdfExportContent = document.getElementById('pdfExportContent'); if (!pdfExportContent) { console.error('PDF export content area not found.'); displayMessage('Error preparing PDF: Content area missing.', 'error'); return; } // Temporarily make sure results header is visible for capture if it was empty const originalHeaderDisplay = resultsHeaderEl.style.display; if (!resultsHeaderEl.textContent && resultsArea.innerHTML.includes('With no change')) { resultsHeaderEl.textContent = `Assessment for No Change in Rates:`; // Default for no change scenario resultsHeaderEl.style.display = 'block'; // Ensure it's visible } // Use html2canvas to capture the content html2canvas(pdfExportContent, { scale: 2, useCORS: true }).then(canvas => { const imgData = canvas.toDataURL('image/png'); const { jsPDF } = window.jspdf; // Access jsPDF from the global scope // Calculate PDF dimensions based on canvas aspect ratio // A4 page is 210mm wide x 297mm tall. const pdf = new jsPDF({ orientation: 'p', // portrait unit: 'mm', // millimeters format: 'a4' }); const pdfWidth = pdf.internal.pageSize.getWidth(); const pdfHeight = pdf.internal.pageSize.getHeight(); const canvasWidth = canvas.width; const canvasHeight = canvas.height; const canvasAspectRatio = canvasWidth / canvasHeight; let imgWidth = pdfWidth - 20; // With 10mm margins let imgHeight = imgWidth / canvasAspectRatio; if (imgHeight > pdfHeight - 20) { // If height exceeds page, scale by height imgHeight = pdfHeight - 20; imgWidth = imgHeight * canvasAspectRatio; } const x = (pdfWidth - imgWidth) / 2; // Center the image const y = 10; // 10mm margin from top pdf.setFontSize(16); pdf.text("Central Bank Rate Decision Impact Model - Results", pdfWidth / 2, y + 5, { align: "center" }); pdf.addImage(imgData, 'PNG', x, y + 15, imgWidth, imgHeight); pdf.save('central-bank-impact-analysis.pdf'); // Restore original display if changed if (!resultsHeaderEl.textContent && resultsArea.innerHTML.includes('With no change')) { resultsHeaderEl.textContent = ''; // Clear it back resultsHeaderEl.style.display = originalHeaderDisplay; } }).catch(error => { console.error('Error generating PDF:', error); displayMessage('Failed to generate PDF. See console for details.', 'error'); // Restore original display on error too if (!resultsHeaderEl.textContent && resultsArea.innerHTML.includes('With no change')) { resultsHeaderEl.textContent = ''; resultsHeaderEl.style.display = originalHeaderDisplay; } }); }); });
Scroll to Top