chart = {
const root = pack(data);
const svg = d3.create("svg")
.attr("viewBox", [0, 0, width, height]);
const node = svg.selectAll("g")
.data(d3.nest().key(d => d.height).entries(root.descendants()))
.join("g")
.selectAll("g")
.data(d => d.values)
.join("g")
.attr("transform", d => `translate(${d.x + 1},${d.y + 1})`);
const leaf = node.filter(d => !d.children);
leaf.append("circle")
.attr("r", d => d.r)
.attr('stroke', '#ccc')
.attr('stroke-opacity', 0)
.attr('fill', '#ccc')
.attr('fill-opacity', 0);
leaf.append('path')
.attr('d', (object) => {
const d = object.data;
const r = object.r;
const w = r * 2;
const extent = [[-w/2, -w/2], [w/2, w/2]];
const projection = d3.geoIdentity()
.reflectY(true)
.fitExtent(extent, d.feature);
const path = d3.geoPath()
.projection(projection);
return path(d.feature);
})
.attr('fill', 'steelblue');
return svg.node();
}