`).join('');
});
}
// --- PDF GENERATION ---
async function generatePdfReport() {
downloadPdfBtn.disabled = true;
downloadPdfBtn.textContent = 'Generating...';
const renderTableRows = (trades) => trades.map(t => `${t.type} ${t.desc} $${t.value.toLocaleString()} `).join('') || `No activity recorded. `;
const reportHtml = `
`;
const pdfTemplate = document.getElementById('pdf-template');
pdfTemplate.innerHTML = reportHtml;
pdfTemplate.classList.remove('invisible');
new Chart(document.getElementById('pdf-sentiment-chart'), { type: 'bar', data: sentimentChart.data, options: { ...sentimentChart.options, animation: { duration: 0 }, maintainAspectRatio: false } });
setTimeout(async () => {
try {
const { jsPDF } = window.jspdf;
const canvas = await html2canvas(pdfTemplate.querySelector('.pdf-page'), { scale: 2 });
const imgData = canvas.toDataURL('image/png');
const pdf = new jsPDF({ orientation: 'p', unit: 'pt', format: 'a4' });
const pdfWidth = pdf.internal.pageSize.getWidth(), pdfHeight = (canvas.height * pdfWidth) / canvas.width;
pdf.addImage(imgData, 'PNG', 0, 0, pdfWidth, pdfHeight);
pdf.save(`Smart_Money_Report_${currentTicker}.pdf`);
} catch (e) { console.error('PDF Generation Error:', e); } finally {
downloadPdfBtn.disabled = false;
downloadPdfBtn.textContent = 'Download PDF Report';
pdfTemplate.classList.add('invisible');
pdfTemplate.innerHTML = '';
}
}, 500);
}
// --- EVENT LISTENERS ---
analyzeBtn.addEventListener('click', () => {
const ticker = tickerInput.value.trim().toUpperCase();
if (ticker) {
currentTicker = ticker;
analyzeData();
switchTab(0);
}
});
downloadPdfBtn.addEventListener('click', generatePdfReport);
// --- INITIALIZATION ---
analyzeData();
switchTab(0);
});
Smart Money Insights Report
TICKER: ${currentTicker} | DATE: ${new Date().toLocaleDateString()}
BULLISH FLOW
$${(analysisResults.bullishFlow/1_000_000).toFixed(1)}M
BEARISH FLOW
$${(analysisResults.bearishFlow/1_000_000).toFixed(1)}M
SENTIMENT
${analysisResults.sentimentScore.toFixed(1)}%
Institutional Flow Breakdown
Notable Bullish Transactions
| Type | Description | Value |
|---|
Notable Bearish Transactions
| Type | Description | Value |
|---|
