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

Function generateData

examples/worker-rendering/main.ts:267–295  ·  view source on GitHub ↗
(
  count: number, 
  dataType: DataType,
  onProgress?: (progress: number) => void
)

Source from the content-addressed store, hash-verified

265// ============================================================================
266
267async function generateData(
268 count: number,
269 dataType: DataType,
270 onProgress?: (progress: number) => void
271): Promise<DataPoint[] | OHLCDataPoint[]> {
272 const chunkSize = 100000; // Generate in chunks to avoid blocking
273 const chunks: Array<DataPoint[] | OHLCDataPoint[]> = [];
274
275 for (let i = 0; i < count; i += chunkSize) {
276 const currentChunkSize = Math.min(chunkSize, count - i);
277
278 // Generate chunk
279 const chunk = generateChunk(i, currentChunkSize, dataType);
280 chunks.push(chunk);
281
282 // Update progress
283 if (onProgress) {
284 onProgress((i + currentChunkSize) / count);
285 }
286
287 // Yield to event loop every chunk
288 if (i + chunkSize < count) {
289 await new Promise(resolve => setTimeout(resolve, 0));
290 }
291 }
292
293 // Type assertion is safe because all chunks are guaranteed to be the same type
294 return chunks.flat() as DataPoint[] | OHLCDataPoint[];
295}
296
297function generateChunk(
298 startIndex: number,

Callers 1

handleGenerateFunction · 0.85

Calls 1

generateChunkFunction · 0.85

Tested by

no test coverage detected