Built with blockbuilder.org
forked from LauraCortes's block: Arc Diagram
forked from LauraCortes's block: TreeMap
xxxxxxxxxx
<meta charset="utf-8">
<style>
rect {
fill: none;
stroke: #fff;
}
text {
font: 8px sans-serif;
}
</style>
<body>
<script src="//d3js.org/d3.v3.min.js"></script>
<script>
var width = 960,
height = 500,
color = d3.scale.category20c();
var treemap = d3.layout.treemap()
.padding(4)
.size([width, height])
.value(function(d) { return d.degree; });
var svg = d3.select("body").append("svg")
.attr("width", width)
.attr("height", height);
d3.json("graph.json", function(error, json) {
if (error) throw error;
console.log(json);
var cell = svg.data([json]).selectAll("g")
.data(treemap.nodes)
.enter().append("g")
.attr("class", "cell")
.attr("transform", function(d) { return "translate(" + d.x + "," + d.y + ")"; });
cell.append("rect")
.attr("width", function(d) { return d.dx; })
.attr("height", function(d) { return d.dy; })
.style("fill", function(d) { return d.children ? color(d.label) : null; });
cell.append("text")
.attr("x", function(d) { return d.dx / 2; })
.attr("y", function(d) { return d.dy / 2; })
.attr("dy", ".35em")
.attr("text-anchor", "middle")
.text(function(d) { return d.children ? null : d.label; });
});
</script>
https://d3js.org/d3.v3.min.js