chart = {
const svg = d3.create("svg")
.attr("viewBox", [0, 0, width, height]);
svg.append("g")
.attr("fill", color)
.selectAll("rect")
.data(data)
.join("rect")
.attr("x", x(0))
.attr("y", (d, i) => y(i))
.attr("width", d => x(d.value) - x(0))
.attr("height", y.bandwidth());
svg.append("g")
.attr("fill", "white")
.attr("text-anchor", "end")
.attr("font-family", "sans-serif")
.attr("font-weight", "bolder")
.attr("font-size", 14)
.selectAll("text")
.data(data)
.join("text")
.attr("x", d => x(d.value))
.attr("y", (d, i) => y(i) + y.bandwidth() / 2)
.attr("dy", "0.35em")
.attr("dx", -4)
.text(d => textFormat(d.value))
.call(text => text.filter(d => x(d.value) - x(0) < textOut)
.attr("dx", +4)
.attr("fill", "black")
.attr("text-anchor", "start"));
svg.append("g")
.call(yAxis);
return svg.node();
}