~bac/juju-gui/trunkcopy

« back to all changes in this revision

Viewing changes to lib/d3/examples/bundle/bundle-treemap.js

  • Committer: kapil.foss at gmail
  • Date: 2012-07-13 18:45:59 UTC
  • Revision ID: kapil.foss@gmail.com-20120713184559-2xl7be17egsrz0c9
reshape

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
var width = 960,
2
 
    height = 500;
3
 
 
4
 
var fill = d3.scale.ordinal()
5
 
    .range(colorbrewer.Greys[9].slice(1, 4));
6
 
 
7
 
var stroke = d3.scale.linear()
8
 
    .domain([0, 1e4])
9
 
    .range(["brown", "steelblue"]);
10
 
 
11
 
var treemap = d3.layout.treemap()
12
 
    .size([width, height])
13
 
    .value(function(d) { return d.size; });
14
 
 
15
 
var bundle = d3.layout.bundle();
16
 
 
17
 
var div = d3.select("#chart").append("div")
18
 
    .style("position", "relative")
19
 
    .style("width", width + "px")
20
 
    .style("height", height + "px");
21
 
 
22
 
var line = d3.svg.line()
23
 
    .interpolate("bundle")
24
 
    .tension(.85)
25
 
    .x(function(d) { return d.x + d.dx / 2; })
26
 
    .y(function(d) { return d.y + d.dy / 2; });
27
 
 
28
 
d3.json("../data/flare-imports.json", function(classes) {
29
 
  var nodes = treemap.nodes(packages.root(classes)),
30
 
      links = packages.imports(nodes);
31
 
 
32
 
  div.selectAll("div")
33
 
      .data(nodes)
34
 
    .enter().append("div")
35
 
      .attr("class", "cell")
36
 
      .style("background", function(d) { return d.children ? fill(d.key) : null; })
37
 
      .call(cell)
38
 
      .text(function(d) { return d.children ? null : d.key; });
39
 
 
40
 
  div.append("svg")
41
 
      .attr("width", width)
42
 
      .attr("height", height)
43
 
      .style("position", "absolute")
44
 
    .selectAll("path.link")
45
 
      .data(bundle(links))
46
 
    .enter().append("path")
47
 
      .style("stroke", function(d) { return stroke(d[0].value); })
48
 
      .attr("class", "link")
49
 
      .attr("d", line);
50
 
});
51
 
 
52
 
function cell() {
53
 
  this
54
 
      .style("left", function(d) { return d.x + "px"; })
55
 
      .style("top", function(d) { return d.y + "px"; })
56
 
      .style("width", function(d) { return d.dx - 1 + "px"; })
57
 
      .style("height", function(d) { return d.dy - 1 + "px"; });
58
 
}