chart = {
const svg = d3.create("svg")
.attr("viewBox", [0, 0, width, height]);
svg.append("g").call(xAxisBottom);
svg.append("g").call(xAxisTop);
svg.selectAll(".grid-line")
.data(x.ticks())
.join("line")
.attr("class", "grid-line")
.attr("x1", d => x(d))
.attr("x2", d => x(d))
.attr("y1", margin.top)
.attr("y2", height - margin.top)
.attr("stroke-width", 1)
.attr("stroke", "lightgray");
svg.selectAll(".line-beeswarm")
.data(families)
.join("line")
.attr("class", "line-beeswarm")
.attr("x1", margin.left - 10)
.attr("x2", width - margin.right + 10)
.attr("y1", d => y(d))
.attr("y2", d => y(d))
.attr("stroke-width", 0.2)
.attr("stroke", d => color(d));
svg.selectAll(".label-family")
.data(families)
.join("text")
.attr("class", "label-family")
.attr("x", 0)
.attr("y", d => y(d))
.attr("alignment-baseline", "middle")
.text(d => d ? d : "other");
const pair = svg.selectAll(".beeswarm-pair")
.data(nested)
.join("g")
.attr("class", (d) => "beeswarm-pair")
.attr("fill", (d) => color(d.key));
pair.selectAll(".circle-top")
.data((d) => dodge(d.values.filter(e => e.currentShare), radius * 2 + padding))
.join("circle")
.attr("class", "circle-top")
.attr("cx", (e) => e.x)
.attr("cy", (e) => y(e.data.family) - radius - padding - e.y);
pair.selectAll(".circle-bottom")
.data((d) => dodge(d.values.filter(e => !e.currentShare), radius * 2 + padding))
.join("circle")
.attr("class", 'circle-top')
.attr("cx", (e) => e.x)
.attr("cy", (e) => y(e.data.family) + radius + padding + e.y)
.attr('opacity', 0.25);
pair.selectAll("circle")
.attr("r", radius)
.append("title")
.text(d => `${d.data.party} (${d.data.country}, ${formatYear(d.data.date)}); ${d.data.share} -> ${d.data.currentShare}`);
return svg.node();
}