function beeswarm(
data,
{
bind = null,
width = 1000,
height = 500,
r = d3.scaleSqrt([100, 1000], [1, Math.sqrt(width * height) / 30]),
margin = {
top: 100,
right: 0,
bottom: 10,
left: 100
}
}
) {
console.log(data);
bind.selectAll("svg").remove();
const chartwidth = width - margin.left - margin.right;
const chartheight = height - margin.top - margin.bottom;
const beeswarm = beeswarmForce()
.x((d) => x(d.Age))
.y(chartheight / 2)
.r(1 + 2);
console.log(data);
const x = d3.scaleLinear(
d3.extent(data, (d) => d.Age),
[0, chartwidth]
);
const svg = bind
.append("svg")
.attr("width", width + margin.left + margin.right)
.attr("height", height + margin.top + margin.bottom);
const g = svg
.append("g")
.attr("transform", `translate(${[margin.left, margin.top]})`);
g.append("g")
.call(d3.axisBottom(x).tickSizeOuter(0))
.attr("transform", `translate(0, ${chartheight / 1.25})`);
g.selectAll("circle")
.data(beeswarm(data))
.join("circle")
.attr("stroke", "black")
.attr("fill-opacity", 0)
.attr("cx", (d) => d.x)
.attr("cy", (d) => d.y)
.attr("r", 2);
return svg.node();
}