Use Canvas Layers
@genomics/use-canvas-layers
Hover without repainting a million points.
Preview
Differential expression
built on usePlotSurface
32 genes · hover, or tab in and use arrow keys
About
One canvas and one draw is right for a virtualized grid and wrong for anything interactive, because hover becomes a dependency of the draw: move the pointer over a Manhattan plot and the entire variant cloud is re-rasterized to move one ring. Layers are declared in paint order, each with its own draw and its own dependency list, so a change to one repaints only that one. Theme tokens are passed in rather than closed over, which is what makes a dark-mode switch repaint every layer instead of leaving a static axis in light-mode colors.
Usage
import { useCanvasLayers } from "@/components/ui/use-canvas-layers"
const { wrapRef, layerProps } = useCanvasLayers({
height: 240,
tokens,
layers: [
{ name: "data", draw: drawPoints, deps: [hits, x, y] },
{ name: "marks", draw: drawHover, deps: [hovered] },
],
})Registry dependencies
Source:
components/ui/use-canvas-layers.ts