d3-scale
d3-scale copied to clipboard
scale.high/low
scale.low and scale.high define what to do with values higher or lower than the bounds of the domain. If undefined, we do the usual (ie. interpolate or clamp).
- [ ] add tests
- [ ] generalize to other scales (diverging, etc)
- [ ] should it be possible to distinguish N/A and invalid with different "unknown"?
demo https://observablehq.com/@d3/scale-high-low-258
Is this interpretable for a categorical scale too?
I assume it'd work for an ordinal scale, but what does "high" vs. "low" mean for a categorical one?
Good question! (for now it's only designed for continuous scales, and implemented in just one class of them).
thinking out loud:
- On a categorical scale I guess you would only use scale.unknown("oops") — and if you want specific values for undefined/NaN, you can already define them in the domain.
- On an ordinal scale, where the domain is made of comparable values (e.g. ["B", "C", "D"]), and the value is comparable, it can make sens to implment high, low, or even in-between domain elements. (I'm not proposing to implement that.)
in between 🤯 hadn't thought of that one.