(function() { window.main = function() { var colorize, height, polygon, svg, width; width = 960; height = 500; svg = d3.select('body').append('svg').attr('width', width).attr('height', height); polygon = [[300, 200], [300, 300], [370, 310], [400, 300], [360, 260], [400, 180]]; window.voronoi = d3.geom.voronoi().clipExtent([[.5, .5], [width - .5, height - .5]]); colorize = d3.scale.category10(); svg.selectAll('.voronoi').data(voronoi(polygon)).enter().append('path').attr('class', 'voronoi').style('fill', function(d, i) { return colorize(i); }).attr('d', function(d) { return "M" + (d.join('L')) + "Z"; }); svg.selectAll('.polygon').data([polygon]).enter().append('path').attr('class', 'polygon').attr('d', function(d) { return "M" + (d.join('L')) + "Z"; }); return svg.selectAll('.link').data(voronoi.links(polygon)).enter().append('line').attr('class', 'link').attr('x1', function(d) { return d.source[0]; }).attr('y1', function(d) { return d.source[1]; }).attr('x2', function(d) { return d.target[0]; }).attr('y2', function(d) { return d.target[1]; }); }; }).call(this);