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

Function getPlotSizeCssPx

src/core/createRenderCoordinator.ts:2308–2341  ·  view source on GitHub ↗
(
    canvas: SupportedCanvas,
    gridArea: GridArea
  )

Source from the content-addressed store, hash-verified

2306 };
2307
2308 const getPlotSizeCssPx = (
2309 canvas: SupportedCanvas,
2310 gridArea: GridArea
2311 ): { readonly plotWidthCss: number; readonly plotHeightCss: number } | null => {
2312 let canvasWidthCss: number;
2313 let canvasHeightCss: number;
2314
2315 if (isHTMLCanvasElement(canvas)) {
2316 // HTMLCanvasElement: use getBoundingClientRect() for actual CSS dimensions
2317 const rect = canvas.getBoundingClientRect();
2318 if (!(rect.width > 0) || !(rect.height > 0)) return null;
2319 canvasWidthCss = rect.width;
2320 canvasHeightCss = rect.height;
2321 } else {
2322 // OffscreenCanvas: calculate CSS pixels from canvas dimensions divided by device pixel ratio
2323 const dpr = gpuContext.devicePixelRatio ?? 1.0;
2324 console.log('[getPlotSizeCssPx] OffscreenCanvas dimensions:', {
2325 canvasWidth: canvas.width,
2326 canvasHeight: canvas.height,
2327 dpr,
2328 calculatedCssWidth: canvas.width / dpr,
2329 calculatedCssHeight: canvas.height / dpr
2330 });
2331 canvasWidthCss = canvas.width / dpr;
2332 canvasHeightCss = canvas.height / dpr;
2333 if (!(canvasWidthCss > 0) || !(canvasHeightCss > 0)) return null;
2334 }
2335
2336 const plotWidthCss = canvasWidthCss - gridArea.left - gridArea.right;
2337 const plotHeightCss = canvasHeightCss - gridArea.top - gridArea.bottom;
2338 if (!(plotWidthCss > 0) || !(plotHeightCss > 0)) return null;
2339
2340 return { plotWidthCss, plotHeightCss };
2341 };
2342
2343 const computeInteractionScalesGridCssPx = (
2344 gridArea: GridArea,

Callers 2

renderFunction · 0.85

Calls 1

isHTMLCanvasElementFunction · 0.90

Tested by

no test coverage detected