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

Method init

src/worker/ChartGPUWorkerProxy.ts:393–432  ·  view source on GitHub ↗

* Initializes the worker chart instance. * Must be called before using the chart. * * @returns Promise that resolves when worker is ready

()

Source from the content-addressed store, hash-verified

391 * @returns Promise that resolves when worker is ready
392 */
393 async init(): Promise<void> {
394 // Create OffscreenCanvas for worker rendering
395 const canvas = document.createElement('canvas');
396 canvas.style.display = 'block';
397 canvas.style.width = '100%';
398 canvas.style.height = '100%';
399 this.container.appendChild(canvas);
400
401 // Get canvas dimensions
402 const rect = canvas.getBoundingClientRect();
403 const dpr = window.devicePixelRatio || 1;
404 const width = Math.max(1, Math.round(rect.width * dpr));
405 const height = Math.max(1, Math.round(rect.height * dpr));
406
407 canvas.width = width;
408 canvas.height = height;
409
410 // Set up event listeners on canvas BEFORE transferring to worker
411 this.setupEventListeners(canvas);
412
413 // Set up ResizeObserver and device pixel ratio monitoring BEFORE transferring canvas
414 this.setupResizeObserver(canvas);
415 this.setupDevicePixelRatioMonitoring();
416
417 // Create DOM overlays AFTER canvas is in DOM (overlays need container)
418 this.createOverlays();
419
420 // Transfer canvas to worker
421 const offscreenCanvas = canvas.transferControlToOffscreen();
422
423 // Send init message and wait for ready response
424 await this.sendMessageWithResponse<ReadyMessage>({
425 type: 'init',
426 chartId: this.chartId,
427 messageId: generateMessageId(),
428 canvas: offscreenCanvas,
429 devicePixelRatio: dpr,
430 options: this.cachedOptions,
431 }, [offscreenCanvas]);
432 }
433
434 // =============================================================================
435 // Event Forwarding to Worker

Callers 1

createChartInWorkerFunction · 0.95

Calls 5

setupEventListenersMethod · 0.95
setupResizeObserverMethod · 0.95
createOverlaysMethod · 0.95
generateMessageIdFunction · 0.85

Tested by

no test coverage detected