fix market flow plot

This commit is contained in:
MuslemRahimi 2025-01-02 17:17:31 +01:00
parent 1620a27fb6
commit af433d50ac

View File

@ -222,6 +222,9 @@
const netPutPremList = marketTideData?.map((item) => item?.net_put_premium); const netPutPremList = marketTideData?.map((item) => item?.net_put_premium);
const volumeList = marketTideData?.map((item) => item?.net_volume); const volumeList = marketTideData?.map((item) => item?.net_volume);
const positiveVolume = volumeList.map((v) => (v >= 0 ? v : "-"));
const negativeVolume = volumeList.map((v) => (v < 0 ? v : "-"));
const options = { const options = {
silent: true, silent: true,
animation: false, animation: false,
@ -241,28 +244,47 @@
tooltip: { tooltip: {
trigger: "axis", trigger: "axis",
hideDelay: 100, hideDelay: 100,
borderColor: "#969696", // Black border color borderColor: "#969696",
borderWidth: 1, // Border width of 1px borderWidth: 1,
backgroundColor: "#313131", // Optional: Set background color for contrast backgroundColor: "#313131",
textStyle: { textStyle: {
color: "#fff", // Optional: Text color for better visibility color: "#fff",
}, },
formatter: function (params) { formatter: function (params) {
// Get the timestamp from the first parameter
const timestamp = params[0].axisValue; const timestamp = params[0].axisValue;
// Initialize result with timestamp
let result = timestamp + "<br/>"; let result = timestamp + "<br/>";
// Sort params to ensure Vol appears last // Find volume value and determine color
params.sort((a, b) => { const volParams = params.find((p) => p.seriesName.includes("Vol"));
if (a.seriesName === "Vol") return 1; const volIndex = volParams?.dataIndex ?? 0;
if (b.seriesName === "Vol") return -1; const volValue = volumeList[volIndex];
return 0; const volColor = volValue >= 0 ? "#90EE90" : "#FF6B6B";
});
// Add each series data // Sort and filter params
params.forEach((param) => { const filteredParams = params
.filter(
(p) =>
!p.seriesName.includes("Vol") ||
p.seriesName === "Positive Vol",
)
.map((p) => {
if (p.seriesName.includes("Vol")) {
return {
...p,
seriesName: "Vol",
value: volValue,
color: volColor,
};
}
return p;
})
.sort((a, b) => {
if (a.seriesName === "Vol") return 1;
if (b.seriesName === "Vol") return -1;
return 0;
});
filteredParams.forEach((param) => {
const marker = const marker =
'<span style="display:inline-block;margin-right:4px;' + '<span style="display:inline-block;margin-right:4px;' +
"border-radius:10px;width:10px;height:10px;background-color:" + "border-radius:10px;width:10px;height:10px;background-color:" +
@ -415,16 +437,30 @@
smooth: true, smooth: true,
}, },
{ {
name: "Vol", name: "Positive Vol",
type: "line", type: "line",
data: volumeList, data: positiveVolume,
xAxisIndex: 1, xAxisIndex: 1,
yAxisIndex: 2, yAxisIndex: 2,
showSymbol: false, showSymbol: false,
areaStyle: { opacity: 1 }, areaStyle: {
itemStyle: { opacity: 1,
color: "#E11D48", color: "#19AA75",
}, },
itemStyle: { color: "#19AA75" },
},
{
name: "Negative Vol",
type: "line",
data: negativeVolume,
xAxisIndex: 1,
yAxisIndex: 2,
showSymbol: false,
areaStyle: {
opacity: 1,
color: "#F71F4F",
},
itemStyle: { color: "#F71F4F" },
}, },
], ],
}; };