quantize()

quantize(value)

Given a value in the input domain, returns the corresponding value in the output range. For example, to apply a color encoding:

1
2
3
4
5
6
var color = d3.scaleQuantize()
    .domain([0, 1])
    .range(["brown", "steelblue"]);
 
color(0.49); // "brown"
color(0.51); // "steelblue"

Or dividing the domain into three equally-sized parts with different range values to compute an appropriate stroke width:

1
2
3
4
5
6
7
var width = d3.scaleQuantize()
    .domain([10, 100])
    .range([1, 2, 4]);
 
width(20); // 1
width(50); // 2
width(80); // 4
doc_D3_Js
2025-01-10 15:47:30
Comments
Leave a Comment

Please login to continue.