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

Function setupControls

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

Source from the content-addressed store, hash-verified

428}
429
430function setupControls() {
431 document.getElementById('toggle-btn')!.addEventListener('click', toggleStreaming);
432 document.getElementById('autoscroll-btn')!.addEventListener('click', toggleAutoScroll);
433
434 // Style toggle
435 let isHollow = false;
436 document.getElementById('style-btn')!.addEventListener('click', () => {
437 isHollow = !isHollow;
438 // Preserve full options when changing style
439 const series0 = fullChartOptions.series?.[0];
440 if (series0 && series0.type === 'candlestick') {
441 fullChartOptions = {
442 ...fullChartOptions,
443 series: [
444 {
445 ...series0,
446 style: isHollow ? 'hollow' : 'classic',
447 data,
448 },
449 ],
450 };
451 chart.setOption(fullChartOptions);
452 }
453 document.getElementById('style-btn')!.textContent = isHollow ? 'Style: Hollow' : 'Style: Classic';
454 });
455
456 // Timeframe buttons - actually switch intervals
457 document.querySelectorAll('.timeframe-btn').forEach((btn) => {
458 btn.addEventListener('click', (e) => {
459 const tf = (e.target as HTMLElement).dataset.tf;
460 if (!tf) return;
461
462 // Update active button state
463 document.querySelectorAll('.timeframe-btn').forEach((b) => b.classList.remove('active'));
464 (e.target as HTMLElement).classList.add('active');
465
466 // Switch to the new timeframe
467 switchTimeframe(tf);
468 });
469 });
470
471 // Candle count preset buttons
472 document.querySelectorAll('.preset-btn').forEach((btn) => {
473 btn.addEventListener('click', (e) => {
474 const count = parseInt((e.target as HTMLElement).dataset.count || '60', 10);
475
476 // Update active button state
477 document.querySelectorAll('.preset-btn').forEach((b) => b.classList.remove('active'));
478 (e.target as HTMLElement).classList.add('active');
479
480 // Switch to the new candle count
481 switchCandleCount(count);
482 });
483 });
484
485 window.addEventListener('resize', () => chart.resize());
486}
487

Callers 1

initFunction · 0.85

Calls 4

switchTimeframeFunction · 0.85
switchCandleCountFunction · 0.85
setOptionMethod · 0.65
resizeMethod · 0.65

Tested by

no test coverage detected