Skip to main content

Function: binner()

binner(o): Binner

Defined in: packages/sdvplot/src/bins/squarebin.ts:170

One binning API for both lattices: binner({ radius: 15 }) is d3-hexbin's, binner({ shape: "square", side: 15 }) squares, and binner({ shape: "square", radius: 15, equalArea: true }) squares of side 15·√(3√3/2) ≈ 24.18, each the area of a radius-15 hexagon. Works on any x/y data, not just shots. Throws InputError on an unknown shape or a size that is not a positive finite number, naming the option passed.

Parameters​

o​

BinnerOptions

Returns​

Binner

Example​

import { binner } from "@sportsdataverse/sdvplot/bins";

const b = binner({ shape: "square", radius: 10, equalArea: true }); // side 16.1185…: a radius-10 hexagon's area
// three Brooklyn shots of 2025-26 (sportsdataverse-data nba_stats_shots): the two at the rim share a square
const shots = [
{ x_legacy: 0, y_legacy: 0 },
{ x_legacy: -1, y_legacy: 7 },
{ x_legacy: -44, y_legacy: 252 },
];
b.bins(shots, { x: (s) => s.x_legacy, y: (s) => s.y_legacy }).map((c) => [c.x, c.y, c.length]);