charts.extent
The minimum and maximum of a series as [min, max], skipping gaps (null), or null when there is no value.
1.0.1 · published 2026-10-03 by charlie · Anterra
Pinned by 15 tests, run in TypeScript, Python and Rust.
What it does
`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.
For example
extent(3, 1, 2)→ 1, 3 an unordered seriesextent(—, 5, 7)→ 5, 7 a gap is skipped, not read as zero (Math.min treats null as 0)extent(4.5, —, -2.25, 9, —)→ -2.25, 9 gaps in the middle and at the end
The function
The same function in TypeScript, Python and Rust, pinned by the same tests. Pick your language; the choice follows you around the registry.
pub fn extent(values: &[Option<f64>]) -> Option<Vec<f64>>
| values | float?[] | the series; null marks a gap, such as a missing reading |
| returns | float[]? | [min, max], or null when every value is a gap or the list is empty |
Your code names it in one line, in the file that uses it
fune!(charts.extent@^1); // then call extent(…)
Imports name this capability’s declared dependencies, which fune builds next to it in your project; each one links to its page.
use super::funejson::Value; ← the fune runtime: the JSON value the test vectors use; fune build keeps it only where a signature takes one
/// [min, max] of a series, skipping gaps (`None`); `None` when nothing is left.
///
/// # Panics
/// Panics on a value that is not finite.
pub fn extent(values: &[Option<f64>]) -> Option<Vec<f64>> {
let mut range: Option<(f64, f64)> = None;
for v in values.iter().flatten() {
if !v.is_finite() {
panic!("values must be finite numbers or null, received {}", v);
}
range = Some(match range {
None => (*v, *v),
Some((lo, hi)) => (if *v < lo { *v } else { lo }, if *v > hi { *v } else { hi }),
});
}
range.map(|(lo, hi)| vec![lo, hi])
}
pub fn fune_vector(args: &[Value]) -> Value {
// A value the typed signature cannot hold (text, true) is refused with the
// wording TypeScript and Python use, rather than read as 0.
let values: Vec<Option<f64>> = args[0]
.as_arr()
.iter()
.map(|v| match v {
Value::Null => None,
Value::Int(_) | Value::Float(_) => Some(v.as_f64()),
_ => panic!("values must be finite numbers or null, received a value that is not a number"),
})
.collect();
match extent(&values) {
Some(r) => Value::Arr(r.into_iter().map(Value::Float).collect()),
None => Value::Null,
}
}Install
fune build
With that line in your source, in a Rust project (language rust in fune.project), fune build resolves it and nothing else, pins them in fune.lock, downloads only the Rust package of each, and builds the code above into your project’s .fune/build, one readable file per capability with a header linking back here. A crate’s build.rs runs it before every compile. Or pin a range in fune.project and build in one step:
fune add charts.extent
The manifest, vectors and README with only the Rust implementation. Install it without the registry with fune add ./charts.extent-1.0.1-rust.fune, or fetch it from a terminal with fune pull charts.extent@1.0.1:rust.
The whole function, every language, is one file too: charts.extent-1.0.1.fune, 7,183 bytes, sha256 399353815202eee83b7de1869a785a3df6ca52d42d567693e8d053b41db659b9. It installs into a project of any language.
Customise it in your app
The seams this capability offers. Put a marker directly above a function of your own and fune build wires it into the built code; the package on the registry is not changed, the built file’s header lists it under CUSTOMISED, and fune hooks lists every hook in the project. How hooks work.
before — your function gets the arguments and returns them, changed or not, or throws to refuse the call.
// fune: before charts.extent
after — your function gets the result and the arguments, and returns the final result.
// fune: after charts.extent
replace — it requires no other capability, so there is no dependency to replace.
step — your function runs at a numbered point inside the function’s body, receives the in-scope values it names as parameters, and may return replacements. List the points with fune show charts.extent --steps.
// fune: step charts.extent after <n|label>
Tests
A version published now needs at least 8 tests for every function, and one that expects the error for each function that throws; the registry refuses it otherwise. fune verify --all runs each case in TypeScript, Python and Rust, and a project runs them again with fune verify. This page lists the cases; it does not run them. The exact JSON is vectors.json.
| Case | Arguments | Expected | |
|---|---|---|---|
| an unordered series | 3, 1, 2 | → | 1, 3 |
| a gap is skipped, not read as zero (Math.min treats null as 0) | —, 5, 7 | → | 5, 7 |
| gaps in the middle and at the end | 4.5, —, -2.25, 9, — | → | -2.25, 9 |
| negative values only | -3, -8, -1 | → | -8, -1 |
| one value is both ends | 42 | → | 42, 42 |
| all values equal | 2, 2, 2 | → | 2, 2 |
| every value a gap gives null | —, — | → | — |
| an empty series gives null | → | — | |
| fractions are returned exactly, not rounded | 0.1, 0.3, 0.2 | → | 0.1, 0.3 |
| very large and very small magnitudes | 1,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,0… | → | -0, 1,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,0… |
Show the other 5 tests
| Case | Arguments | Expected | |
|---|---|---|---|
| a single negative value is both ends | -0.5 | → | -0.5, -0.5 |
| zero is a value, not a gap | 0, —, 0 | → | 0, 0 |
| a leading gap then values that only fall | —, 10, 8, 6 | → | 6, 10 |
| a value that is not a number is an error, not a gap | 1, 2, 3 | → | error: values must be finite numbers or null |
| true is not a number either | 1, true | → | error: values must be finite numbers or null |
More from the author
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.
Files
| Path | Bytes |
|---|---|
| README.md | 1,142 |
| impl/python.py | 808 |
| impl/rust.rs | 1,316 |
| impl/typescript.ts | 799 |
| vectors.json | 1,516 |