-
-
Notifications
You must be signed in to change notification settings - Fork 86
Open
Labels
API changeFor PRs that require API design reviewFor PRs that require API design reviewTopic: JS APIenhancementNew feature or requestNew feature or request
Description
Currently we have Color.range()
and friends which only interpolates between 2 colors. I just had to write this for a color component I’m writing (<color-slider>
), and it was no fun:
colorAt (p) {
let bands = this.scales?.length;
if (bands <= 0) {
return null;
}
// FIXME the values outside of [0, 1] should be scaled
if (p >= 1) {
return this.scales.at(-1)(p);
}
else if (p <= 0) {
return this.scales[0](p);
}
let band = 1 / bands;
let scaleIndex = Math.max(0, Math.min(Math.floor(p / band), bands - 1));
let scale = this.scales[scaleIndex];
let color = scale((p % band) * bands);
return color;
}
And this is just equally spaced color stops. I dread to think about implementing the general case.
Which is why I think Color.js should provide it 😁
I’m thinking of something like:
/**
@param {Array<Color | {color: Color, at: number}>} stops
@param {RangeOptions} [options]
*/
function colorScale(colors: Array<Color>, options): function;
Thoughts?
Metadata
Metadata
Assignees
Labels
API changeFor PRs that require API design reviewFor PRs that require API design reviewTopic: JS APIenhancementNew feature or requestNew feature or request