// Generated by CoffeeScript 1.10.0 (function() { var cells, cells_data, height, radius, sites, sites_data, svg, voronoi, width; svg = d3.select('svg'); width = svg.node().getBoundingClientRect().width; height = svg.node().getBoundingClientRect().height; radius = 10; sites_data = d3.range(20).map(function() { return { x: Math.round(Math.random() * (width - radius * 2) + radius), y: Math.round(Math.random() * (height - radius * 2) + radius) }; }); voronoi = d3.voronoi().x(function(d) { return d.x; }).y(function(d) { return d.y; }).extent([[-1, -1], [width + 1, height + 1]]); cells_data = voronoi.polygons(sites_data); cells = svg.selectAll('.cell').data(cells_data); cells.enter().append('path').attrs({ "class": 'cell', d: function(d) { if (d == null) { return null; } else { return "M" + d.join("L") + "Z"; } } }); sites = svg.selectAll('.site').data(sites_data); sites.enter().append('circle').attrs({ "class": 'site', r: radius, cx: function(d) { return d.x; }, cy: function(d) { return d.y; } }); }).call(this);