{
const svg = d3.create("svg").attr("viewBox", [0, 0, width, height]);
const iwidth = width - margin.right - margin.left;
const g = svg
.append("g")
.attr("transform", `translate(${margin.left}, ${margin.top})`);
const dur = d3
.scaleBand()
.domain(new Set(data.map(d => d[catAttrib])).values())
.range([0, 1]);
const attrName = d3
.scaleOrdinal()
.domain(new Set(data.map(d => d[catAttrib])).values())
.range(["", "cx", "cy"]);
g.selectAll(".row")
.data(data)
.join("circle")
.attr("r", 5)
.attr(
"transform",
d =>
`translate(${Math.random() * iwidth}, ${(Math.random() * height) / 2})`
)
.append("animate")
.attr("attributeName", d => attrName(d[catAttrib]))
.attr("values", "0;5;0")
.attr("dur", d => dur(d[catAttrib]) + "s")
.attr("repeatCount", "indefinite");
return svg.node();
}