Skip to content

Instantly share code, notes, and snippets.

@lebek
Created October 31, 2013 13:15
Show Gist options
  • Save lebek/7249495 to your computer and use it in GitHub Desktop.
Save lebek/7249495 to your computer and use it in GitHub Desktop.
var histWidth = 2; // Number of bins in x
var histHeight = 2; // Number of bins in y
var pointWidth = 5; // Number of points in x
var pointHeight = 5; // Number of points in y
var xScale = d3.scale.quantile()
.domain([0, pointWidth-1])
.range([0, histWidth-1]);
var yScale = d3.scale.quantile()
.domain([0, pointHeight-1])
.range([0, histHeight-1]);
/* Returns the boundaries of bin x, y in the data */
function getBin(x, y) {
return [xScale.invertExtent(x), yScale.invertExtent(y)];
}
console.log(getBin(0,0));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment