High Volume Node(s) (examples): ${ofap_analysisResults.hvn.slice(0,3).map(n=>n.price.toFixed(precision)).join(', ')}
`;
}
}
function ofap_displayInterpretations() {
const container = ofap_getEl('ofap_interpretationText');
if (!container) return;
if (!ofap_analysisResults || ofap_analysisResults.interpretations.length === 0) {
container.innerHTML = '
No data processed or specific interpretations generated. Process data in Tab 1.
';
return;
}
container.innerHTML = '
' + ofap_analysisResults.interpretations.map(interp => `- ${interp}
`).join('') + '
';
}
// --- PDF Generation ---
function ofap_downloadPDF() {
if (!ofap_analysisResults) { alert("Please process data first."); return; }
if (typeof window.jspdf === 'undefined' || typeof window.jspdf.jsPDF === 'undefined') {
alert('PDF library (jsPDF) is not loaded.'); return;
}
const { jsPDF: JSPDF } = window.jspdf;
const doc = new JSPDF();
let y = 15; const m = 15; const cw = doc.internal.pageSize.getWidth() - (2 * m);
const res = ofap_analysisResults;
const precision = ofap_config.tickSizePrecision();
function addLine(text, size, style = 'normal', indent = 0, spacing = 2.5) {
if (y > 270) { doc.addPage(); y = m; }
doc.setFontSize(size); doc.setFont(undefined, style);
const lines = doc.splitTextToSize(text, cw - indent);
doc.text(lines, m + indent, y);
y += (lines.length * (size * 0.35)) + spacing;
}
addLine(`Order Flow Analysis: ${ofap_config.assetName}`, 16, 'bold', 0, 5);
addLine(`Processed ${ofap_flowEvents.length} events. Tick Size: ${ofap_config.tickSize}`, 10);
y += 5;
addLine("Key Metrics:", 12, 'bold', 0, 3);
let totalAskVolume = 0, totalBidVolume = 0;
res.volumeProfile.forEach(vp => { totalAskVolume += vp.askVolume; totalBidVolume += vp.bidVolume; });
addLine(`- Total Volume: ${totalAskVolume + totalBidVolume} (Asks: ${totalAskVolume}, Bids: ${totalBidVolume})`, 9, 'normal', 5, 1.5);
addLine(`- Overall Net Delta: ${res.overallDelta > 0 ? '+' : ''}${res.overallDelta}`, 9, 'normal', 5, 1.5);
addLine(`- Final Cumulative Delta: ${res.cumulativeDeltaPoints[res.cumulativeDeltaPoints.length-1].y > 0 ? '+' : ''}${res.cumulativeDeltaPoints[res.cumulativeDeltaPoints.length-1].y}`, 9, 'normal', 5, 1.5);
y += 3;
addLine("Volume Profile Summary:", 12, 'bold', 0, 3);
if (res.poc) addLine(`- Point of Control (POC): ${res.poc.price.toFixed(precision)} (Vol: ${res.poc.totalVolume})`, 9, 'normal', 5, 1.5);
addLine(`Top 5 Volume Levels by Price (Highest Price First):`, 9, 'bold', 5, 2);
res.volumeProfile.slice(0,5).forEach(level => { // Displaying top 5 sorted by price as in display
addLine(` Price: ${level.price.toFixed(precision)}, Total Vol: ${level.totalVolume}, Delta: ${level.delta > 0 ? '+' : ''}${level.delta} (BidV: ${level.bidVolume}, AskV: ${level.askVolume})`, 8, 'normal', 10, 1);
});
y += 5;
addLine("Conceptual Interpretations:", 12, 'bold', 0, 3);
res.interpretations.forEach(interp => addLine(`- ${interp.replace(/
|<\/strong>||<\/span>/gi, '')}`, 9, 'normal', 5, 1.5)); // Basic HTML removal
doc.save(`OrderFlow_Analysis_${ofap_config.assetName.replace(/\W+/g, '_')}.pdf`);
}