/** Number of colour steps every palette carries. */ export declare const HEATMAP_STEPS = 10; /** * How values map to colour steps. * * - `sequential`: low to high. `domain: 'auto'` (the default) uses the min * and max of the cells that show a value; a fixed `[min, max]` clamps. * - `diverging`: two hues either side of `midpoint`. `auto` makes the * domain symmetric around the midpoint, so equal distances either side * get equal intensity. The midpoint defaults to 0, or to the centre of a * fixed domain that does not include 0. * - `quantile`: equal-count buckets (default 10) from the shown values. * Repeated values never split: buckets that would cut through a run of * equal values merge, so the minimum always takes the first step. * - `threshold`: ascending cut points; `n` thresholds make `n + 1` * buckets, spread across the ten steps. At most nine; duplicates merge. * * A fixed domain is `[min, max]`. A reversed pair is put in order, with a * warning in development builds. */ export type HeatmapScale = { type: 'sequential'; domain?: 'auto' | readonly [number, number]; } | { type: 'diverging'; domain?: 'auto' | readonly [number, number]; midpoint?: number; } | { type: 'quantile'; buckets?: number; } | { type: 'threshold'; thresholds: readonly number[]; }; /** A scale with its domain worked out against the data. */ export interface ResolvedHeatmapScale { type: HeatmapScale['type']; /** Low end of the domain, or of the data for quantile and threshold. */ min: number | null; /** High end of the domain, or of the data for quantile and threshold. */ max: number | null; /** Diverging only: the value that separates the two hues. */ midpoint?: number; /** Quantile and threshold: the ascending bucket edges. */ thresholds: readonly number[]; /** Maps a value to a step, 0 to 9. */ stepOf: (value: number) => number; } /** Min and max of the finite values, or null when there are none. */ export declare function extent(values: readonly number[]): [number, number] | null; /** * Sequential step: the domain is cut into ten equal bands. A value on a * band edge takes the band above; the top edge belongs to the top step. * Values outside the domain clamp to the end steps. */ export declare function sequentialStep(value: number, low: number, high: number): number; /** * Diverging step: steps 0 to 4 sit below the midpoint (0 is the furthest), * steps 5 to 9 above it (9 is the furthest). Ten steps have no middle one, * so a value exactly on the midpoint takes step 5, the palest step above. * It is painted in the neutral midpoint colour instead (see `onMidpoint`). */ export declare function divergingStep(value: number, low: number, midpoint: number, high: number): number; /** * Whether a value sits exactly on a diverging scale's midpoint, so it is * painted neutral (`--heatmap-midpoint`) rather than in either hue. Exact * up to floating-point rounding, a few units in the last place of the * scale's largest magnitude: the centre of [0.1, 0.2] is computed as * 0.15000000000000002, and 0.1 + 0.2 - 0.3 is not quite 0. A value that * merely rounds to the midpoint when printed keeps its step. Other scale * types have no midpoint. */ export declare function onMidpoint(scale: ResolvedHeatmapScale, value: number): boolean; /** * Quantile of a sorted array at `p` (0 to 1), interpolating linearly * between neighbours (the R-7 method spreadsheets use). */ export declare function quantileSorted(sorted: readonly number[], p: number): number; /** The `buckets - 1` inner edges that cut sorted values into equal counts. */ export declare function quantileThresholds(sorted: readonly number[], buckets: number): number[]; /** * Quantile edges that cut something. Each raw edge moves up to the first * value at or above it, which puts every value in the same bucket but makes * the edge a value the data holds, so no bucket is left empty (an edge * between two values could cut a band nothing falls in). Then edges that * repeat go: when many values repeat (60% of cells at zero), several raw * edges land on the same value, and kept they would put the minimum * mid-scale. An edge at the minimum has nothing below it, so it goes too. */ export declare function usableQuantileEdges(sorted: readonly number[], buckets: number): number[]; /** How many edges are at or below `value`: its bucket, 0 to edges.length. */ export declare function thresholdBucket(value: number, thresholds: readonly number[]): number; /** Spreads bucket `bucket` of `bucketCount` evenly across the ten steps. */ export declare function bucketStep(bucket: number, bucketCount: number): number; /** * Works out a scale against the values that will be shown. Pass only the * values of cells that render a colour: empty and low-sample cells must not * stretch the domain. */ export declare function resolveScale(scale: HeatmapScale, values: readonly number[]): ResolvedHeatmapScale; /** How a margin combines its cells. */ export type HeatmapAggregate = 'sum' | 'mean'; /** One cell as aggregation sees it. */ export interface AggregateInput { value: number | null; count?: number; } /** A combined value and the count behind it. */ export interface AggregateResult { value: number | null; /** Sum of the counts, when any cell carried one. */ count?: number; } /** Sum of the values; empty cells are skipped. Null when nothing is left. */ export declare function sumOf(cells: readonly AggregateInput[]): AggregateResult; /** * Mean weighted by count: sum(value x count) / sum(count). This is the only * correct way to combine rates (26% of 39 and 50% of 2 is 27%, not 38%). * A cell without a count weighs 1, so data with no counts at all gets a * plain mean. Cells with a count of 0 add nothing. */ export declare function weightedMean(cells: readonly AggregateInput[]): AggregateResult; /** Combines cells with the given method. */ export declare function aggregate(cells: readonly AggregateInput[], method: HeatmapAggregate): AggregateResult; //# sourceMappingURL=heatmap-scale.d.ts.map