source: Dev/trunk/d3/examples/voronoi/voronoi.js @ 76

Last change on this file since 76 was 76, checked in by fpvanagthoven, 14 years ago

d3

File size: 985 bytes
Line 
1var w = 960,
2    h = 500;
3
4var vertices = d3.range(100).map(function(d) {
5  return [Math.random() * w, Math.random() * h];
6});
7
8var svg = d3.select("#chart")
9  .append("svg:svg")
10    .attr("width", w)
11    .attr("height", h)
12    .attr("class", "PiYG")
13    .on("mousemove", update);
14
15svg.selectAll("path")
16    .data(d3.geom.voronoi(vertices))
17  .enter().append("svg:path")
18    .attr("class", function(d, i) { return i ? "q" + (i % 9) + "-9" : null; })
19    .attr("d", function(d) { return "M" + d.join("L") + "Z"; });
20
21svg.selectAll("circle")
22    .data(vertices.slice(1))
23  .enter().append("svg:circle")
24    .attr("transform", function(d) { return "translate(" + d + ")"; })
25    .attr("r", 2);
26
27function update() {
28  vertices[0] = d3.svg.mouse(this);
29  svg.selectAll("path")
30      .data(d3.geom.voronoi(vertices)
31      .map(function(d) { return "M" + d.join("L") + "Z"; }))
32      .filter(function(d) { return this.getAttribute("d") != d; })
33      .attr("d", function(d) { return d; });
34}
Note: See TracBrowser for help on using the repository browser.