Skip to content

Instantly share code, notes, and snippets.

@daguar
Created January 12, 2014 19:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save daguar/8389275 to your computer and use it in GitHub Desktop.
Save daguar/8389275 to your computer and use it in GitHub Desktop.
D3 OOPy quantizer for 1-5 range
// Quantizing data into buckets
function Quantizer(data_array) {
min = d3.min(data)
max = d3.max(data)
this.quantizeNumber = d3.scale.quantize()
.domain([min,max])
.range([1,5]) // Start with only mapping on 1-5 color scale
}
/* Test for Quantizer
data = [1,2,3,10];
var quantizer = new Quantizer(data)
console.log(quantizer.quantizeNumber(2));
console.log(quantizer.quantizeNumber(10));
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment