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

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

d3

File size: 1.0 KB
Line 
1var w = 960,
2    h = 960,
3    format = d3.format(",d");
4
5var pack = d3.layout.pack()
6    .size([w - 4, h - 4])
7    .value(function(d) { return d.size; });
8
9var vis = d3.select("#chart").append("svg:svg")
10    .attr("width", w)
11    .attr("height", h)
12    .attr("class", "pack")
13  .append("svg:g")
14    .attr("transform", "translate(2, 2)");
15
16d3.json("../data/flare.json", function(json) {
17  var node = vis.data([json]).selectAll("g.node")
18      .data(pack.nodes)
19    .enter().append("svg:g")
20      .attr("class", function(d) { return d.children ? "node" : "leaf node"; })
21      .attr("transform", function(d) { return "translate(" + d.x + "," + d.y + ")"; });
22
23  node.append("svg:title")
24      .text(function(d) { return d.name + (d.children ? "" : ": " + format(d.size)); });
25
26  node.append("svg:circle")
27      .attr("r", function(d) { return d.r; });
28
29  node.filter(function(d) { return !d.children; }).append("svg:text")
30      .attr("text-anchor", "middle")
31      .attr("dy", ".3em")
32      .text(function(d) { return d.name.substring(0, d.r / 3); });
33});
Note: See TracBrowser for help on using the repository browser.