d3-scale icon indicating copy to clipboard operation
d3-scale copied to clipboard

scale.high/low

Open Fil opened this issue 4 years ago • 3 comments

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

Fil avatar Jan 05 '22 11:01 Fil

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?

visnup avatar Jan 07 '22 18:01 visnup

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.)

Fil avatar Jan 07 '22 18:01 Fil

in between 🤯 hadn't thought of that one.

visnup avatar Jan 11 '22 18:01 visnup