computeHexBins()
function computeHexBins<T>(layer, dimensions): HexBin[];Defined in: packages/core/src/hexbin/bins.ts:62
Buckets points into a hexagonal lattice over the pitch — mplsoccer's
hexbin. Hexagons pack more evenly than squares (every neighbour is
equidistant), so dense event data reads with less of the axis-aligned
banding a rectangular Heatmap shows.
Hand-rolled rather than taking d3-hexbin, to preserve
@pitchkit/core's zero-runtime-dependency invariant — the same call
color/scale.ts documents. The lattice itself is d3-hexbin's: two
interleaved rectangular grids (odd rows offset by half a column), where
a point's bin is the nearer of the two candidate centres. Bins with no
points are omitted rather than returned with value: 0; unlike a
rectangular grid, an empty hex has no cell to shade in a tiling that
never covers the pitch exactly at its edges anyway.
Cell size is driven by binsX (hexagon columns across the pitch
length), mirroring Heatmap's binsX, rather than an absolute radius —
so the same layer looks right on a 120x80 StatsBomb pitch and a 100x100
Opta one. The pitch transform is uniform-scale (see
createPixelTransform), so hexagons that are regular in provider units
stay regular in pixels.
Type Parameters
| Type Parameter |
|---|
T |
Parameters
| Parameter | Type |
|---|---|
layer | HexbinLayer<T> |
dimensions | PitchDimensions |
Returns
HexBin[]