Skip to content

Documentation / @finchart/core / index / slotWidth

Function: slotWidth() ​

slotWidth<T>(data, mapping, places?, fullData?): number

Defined in: packages/core/src/series/slot.ts:39

A slot is the pixel gap between neighboring bars. The three series that need a width (candle, histogram, bar) all use this same arithmetic — measuring it separately in each would eventually let them drift apart.

Dividing the plot width by the visible count breaks down once panning goes past the end of the data — the handful of points left behind would split the whole screen between them and turn into giant blocks. A gap stays the same even as the count shrinks, so the width doesn't wobble.

When data (already sliced to the viewport) has no neighbor at all (panning past the end of the data leaves a single point), the actual left and right neighbors of that point are found in fullData (the full registered dataset) by binary search, and the width is re-measured at the current scale — this is O(log n), not a scan of the entire dataset, so staying at the edge of the screen for frame after frame on a dataset of hundreds of thousands of points costs almost nothing. (In the genuinely rare case where the viewport has two or more points but every pixel gap between them is 0, no single representative point can be pinned down, so it falls back to the median over the whole of fullData.) Only when fullData also has no neighbor (a truly single-point dataset) does it finally fall to FALLBACK_SLOT.

Type Parameters ​

T ​

T extends BaseDataPoint

Parameters ​

data ​

readonly T[]

mapping ​

XMapping

places? ​

number[] | null

fullData? ​

readonly T[]

Returns ​

number