T predictions WIP

This commit is contained in:
Dobromir Popov
2025-11-22 01:02:19 +02:00
parent a7def3b788
commit f967f0a142
7 changed files with 200 additions and 39 deletions

View File

@@ -160,22 +160,42 @@ class ChartManager {
marker: { color: [[volumeColor]] }
}, [1]);
} else {
// Update last candle using restyle
const lastIndex = candlestickTrace.x.length - 1;
// Update last candle using restyle - simpler approach for updating single point
// We need to get the full arrays, modify last element, and send back
// This is less efficient but more reliable for updates than complex index logic
const x = candlestickTrace.x;
const open = candlestickTrace.open;
const high = candlestickTrace.high;
const low = candlestickTrace.low;
const close = candlestickTrace.close;
const volume = volumeTrace.y;
const colors = volumeTrace.marker.color;
const lastIdx = x.length - 1;
// Update local arrays
x[lastIdx] = candleTimestamp;
open[lastIdx] = candle.open;
high[lastIdx] = candle.high;
low[lastIdx] = candle.low;
close[lastIdx] = candle.close;
volume[lastIdx] = candle.volume;
colors[lastIdx] = candle.close >= candle.open ? '#10b981' : '#ef4444';
// Push updates to Plotly
Plotly.restyle(plotId, {
'x': [[...candlestickTrace.x.slice(0, lastIndex), candleTimestamp]],
'open': [[...candlestickTrace.open.slice(0, lastIndex), candle.open]],
'high': [[...candlestickTrace.high.slice(0, lastIndex), candle.high]],
'low': [[...candlestickTrace.low.slice(0, lastIndex), candle.low]],
'close': [[...candlestickTrace.close.slice(0, lastIndex), candle.close]]
x: [x],
open: [open],
high: [high],
low: [low],
close: [close]
}, [0]);
// Update volume
const volumeColor = candle.close >= candle.open ? '#10b981' : '#ef4444';
Plotly.restyle(plotId, {
'x': [[...volumeTrace.x.slice(0, lastIndex), candleTimestamp]],
'y': [[...volumeTrace.y.slice(0, lastIndex), candle.volume]],
'marker.color': [[...volumeTrace.marker.color.slice(0, lastIndex), volumeColor]]
x: [x],
y: [volume],
'marker.color': [colors]
}, [1]);
}