Last active
August 29, 2015 14:07
-
-
Save methyl/d5e4dacb446cac4beaa2 to your computer and use it in GitHub Desktop.
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
{ | |
"name": "flare", | |
"children": [ | |
{ | |
"name": "analytics", | |
"children": [ | |
{ | |
"name": "cluster", | |
"children": [ | |
{"name": "AgglomerativeCluster", "size": 3938}, | |
{"name": "CommunityStructure", "size": 3812}, | |
{"name": "HierarchicalCluster", "size": 6714}, | |
{"name": "MergeEdge", "size": 743} | |
] | |
}] | |
}] | |
} |
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> | |
<meta charset="utf-8"> | |
<style> | |
text { | |
font: 10px sans-serif; | |
} | |
</style> | |
<body> | |
<script src="http://d3js.org/d3.v3.min.js"></script> | |
<script> | |
var diameter = 960, | |
format = d3.format(",d"), | |
color = d3.scale.category20c(); | |
var bubble = d3.layout.pack() | |
.sort(null) | |
.size([diameter, diameter]) | |
.padding(1.5); | |
var svg = d3.select("body").append("svg") | |
.attr("width", diameter) | |
.attr("height", diameter) | |
.attr("class", "bubble"); | |
d3.json("flare.json", function(error, root) { | |
var node = svg.selectAll(".node") | |
.data(bubble.nodes(classes(root)) | |
.enter().append("g") | |
.attr("class", "node") | |
.attr("transform", function(d) { return "translate(" + d.x + "," + d.y + ")"; }); | |
node.append("title") | |
.text(function(d) { return d.className + ": " + format(d.value); }); | |
node.append("circle") | |
.attr("r", function(d) { return d.r; }) | |
.style("fill", function(d) { return color(d.packageName); }); | |
node.append("text") | |
.attr("dy", ".3em") | |
.style("text-anchor", "middle") | |
.text(function(d) { return d.className.substring(0, d.r / 3); }); | |
}); | |
// Returns a flattened hierarchy containing all leaf nodes under the root. | |
function classes(root) { | |
var classes = []; | |
function recurse(name, node) { | |
if (node.children) node.children.forEach(function(child) { recurse(node.name, child); }); | |
else classes.push({packageName: name, className: node.name, value: node.size}); | |
} | |
recurse(null, root); | |
return {children: classes}; | |
} | |
d3.select(self.frameElement).style("height", diameter + "px"); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment