3
r = Math.min(w, h) / 2,
4
color = d3.scale.category20c();
6
var vis = d3.select("#chart").append("svg")
10
.attr("transform", "translate(" + w / 2 + "," + h / 2 + ")");
12
var partition = d3.layout.partition()
14
.size([2 * Math.PI, r * r])
15
.value(function(d) { return 1; });
17
var arc = d3.svg.arc()
18
.startAngle(function(d) { return d.x; })
19
.endAngle(function(d) { return d.x + d.dx; })
20
.innerRadius(function(d) { return Math.sqrt(d.y); })
21
.outerRadius(function(d) { return Math.sqrt(d.y + d.dy); });
23
d3.json("../data/flare.json", function(json) {
24
var path = vis.data([json]).selectAll("path")
25
.data(partition.nodes)
26
.enter().append("path")
27
.attr("display", function(d) { return d.depth ? null : "none"; }) // hide inner ring
29
.attr("fill-rule", "evenodd")
30
.style("stroke", "#fff")
31
.style("fill", function(d) { return color((d.children ? d : d.parent).name); })
34
d3.select("#size").on("click", function() {
36
.data(partition.value(function(d) { return d.size; }))
39
.attrTween("d", arcTween);
41
d3.select("#size").classed("active", true);
42
d3.select("#count").classed("active", false);
45
d3.select("#count").on("click", function() {
47
.data(partition.value(function(d) { return 1; }))
50
.attrTween("d", arcTween);
52
d3.select("#size").classed("active", false);
53
d3.select("#count").classed("active", true);
57
// Stash the old values for transition.
63
// Interpolate the arcs in data space.
64
function arcTween(a) {
65
var i = d3.interpolate({x: a.x0, dx: a.dx0}, a);