Created
July 31, 2012 17:25
-
-
Save jacksonhenry3/3218715 to your computer and use it in GitHub Desktop.
coffe wheel test
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <!DOCTYPE html> | |
| <html> | |
| <head> | |
| <meta http-equiv="Content-Type" content="text/html;charset=utf-8"> | |
| <title>Partition - Sunburst</title> | |
| <script src="http://d3js.org/d3.v2.js"></script> | |
| <style type="text/css"> | |
| path { | |
| stroke: #fff; | |
| fill-rule: evenodd; | |
| } | |
| </style> | |
| </head> | |
| <body> | |
| <div id="chart"></div> | |
| <script type="text/javascript"> | |
| var width = 960, | |
| height = 700, | |
| radius = Math.min(width, height) / 2; | |
| var x = d3.scale.linear() | |
| .range([0, 2 * Math.PI]); | |
| var y = d3.scale.sqrt() | |
| .range([0, radius]); | |
| var color = d3.scale.category20c(); | |
| var vis = d3.select("#chart").append("svg") | |
| .attr("width", width) | |
| .attr("height", height) | |
| .append("g") | |
| .attr("transform", "translate(" + width / 2 + "," + height / 2 + ")"); | |
| var partition = d3.layout.partition() | |
| .sort(null) | |
| .size([2 * Math.PI, radius * radius]) | |
| .children(function(d) { return isNaN(d.value) ? d3.entries(d.value) : null; }) | |
| .value(function(d) { return d.size; }); | |
| var arc = d3.svg.arc() | |
| .startAngle(function(d) { return Math.max(0, Math.min(2 * Math.PI, x(d.x))); }) | |
| .endAngle(function(d) { return Math.max(0, Math.min(2 * Math.PI, x(d.x + d.dx))); }) | |
| .innerRadius(function(d) { return Math.max(0, y(d.y)); }) | |
| .outerRadius(function(d) { return Math.max(0, y(d.y + d.dy)+2); }); | |
| d3.json("flare.json", function(json) { | |
| var g = vis.data(d3.entries(json)).selectAll("g") | |
| .data(partition) | |
| .enter().append("svg:g") | |
| .attr("display", function(d) { return d.depth ? null : "none"; }); // hide inner ring | |
| g.append("svg:path") | |
| .attr("d", arc) | |
| .attr("stroke", "#fff") | |
| .attr("fill", function(d) { return color((d.children ? d : d.parent).data.key); }) | |
| .attr("fill-rule", "evenodd"); | |
| g.append("svg:text") | |
| .attr("transform", function(d) { return "rotate(" + (d.x + d.dx / 2 - Math.PI / 2) / Math.PI * 180 + ")"; }) | |
| .attr("x", function(d) { return Math.sqrt(d.y); }) | |
| .attr("dx", "6") // margin | |
| .attr("dy", ".35em") // vertical-align | |
| .text(function(d) { return d.data.key; }); | |
| var path = vis.data([json]).selectAll("path") | |
| .data(partition.nodes) | |
| .enter().append("path") | |
| .attr("d", arc) | |
| .style("fill", function(d) { return color((d.children ? d : d.parent).name); }) | |
| .on("click", click); | |
| function click(d) { | |
| path.transition() | |
| .duration(1000) | |
| .attrTween("d", arcTween(d)); | |
| } | |
| }); | |
| // Interpolate the scales! | |
| function arcTween(d) { | |
| var xd = d3.interpolate(x.domain(), [d.x, d.x + d.dx]), | |
| yd = d3.interpolate(y.domain(), [d.y, 1]), | |
| yr = d3.interpolate(y.range(), [d.y ? 20 : 0, radius]); | |
| return function(d, i) { | |
| return i | |
| ? function(t) { return arc(d); } | |
| : function(t) { x.domain(xd(t)); y.domain(yd(t)).range(yr(t)); return arc(d); }; | |
| }; | |
| } | |
| </script> | |
| </body> | |
| </html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment