/** A point to count: where it is, a number it carries (optional) and whether it counts as a success (a goal, a made shot). */ export interface Sample { x: number; y: number; value?: number | null; hit?: boolean; /** Which input it was, for a caller who wants its tooltip. */ index?: number; } /** The statistics of a bin. `percent` is each bin's share of all the samples (0 to 100); `rate` is the share of a bin's samples that are hits (0 to 100). */ export type StatisticName = "count" | "sum" | "mean" | "median" | "percent" | "max" | "min" | "rate"; /** What a bin holds, and what a custom reducer is told. */ export interface BinInfo { /** How many samples fell in the bin. */ count: number; /** How many of them were hits. */ hits: number; /** How many samples were binned in all. */ total: number; } /** A custom statistic: the finite values of a bin's samples (an empty list when none had one), and the bin's counts. Return `null` for a bin that has no value. */ export type Reducer = (values: readonly number[], info: BinInfo) => number | null; /** One bin's accumulator. */ export interface Bin { n: number; hits: number; sum: number; nv: number; low: number; high: number; values: number[] | undefined; } export declare const newBin: (keep: boolean) => Bin; /** True for a statistic that needs the list of values (the median and a custom reducer). */ export declare const needsValues: (statistic: StatisticName | Reducer) => boolean; /** The median of a list that is not empty. */ export declare function median(values: readonly number[]): number; /** The value of a bin under a statistic, or `null` when it has none (an empty bin; a mean of samples that carry no value). */ export declare function reduceBin(statistic: StatisticName | Reducer, bin: Bin, total: number): number | null; /** `n` equal steps from `a` to `b`, as the `n + 1` edges that bound them. */ export declare function uniformEdges(a: number, b: number, n: number): number[]; /** The index of the bin an edge list puts `v` in (the last bin includes its upper edge), or -1 when `v` is outside. */ export declare function binOf(edges: readonly number[], v: number): number; /** A grid of bins. */ export interface Grid { xEdges: number[]; yEdges: number[]; /** Row by row from the top: `bins[row * nx + column]`. */ bins: Bin[]; nx: number; ny: number; /** Samples that fell inside the grid, and the number that fell outside it. */ total: number; outside: number; } /** Count samples into the rectangles between two lists of edges (`binned_statistic_2d`'s job). A sample outside the edges is counted as `outside`. */ export declare function binGrid(samples: readonly Sample[], xEdges: readonly number[], yEdges: readonly number[], keepValues?: boolean): Grid; /** The value of every bin of a grid under a statistic. */ export declare const gridValues: (grid: Grid, statistic: StatisticName | Reducer) => (number | null)[]; /** How a hexagon sits: a corner up (`pointy`) or an edge up (`flat`). */ export type HexOrientation = "pointy" | "flat"; /** The hexagon (axial `q`, `r`) that holds `(x, y)` on a grid of hexagons of circumradius `size` whose (0, 0) hexagon is centred at `(ox, oy)`. */ export declare function hexAt(x: number, y: number, size: number, orientation: HexOrientation, ox?: number, oy?: number): [number, number]; /** The centre of hexagon (`q`, `r`). */ export declare function hexCentre(q: number, r: number, size: number, orientation: HexOrientation, ox?: number, oy?: number): [number, number]; /** The six corners of a hexagon of circumradius `size`, as offsets from its centre, clockwise from the right (flat) or the lower right (pointy), with y down. */ export declare function hexCorners(size: number, orientation: HexOrientation): [number, number][]; /** A hexagon with the bin it holds. */ export interface HexBin { q: number; r: number; cx: number; cy: number; bin: Bin; } /** Count samples into hexagons. The hexagons that hold at least one sample are returned, in the order of their rows (top to bottom, left to right). */ export declare function hexBins(samples: readonly Sample[], size: number, orientation: HexOrientation, origin: readonly [number, number], keepValues?: boolean): { cells: HexBin[]; total: number; }; /** * Scott's rule for a density in two dimensions: each axis's bandwidth is its standard deviation times `n^(-1/6)`, with `n` the number of * samples (the effective number, when they have weights). In the same units as the samples. Silverman's rule is the same number in two dimensions. */ export declare function scottBandwidth(xs: readonly number[], ys: readonly number[], weights?: readonly number[]): [number, number]; /** A density on a grid of nodes, `nx` by `ny`, spaced evenly from the first to the last of `x` and of `y`. */ export interface Density { nx: number; ny: number; x: readonly [number, number]; y: readonly [number, number]; /** Row by row from the top: `z[j * nx + i]` at node `i`, `j`. The density integrates to 1 over the plane (per square of the samples' unit). */ z: Float64Array; /** The bandwidths used, in the samples' unit. */ bandwidth: [number, number]; max: number; } /** * A Gaussian kernel density estimate of weighted samples on a grid of nodes. A sample adds a bell of the given bandwidth to every node * within four bandwidths of it (the bell's tail beyond is under a thousandth of its height), so the cost is the number of samples times a window * of nodes and not the whole grid. The density is not folded back at the edges: what lies beyond the box is lost. */ export declare function densityGrid(samples: readonly Sample[], box: { x: readonly [number, number]; y: readonly [number, number]; }, nx: number, ny: number, bandwidth: readonly [number, number], weights?: readonly number[]): Density; /** The density's value at `(x, y)`, by bilinear interpolation between the four nodes round it (0 outside the grid). */ export declare function densityAt(d: Density, x: number, y: number): number; /** * The densities that bound the smallest regions holding the given shares of the mass (the highest-density regions), for a density on a * grid: `masses` of 0.5 gives the density above which half of the mass lies. */ export declare function massThresholds(d: Density, masses: readonly number[]): number[]; /** A point on a contour. */ export type Pt = readonly [number, number]; /** * The closed rings that bound the part of a density at or above `level`, by marching squares. The grid is padded with a border of * nodes below every level, so every ring closes (a region that reaches the box's edge is closed just beyond it). The rings are in the * density's own coordinates; a ring that bounds a hole runs the other way, so that an even-odd fill leaves the hole empty. */ export declare function contourRings(d: Density, level: number): Pt[][]; /** "Nice" tick values: about `count` of them, at 1, 2, 2.5 or 5 times a power of ten, covering `[low, high]` within it. */ export declare function niceTicks(low: number, high: number, count?: number): number[];