| 216 | // Throttle current candle updates to avoid overwhelming the GPU |
| 217 | let lastCurrentCandleUpdate = 0; |
| 218 | function throttledUpdateCurrentCandle() { |
| 219 | const now = performance.now(); |
| 220 | if (now - lastCurrentCandleUpdate < 100) return; |
| 221 | lastCurrentCandleUpdate = now; |
| 222 | |
| 223 | // Update just the last candle efficiently by updating the full options with new data |
| 224 | const lastIdx = data.length - 1; |
| 225 | const series0 = fullChartOptions.series?.[0]; |
| 226 | if (lastIdx >= 0 && series0 && series0.type === 'candlestick') { |
| 227 | // Preserve full series config and only update data |
| 228 | fullChartOptions = { |
| 229 | ...fullChartOptions, |
| 230 | series: [ |
| 231 | { |
| 232 | ...series0, |
| 233 | data, |
| 234 | }, |
| 235 | ], |
| 236 | }; |
| 237 | chart.setOption(fullChartOptions); |
| 238 | } |
| 239 | } |
| 240 | |
| 241 | function toggleStreaming() { |
| 242 | isStreaming = !isStreaming; |