d3.piecewise?
mbostock opened this issue · 2 comments
mbostock commented
A very lightweight piecewise linear scale. Implementation:
d3.piecewise = function(interpolate, values) {
var n = values.length - 1, I = d3.pairs(values, interpolate);
return function(t) {
var i = Math.max(0, Math.min(n - 1, Math.floor(t *= n)));
return I[i](t - i);
};
};
Example usage:
d3.piecewise(d3.interpolateRgb, ["red", "green", "blue"])
mbostock commented
Compared to d3-scale:
d3.scaleLinear()
.domain([0, 0.5, 1])
.range(["red", "green", "blue"])
.interpolate(d3.interpolateRgb)