function labels(svg) {
let label = svg
.append("g")
.style("font", "bold 12px var(--sans-serif)")
.style("font-variant-numeric", "tabular-nums")
.attr("text-anchor", "end")
.selectAll("text");
return ([date, data], transition) =>
(label = label
.data(data.slice(0, n), d => d.name)
.join(
enter =>
enter
.append("text")
.attr(
"transform",
d => `translate(${x(prev(d).value)},${y(prev(d).rank)})`
)
.attr("y", y.bandwidth() / 2)
.attr("x", -6)
.attr("dy", "-0.25em")
.text(d => title(d.name))
.call(text =>
text
.append("tspan")
.attr("fill-opacity", 0.7)
.attr("font-weight", "normal")
.attr("x", -6)
.attr("dy", "1.15em")
),
update => update,
exit =>
exit
.transition(transition)
.remove()
.attr(
"transform",
d => `translate(${x(next(d).value)},${y(next(d).rank)})`
)
.call(g =>
g
.select("tspan")
.tween("text", d => textTween(d.value, next(d).value))
)
)
.call(bar =>
bar
.transition(transition)
.attr("transform", d => `translate(${x(d.value)},${y(d.rank)})`)
.call(g =>
g
.select("tspan")
.tween("text", d => textTween(prev(d).value, d.value))
)
));
}