Module

Hylograph.Components.Binning

Package
purescript-hylograph-components
Repository
afcondon/purescript-hylograph-components

Histogram binning preprocessor.

Pure functions over Array Number producing Array Bin. There is no Histogram chart module by design: a histogram is a BarChart whose categories are bin ranges and whose barPadding is set to 0 so the bars touch. That makes this module the entire taxonomy cost of adding "histogram" to the library.

equalWidth — fixed-width bins over [min, max]. Classic histogram. equalCount — quantile bins: each bin holds roughly the same number of samples. Widths vary; useful for skewed data.

Values exactly equal to the upper bound of the dataset are assigned to the final bin (half-open [lo, hi) in the interior, closed on the right end — D3's behaviour).

#Bin Source

type Bin = { binEnd :: Number, binStart :: Number, count :: Int }

#equalWidth Source

equalWidth :: Int -> Array Number -> Array Bin

n equal-width bins covering [min values, max values]. Empty input or n <= 0 returns []. A degenerate run (all values equal) returns one bin containing every sample.

#equalCount Source

equalCount :: Int -> Array Number -> Array Bin

n quantile bins: each bin holds roughly length values / n samples, so widths reflect the distribution's shape. Ties are resolved in sort order (same sample may shift by one bin depending on sort stability — matches D3's d3.bin().thresholds for quantile thresholds).

#defaultLabel Source

defaultLabel :: Bin -> String

Default bin label: "start–end" with one decimal place. Many callers want a custom format (integers, units, currency); bypass this and build the label per bin directly on the chart's encoding.category.