chart = {
const svg = d3.create("svg").attr("viewBox", [0, 0, width, height]);
svg
.append("g")
.selectAll("g")
.data(series)
.join("g")
.attr("fill", d => d.key === "u11" ? colours.primary : colours.primary50)
.selectAll("rect")
.data(d => d)
.join("rect")
.attr("x", d => x(d[0]))
.attr("y", (d, i) => y(d.data.force))
.attr("width", d => x(d[1]) - x(d[0]))
.attr("height", y.bandwidth())
svg
.append("g")
.selectAll("g")
.data(series)
.join("g")
.attr("fill", colours.primary)
.attr("text-anchor", "start")
.attr("font-family", graph.font)
.attr("font-size", graph.fontSize)
.selectAll("text")
.data(d => d)
.join("text")
.filter((d) => d[0] !== 0)
.attr("x", d => x(d[0]))
.attr("y", (d, i) => {
return y(d.data.force) + y.bandwidth() / 2
})
.attr("dy", "0.35em")
.attr("dx", 5)
.text(d => d[0])
svg
.append("g")
.attr("fill", colours.primary50)
.attr("text-anchor", "start")
.attr("font-family", graph.font)
.attr("font-size", graph.fontSize)
.selectAll("text")
.data(ageLeaderboard)
.join("text")
.filter((d) => d.total !== 0)
.attr("x", d => x(d.total))
.attr("y", (d, i) => {
return y(d.force) + y.bandwidth() / 2
})
.attr("dy", "0.35em")
.attr("dx", 4)
.text(d => d.total)
.call(text => text.filter(d => d.total > 150)
.text(d => d.total + " →")
.attr("x", width - 10)
.attr("fill", "white")
.attr("text-anchor", "end"));
svg.append("g").call(xAxis);
svg.append("g").call(yAxis);
return svg.node()
}