computeHexBins()
function computeHexBins<T>(layer, dimensions): HexBin[];Defined in: packages/core/src/hexbin/bins.ts:80
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 lattice is built in display units, not provider units: the pitch
transform scales metres uniformly, but on a percentage grid (Opta,
Wyscout) one x unit is 1.05 m and one y unit only 0.68 m. A lattice that
is regular in grid units would be drawn squashed and would bin points
differently from the same pitch in metres (#99). Everywhere else
displayUnitScale is [1, 1] and this changes nothing.
Type Parameters
| Type Parameter |
|---|
T |
Parameters
| Parameter | Type |
|---|---|
layer | HexbinLayer<T> |
dimensions | PitchDimensions |
Returns
HexBin[]