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

Function init

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

Source from the content-addressed store, hash-verified

88}
89
90async function init() {
91 const container = document.getElementById('chart')!;
92
93 // Generate impressive historical data
94 console.log(`Generating ${currentCandleCount.toLocaleString()} historical candles...`);
95 const startGen = performance.now();
96
97 data = generateHistoricalData({
98 symbol: CONFIG.symbol,
99 startPrice: CONFIG.startPrice,
100 volatility: 0.03, // 3% volatility like static example for nice candle sizes
101 candleCount: currentCandleCount,
102 intervalMs: candleIntervalMs,
103 });
104
105 console.log(`Generated in ${(performance.now() - startGen).toFixed(0)}ms`);
106
107 // Get last price for tick simulator
108 const lastCandle = data[data.length - 1];
109 const lastPrice = getClose(lastCandle); // close price
110
111 // Seed simulated time from the most recent historical candle so the first live candle
112 // continues smoothly after history (instead of starting far in the past/future).
113 simulatedTimeMs = getTimestamp(lastCandle) + candleIntervalMs;
114 lastSimPerfNow = performance.now();
115
116 // Create chart
117 fullChartOptions = {
118 xAxis: { type: 'time', name: 'Time' },
119 yAxis: { type: 'value', name: `${CONFIG.symbol}` },
120 series: [
121 {
122 type: 'candlestick',
123 name: CONFIG.symbol,
124 data,
125 style: 'classic',
126 itemStyle: {
127 upColor: '#22c55e',
128 downColor: '#ef4444',
129 upBorderColor: '#16a34a',
130 downBorderColor: '#dc2626',
131 },
132 sampling: 'ohlc',
133 samplingThreshold: 2000,
134 },
135 ],
136 dataZoom: getDataZoomConfig(currentCandleCount),
137 tooltip: { trigger: 'item' },
138 animation: false, // Critical for streaming performance
139 autoScroll: true,
140 };
141 chart = await createChart(container, fullChartOptions);
142
143 // Setup tick simulator
144 candleAggregator = createCandleAggregator(candleIntervalMs);
145
146 tickSimulator = createTickSimulator({
147 initialPrice: lastPrice,

Callers 1

main.tsFile · 0.70

Calls 11

generateHistoricalDataFunction · 0.90
createCandleAggregatorFunction · 0.90
createTickSimulatorFunction · 0.90
getDataZoomConfigFunction · 0.85
setupControlsFunction · 0.85
startStatsLoopFunction · 0.85
toggleStreamingFunction · 0.85
updateStatsFunction · 0.85
getCloseFunction · 0.70
getTimestampFunction · 0.70
createChartFunction · 0.50

Tested by

no test coverage detected