xxxxxxxxxx
<style> body { font-family: sans-serif; } </style>
<script src="https://cdn.jsdelivr.net/npm/d3@12.10.3/d3.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/d3@12.10.3/d3.layout.min.js"></script>
<div id="chart"></div>
<script>
var r = 960,
format = d3.format(",d"),
fill = d3.scale.category20c();
var bubble = d3.layout.pack()
.sort(null)
.size([r, r]);
var vis = d3.select("#chart").append("svg")
.attr("width", r)
.attr("height", r)
.attr("class", "bubble");
d3.json("flare.json", function(err, json) {
var node = vis.selectAll("g.node")
.data(bubble.nodes(classes(json))
.filter(function(d) { return !d.children; }))
.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 fill(d.packageName); });
node.append("text")
.attr("text-anchor", "middle")
.attr("dy", ".3em")
.text(function(d) { return d.className; })
.each(function(d) {
var rect,
r2 = d.r * d.r,
s = d.r * 2,
t = d3.select(this);
do {
t.style("font-size", s-- + "px");
rect = this.getBBox();
} while (norm2(rect.x, rect.y) > r2
|| norm2(rect.x + rect.width, rect.y) > r2
|| norm2(rect.x + rect.width, rect.y + rect.height) > r2
|| norm2(rect.x, rect.y + rect.height) > r2);
});
});
function norm2(x, y) {
return x * x + y * y;
}
// 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};
}
</script>
Modified http://mbostock.github.com/d3/d3.min.js to a secure url
Modified http://mbostock.github.com/d3/d3.layout.min.js to a secure url
https://mbostock.github.com/d3/d3.min.js
https://mbostock.github.com/d3/d3.layout.min.js