`;
});
newsSentimentDisplay.innerHTML = newsHtml;
}
/**
* Displays simulated COT report insights.
*/
function displayCOTInsights() {
if (!cotInsightsDisplay) return; // Null check
let cotHtml = '
`;
cotInsightsDisplay.innerHTML = cotHtml;
}
/**
* Generates the comprehensive sentiment report content within the UI.
*/
window.generateSentimentReport = function() {
if (!reportContentDiv || !sentimentReportOutput) return; // Null check
let reportHtml = `
Key insights from hypothetical Commitment of Traders (COT) report data:
'; cotHtml += `| Currency | Large Speculators Net Position | Interpretation |
|---|---|---|
| ${item.currency} | ${item.largeSpeculatorsNet} | ${item.interpretation} |
Forex Market Sentiment Report
Date: ${new Date().toLocaleDateString('en-US', { year: 'numeric', month: 'long', day: 'numeric' })}
1. Retail Trader Sentiment
| Pair | Long (%) | Short (%) | Interpretation |
|---|---|---|---|
| ${pair} | ${data.long} | ${data.short} | ${data.description} |
2. News Sentiment Analysis
| Headline | Sentiment | Potential Impact |
|---|---|---|
| ${item.headline} | ${item.sentiment} | ${item.impact} |
3. COT Report Insights (Hypothetical)
| Currency | Large Speculators Net Position | Interpretation |
|---|---|---|
| ${item.currency} | ${item.largeSpeculatorsNet} | ${item.interpretation} |
Note: This report is based on simulated sentiment data for illustrative purposes. Real-time market sentiment analysis requires access to live data sources.
`; reportContentDiv.innerHTML = reportHtml; sentimentReportOutput.classList.remove('hidden'); // Show the report section }; /** * Downloads the generated sentiment report as a PDF. */ window.downloadSentimentPdf = function() { if (!reportContentDiv || !downloadPdfBtn) { // Null check console.error("Report content or download button not found for PDF generation."); return; } // Temporarily hide the download button within the report for PDF capture const originalDisplay = downloadPdfBtn.style.display; downloadPdfBtn.style.display = 'none'; // Use a temporary div to capture only the report content const tempDiv = document.createElement('div'); tempDiv.innerHTML = reportContentDiv.innerHTML; tempDiv.style.backgroundColor = '#ffffff'; // Ensure white background for PDF tempDiv.style.padding = '20px'; // Add some padding document.body.appendChild(tempDiv); // Append to body for rendering context html2canvas(tempDiv, { scale: 2, useCORS: true, logging: false }).then(canvas => { const imgData = canvas.toDataURL('image/png'); const { jsPDF } = window.jspdf; const pdf = new jsPDF('p', 'mm', 'a4'); // 'p' for portrait, 'mm' for millimeters, 'a4' size const imgWidth = 210; // A4 width in mm const pageHeight = 297; // A4 height in mm const imgHeight = canvas.height * imgWidth / canvas.width; let heightLeft = imgHeight; let position = 0; pdf.addImage(imgData, 'PNG', 0, position, imgWidth, imgHeight); heightLeft -= pageHeight; while (heightLeft >= 0) { position = heightLeft - imgHeight; pdf.addPage(); pdf.addImage(imgData, 'PNG', 0, position, imgWidth, imgHeight); heightLeft -= pageHeight; } pdf.save("Forex_Sentiment_Report.pdf"); document.body.removeChild(tempDiv); // Clean up the temporary div downloadPdfBtn.style.display = originalDisplay; // Restore button display }).catch(error => { console.error("Error generating PDF:", error); // Re-show the button even if there's an error downloadPdfBtn.style.display = originalDisplay; }); }; // --- Event Listeners --- if (pairSelect) { pairSelect.addEventListener('change', displayRetailSentiment); } // Initial display and setup switchTab(0); // Activate the first tab by default updateNavButtons(); // Set initial nav button states });