[76] | 1 | <!DOCTYPE html> |
---|
| 2 | <html> |
---|
| 3 | <head> |
---|
| 4 | <meta http-equiv="Content-Type" content="text/html;charset=utf-8"> |
---|
| 5 | <title>Partition - Icicle</title> |
---|
| 6 | <script type="text/javascript" src="../../d3.js"></script> |
---|
| 7 | <script type="text/javascript" src="../../d3.layout.js"></script> |
---|
| 8 | <style type="text/css"> |
---|
| 9 | |
---|
| 10 | rect { |
---|
| 11 | stroke: #fff; |
---|
| 12 | } |
---|
| 13 | |
---|
| 14 | </style> |
---|
| 15 | </head> |
---|
| 16 | <body> |
---|
| 17 | <div id="chart"></div> |
---|
| 18 | <script type="text/javascript"> |
---|
| 19 | |
---|
| 20 | var w = 960, |
---|
| 21 | h = 250, |
---|
| 22 | x = d3.scale.linear().range([0, w]), |
---|
| 23 | y = d3.scale.linear().range([0, h]), |
---|
| 24 | color = d3.scale.category20c(); |
---|
| 25 | |
---|
| 26 | var vis = d3.select("#chart").append("svg:svg") |
---|
| 27 | .attr("width", w) |
---|
| 28 | .attr("height", h); |
---|
| 29 | |
---|
| 30 | var partition = d3.layout.partition() |
---|
| 31 | .value(function(d) { return d.size; }); |
---|
| 32 | |
---|
| 33 | d3.json("../data/flare.json", function(json) { |
---|
| 34 | var rect = vis.data([json]).selectAll("rect") |
---|
| 35 | .data(partition.nodes) |
---|
| 36 | .enter().append("svg:rect") |
---|
| 37 | .attr("x", function(d) { return x(d.x); }) |
---|
| 38 | .attr("y", function(d) { return y(d.y); }) |
---|
| 39 | .attr("width", function(d) { return x(d.dx); }) |
---|
| 40 | .attr("height", function(d) { return y(d.dy); }) |
---|
| 41 | .attr("fill", function(d) { return color((d.children ? d : d.parent).name); }) |
---|
| 42 | .on("click", click); |
---|
| 43 | |
---|
| 44 | function click(d) { |
---|
| 45 | x.domain([d.x, d.x + d.dx]); |
---|
| 46 | y.domain([d.y, 1]).range([d.y ? 20 : 0, h]); |
---|
| 47 | |
---|
| 48 | rect.transition() |
---|
| 49 | .duration(750) |
---|
| 50 | .attr("x", function(d) { return x(d.x); }) |
---|
| 51 | .attr("y", function(d) { return y(d.y); }) |
---|
| 52 | .attr("width", function(d) { return x(d.x + d.dx) - x(d.x); }) |
---|
| 53 | .attr("height", function(d) { return y(d.y + d.dy) - y(d.y); }); |
---|
| 54 | } |
---|
| 55 | }); |
---|
| 56 | |
---|
| 57 | </script> |
---|
| 58 | </body> |
---|
| 59 | </html> |
---|