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:

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:

var width = d3.scaleQuantize()
    .domain([10, 100])
    .range([1, 2, 4]);

width(20); // 1
width(50); // 2
width(80); // 4
doc_D3_Js
2016-11-24 10:28:35
Comments
Leave a Comment

Please login to continue.