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

Function createChartGPU

src/ChartGPU.ts:449–1475  ·  view source on GitHub ↗
(
  container: HTMLElement,
  options: ChartGPUOptions
)

Source from the content-addressed store, hash-verified

447};
448
449export async function createChartGPU(
450 container: HTMLElement,
451 options: ChartGPUOptions
452): Promise<ChartGPUInstance> {
453 // Check WebGPU support before creating canvas or any resources
454 const supportCheck = await checkWebGPUSupport();
455 if (!supportCheck.supported) {
456 const reason = supportCheck.reason || 'Unknown reason';
457 throw new Error(
458 `ChartGPU: WebGPU is not available.\n` +
459 `Reason: ${reason}\n` +
460 `Browser support: Chrome/Edge 113+, Safari 18+, Firefox not yet supported.\n` +
461 `Resources:\n` +
462 ` - MDN WebGPU API: https://developer.mozilla.org/en-US/docs/Web/API/WebGPU_API\n` +
463 ` - Browser compatibility: https://caniuse.com/webgpu\n` +
464 ` - WebGPU specification: https://www.w3.org/TR/webgpu/\n` +
465 ` - Check your system: https://webgpureport.org/`
466 );
467 }
468
469 const canvas = document.createElement('canvas');
470
471 // Ensure the canvas participates in layout and can size via the container.
472 canvas.style.display = 'block';
473 canvas.style.width = '100%';
474 canvas.style.height = '100%';
475
476 // Append before awaiting so it appears immediately and has measurable size.
477 container.appendChild(canvas);
478
479 let disposed = false;
480 let gpuContext: GPUContext | null = null;
481 let coordinator: RenderCoordinator | null = null;
482 let coordinatorTargetFormat: GPUTextureFormat | null = null;
483 let unsubscribeCoordinatorInteractionXChange: (() => void) | null = null;
484
485 let dataZoomSliderHost: HTMLDivElement | null = null;
486 let dataZoomSlider: DataZoomSlider | null = null;
487
488 let currentOptions: ChartGPUOptions = options;
489 let resolvedOptions: ResolvedChartGPUOptions = resolveOptionsForChart(currentOptions);
490
491 // Chart-owned runtime series store for hit-testing only (cartesian only).
492 // - `runtimeRawDataByIndex[i]` is a mutable array used to reflect streaming appends.
493 // - `runtimeRawBoundsByIndex[i]` is incrementally updated to keep scale/bounds derivation cheap.
494 let runtimeRawDataByIndex: Array<DataPoint[] | OHLCDataPoint[]> = new Array(resolvedOptions.series.length).fill(null).map(() => []);
495 let runtimeRawBoundsByIndex: Array<Bounds | null> = new Array(resolvedOptions.series.length).fill(null);
496 let runtimeHitTestSeriesCache: ResolvedChartGPUOptions['series'] | null = null;
497 let runtimeHitTestSeriesVersion = 0;
498
499 const initRuntimeHitTestStoreFromResolvedOptions = (): void => {
500 runtimeRawDataByIndex = new Array(resolvedOptions.series.length).fill(null).map(() => []);
501 runtimeRawBoundsByIndex = new Array(resolvedOptions.series.length).fill(null);
502 runtimeHitTestSeriesCache = null;
503 runtimeHitTestSeriesVersion++;
504
505 for (let i = 0; i < resolvedOptions.series.length; i++) {
506 const s = resolvedOptions.series[i]!;

Callers

nothing calls this directly

Calls 11

checkWebGPUSupportFunction · 0.90
resolveOptionsForChartFunction · 0.90
resizeInternalFunction · 0.85
syncDataZoomUiFunction · 0.85
createMethod · 0.80
computeGlobalBoundsFunction · 0.70
disposeFunction · 0.70
recreateCoordinatorFunction · 0.70
requestRenderFunction · 0.70
disposeMethod · 0.65

Tested by

no test coverage detected