Functional Weave
Code in Python

charts.extent@1.0.1

README.md

1,142 bytes · view raw

# charts.extent

`extent([null, 5, 7])` is `[5, 7]`: the smallest and largest values of a
series, skipping gaps. It is the first step of nearly every chart (the data
extent becomes a scale's domain), so it is its own capability.

A gap is `null`: a missing reading, a day with no sales recorded rather than
zero sales. Gaps are skipped, never read as zero. The usual one-liner,
JavaScript's `Math.min(...values)`, converts `null` to 0 and so draws a
temperature series from zero; Python's `min()` fails on `None` instead.

When the series is empty or every value is a gap, the answer is `null`, not a
made-up `[0, 0]` or `[Infinity, -Infinity]`: a chart with no data should say
so. A single value gives `[v, v]`; turning that into a usable domain (a scale
needs two different ends) is the chart's decision, not this function's.

Values are returned exactly as given, with no rounding. A value that is not a
finite number is an error.

1.0.1 adds tests; behaviour unchanged. The Rust vector adapter now refuses an
argument that is not a number with the same message as TypeScript and Python, so
the new error tests mean the same in all three.