Browse files

Add hexbin.centers.

  • Loading branch information...
1 parent 7076ccf commit 639c06c61d02d35028749c12b61c3f6c84b17409 @mbostock mbostock committed Mar 15, 2013
Showing with 9 additions and 4 deletions.
  1. +9 −4 hexbin/hexbin.js
View
13 hexbin/hexbin.js
@@ -66,14 +66,19 @@ d3.hexbin = function() {
return "m" + hexagon(radius).join("l") + "z";
};
- hexbin.mesh = function() {
- var path = [], mesh = hexagon(r).slice(0, 4).join("l");
+ hexbin.centers = function() {
+ var centers = [];
for (var y = 0, odd = false; y < height + r; y += dy, odd = !odd) {
for (var x = odd ? dx / 2 : 0; x < width; x += dx) {
- path.push("M", x, ",", y, "m", mesh);
+ centers.push([x, y]);
}
}
- return path.join("");
+ return centers;
+ };
+
+ hexbin.mesh = function() {
+ var fragment = hexagon(r).slice(0, 4).join("l");
+ return hexbin.centers().map(function(p) { return "M" + p + "m" + fragment; }).join("");
};
hexbin.size = function(_) {

0 comments on commit 639c06c

Please sign in to comment.