4
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
5
<title>Partition - Sunburst</title>
6
<script type="text/javascript" src="../../d3.v2.js"></script>
7
<style type="text/css">
17
<div id="chart"></div>
18
<script type="text/javascript">
22
r = Math.min(w, h) / 2,
23
x = d3.scale.linear().range([0, 2 * Math.PI]),
24
y = d3.scale.sqrt().range([0, r]),
25
color = d3.scale.category20c();
27
var vis = d3.select("#chart").append("svg")
31
.attr("transform", "translate(" + w / 2 + "," + h / 2 + ")");
33
var partition = d3.layout.partition()
34
.value(function(d) { return d.size; });
36
var arc = d3.svg.arc()
37
.startAngle(function(d) { return Math.max(0, Math.min(2 * Math.PI, x(d.x))); })
38
.endAngle(function(d) { return Math.max(0, Math.min(2 * Math.PI, x(d.x + d.dx))); })
39
.innerRadius(function(d) { return Math.max(0, y(d.y)); })
40
.outerRadius(function(d) { return Math.max(0, y(d.y + d.dy)); });
42
d3.json("../data/flare.json", function(json) {
43
var path = vis.data([json]).selectAll("path")
44
.data(partition.nodes)
45
.enter().append("path")
47
.style("fill", function(d) { return color((d.children ? d : d.parent).name); })
53
.attrTween("d", arcTween(d));
57
// Interpolate the scales!
58
function arcTween(d) {
59
var xd = d3.interpolate(x.domain(), [d.x, d.x + d.dx]),
60
yd = d3.interpolate(y.domain(), [d.y, 1]),
61
yr = d3.interpolate(y.range(), [d.y ? 20 : 0, r]);
62
return function(d, i) {
64
? function(t) { return arc(d); }
65
: function(t) { x.domain(xd(t)); y.domain(yd(t)).range(yr(t)); return arc(d); };