chart = {
const root = pack(data);
const svg = d3.create("svg")
.attr("viewBox", [0, 0, width, height])
.attr("font-size", 10)
.attr("font-family", "sans-serif")
.attr("text-anchor", "middle");
const leaf = svg.selectAll("g")
.data(root.leaves())
.join("g")
.attr("transform", d => `translate(${d.x + 1},${d.y + 1})`);
leaf.append("path")
.attr("d", d => {
const h = (Math.sqrt(3)/2),
radius = d.r,
xp = 0,
yp = 0,
hexagonData = [
{ "x": radius+xp, "y": yp},
{ "x": radius/2+xp, "y": radius*h+yp},
{ "x": -radius/2+xp, "y": radius*h+yp},
{ "x": -radius+xp, "y": yp},
{ "x": -radius/2+xp, "y": -radius*h+yp},
{ "x": radius/2+xp, "y": -radius*h+yp}
];
return drawHexagon(hexagonData);
})
.attr("id", d => (d.leafUid = d.data.patientId))
.attr("fill", d => color(d.data.cluster))
.attr("stroke", d => color(d.data.cluster))
.attr("stroke-opacity", d => d.data.gender === 'Female' ? 0 : 1.0)
.attr("fill-opacity", d => d.data.gender === 'Female' ? 0 : 0.5);
leaf.append("circle")
.attr("id", d => (d.leafUid = d.data.patientId))
.attr("r", d => d.r)
.attr("fill", d => color(d.data.cluster))
.attr("stroke", d => color(d.data.cluster))
.attr("stroke-opacity", d => d.data.gender === 'Male' ? 0 : 1.0)
.attr("fill-opacity", d => d.data.gender === 'Male' ? 0 : 0.5);
leaf.append("clipPath")
.attr("id", d => (d.clipUid = d.data.patientId))
.append("use")
.attr("xlink:href", d => d.leafUid.href);
leaf.append("text")
.attr("clip-path", d => d.clipUid)
.text(d => d.data.patientId);
leaf.append("title")
.text(d => d.data.patientId);
return svg.node();
}