{
const svg = d3.select(DOM.svg(width, height));
const defs = svg.append("defs");
const artboard = svg.append("g");
const node = artboard
.selectAll(".node")
.data(nodes)
.join("g")
.attr("transform", d => `translate(${d.x}, ${d.y}) rotate(${d.r + 90})`);
node
.append("path")
.attr("fill", (d, i) => colorScale(i))
.attr("d", symbol)
.filter((d, i, items) => items.length - 1 === i)
.attr("mask", "url(#mask)");
const mask = defs.append("mask").attr("id", "mask");
mask
.append("path")
.attr("d", symbol)
.attr("fill", "white");
mask
.append("path")
.attr("d", symbol)
.attr("fill", "black")
.attr("transform", () => {
const a = nodes[0];
const b = nodes[nodes.length - 1];
const cx = a.x - b.x;
const cy = a.y - b.y;
const cr = a.r - b.r;
return `translate(${cy}, ${cx}) rotate(${cr})`;
});
return svg.node();
}