MCPcopy Index your code
hub / github.com/ChartGPU/ChartGPU / throttledUpdateCurrentCandle

Function throttledUpdateCurrentCandle

examples/candlestick-streaming/main.ts:218–239  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

216// Throttle current candle updates to avoid overwhelming the GPU
217let lastCurrentCandleUpdate = 0;
218function 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
241function toggleStreaming() {
242 isStreaming = !isStreaming;

Callers 1

handleTickFunction · 0.85

Calls 1

setOptionMethod · 0.65

Tested by

no test coverage detected