MCPcopy Create free account
hub / github.com/ChartGPU/ChartGPU / getCanvasCssWidth

Function getCanvasCssWidth

src/core/createRenderCoordinator.ts:89–98  ·  view source on GitHub ↗

Gets canvas CSS width - clientWidth for HTMLCanvasElement, width/DPR for OffscreenCanvas.

(canvas: SupportedCanvas | null, devicePixelRatio: number = 1)

Source from the content-addressed store, hash-verified

87
88/** Gets canvas CSS width - clientWidth for HTMLCanvasElement, width/DPR for OffscreenCanvas. */
89function getCanvasCssWidth(canvas: SupportedCanvas | null, devicePixelRatio: number = 1): number {
90 if (!canvas) {
91 return 0;
92 }
93 if (isHTMLCanvasElement(canvas)) {
94 return canvas.clientWidth;
95 }
96 // OffscreenCanvas: width property is in device pixels. Convert to CSS pixels by dividing by DPR.
97 return canvas.width / devicePixelRatio;
98}
99
100/** Gets canvas CSS height - clientHeight for HTMLCanvasElement, height/DPR for OffscreenCanvas. */
101function getCanvasCssHeight(canvas: SupportedCanvas | null, devicePixelRatio: number = 1): number {

Callers 1

renderFunction · 0.85

Calls 1

isHTMLCanvasElementFunction · 0.90

Tested by

no test coverage detected