function animateLink(linkData, index, totalLinks, callback) {
const link = d3.select(pathForInstance)
.data([linkData])
.join('path')
.attr('d', d3.linkHorizontal().x(d => d.y).y(d => d.x))
.attr("stroke-dasharray", function() {
const length = this.getTotalLength();
return `${length} ${length}`;
})
.attr("stroke-dashoffset", function() {
return this.getTotalLength();
});
link.transition()
.duration(2000)
.attr("stroke-dashoffset", 0)
.on("end", () => {
if (index < totalLinks - 1) {
callback(index + 1);
}
});
}