It sounds like what you want is a quantize scale or a threshold scale -- a scale that takes a continuous input value and splits it into bins for conversion to a discrete set of output values.
For quantize scales, you specify the domain as normal ([min,max]
), and the size of the bins is determined by the number of values in the range, such that each bin is the same size.
For threshold scales, you specify the domain as the set of threshold values above which the next value from the range should be used; there should be one fewer threshold values then there are range values.
The version that @FernOfTheAndes got working for you is a polylinear scale: a linear scale with different domain/range blocks. Values in between two points of the domain are converted to a value that is the same distance in between the corresponding two points of the range.
So for a polylinear scale with domain [0,33,66,100]
and range [gray,green,yellow,red]
a value of 0 gets mapped to gray, a value of 33 gets mapped to green, but a value of 15 gets mapped to a gray-green colour halfway in between.
In contrast, for a threshold scale with domain [1,33,66]
and range[gray,green,yellow,red]
, any value greater or equal to 1 but less than 33 will get mapped to pure green.
Alternately, you could use a quantize scale with domain [0,100]
, range [green,yellow,red]
, and use a separate test to assign the colour gray when the value is 0.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…