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

Function computePlotScissorDevicePx

src/core/createRenderCoordinator.ts:639–657  ·  view source on GitHub ↗
(
  gridArea: GridArea
)

Source from the content-addressed store, hash-verified

637};
638
639const computePlotScissorDevicePx = (
640 gridArea: GridArea
641): { readonly x: number; readonly y: number; readonly w: number; readonly h: number } => {
642 const { canvasWidth, canvasHeight, devicePixelRatio } = gridArea;
643
644 const plotLeftDevice = gridArea.left * devicePixelRatio;
645 const plotRightDevice = canvasWidth - gridArea.right * devicePixelRatio;
646 const plotTopDevice = gridArea.top * devicePixelRatio;
647 const plotBottomDevice = canvasHeight - gridArea.bottom * devicePixelRatio;
648
649 const scissorX = clampInt(Math.floor(plotLeftDevice), 0, Math.max(0, canvasWidth));
650 const scissorY = clampInt(Math.floor(plotTopDevice), 0, Math.max(0, canvasHeight));
651 const scissorR = clampInt(Math.ceil(plotRightDevice), 0, Math.max(0, canvasWidth));
652 const scissorB = clampInt(Math.ceil(plotBottomDevice), 0, Math.max(0, canvasHeight));
653 const scissorW = Math.max(0, scissorR - scissorX);
654 const scissorH = Math.max(0, scissorB - scissorY);
655
656 return { x: scissorX, y: scissorY, w: scissorW, h: scissorH };
657};
658
659const clipXToCanvasCssPx = (xClip: number, canvasCssWidth: number): number => ((xClip + 1) / 2) * canvasCssWidth;
660const clipYToCanvasCssPx = (yClip: number, canvasCssHeight: number): number => ((1 - yClip) / 2) * canvasCssHeight;

Callers 1

renderFunction · 0.70

Calls 1

clampIntFunction · 0.70

Tested by

no test coverage detected