Pack Layout

var packLayout = d3.pack();
packLayout.size([300, 300]);
rootNode.sum(d => d.value);
packLayout(rootNode);


Last updated

var packLayout = d3.pack();
packLayout.size([300, 300]);
rootNode.sum(d => d.value);
packLayout(rootNode);


Last updated
d3.select('svg g')
.selectAll('circle')
.data(rootNode.descendants())
.enter()
.append('circle')
.attr('cx', function(d) { return d.x; })
.attr('cy', function(d) { return d.y; })
.attr('r', function(d) { return d.r; })var nodes = d3.select('svg g')
.selectAll('g')
.data(rootNode.descendants())
.enter()
.append('g')
.attr('transform', d => 'translate(' + [d.x, d.y] + ')')
nodes
.append('circle')
.attr('r', d => d.r)
nodes
.append('text')
.attr('dy', 4)
.text(d => d.children === undefined ? d.data.name : '')