I am using sunburst example as a basis and trying to change multi-lined caption on clicking with a new data. The click function looks like this:
function click(d) {
text.transition().attr("opacity", 0);
console.log(d.depth);
path.transition()
.duration(750)
.attrTween("d", arcTween(d))
.each("start", function(e, i) {
if (e.x >= d.x && e.x < (d.x + d.dx))
{
var replaceText = d3.select(this.parentNode).select("text")
replaceText.remove("tspan")
var tspan = replaceText.append("tspan")
.attr("class", "sunburst2")
.attr("x", 0)
.attr("y", 0)
.attr("text-anchor", "middle")
.text("TEST");
}
})
//each
.each("end", function(e, i) {
if (e.x >= d.x && e.x < (d.x + d.dx))
{
var arcText = d3.select(this.parentNode).select("text")
arcText.transition().duration(750)
.attr("opacity", 1)
.attr("transform", function(d) {
return "translate(" + getCentroid(d) + ")rotate(" + textRotation(d) + ")";
})
.attr("text-anchor", "middle")
}
});
//end of each
}
PS: In this example the initial captions should be replaced by "TEST".
But it doesn't work and show nothing. What I am doing wrong? Thanks in advance. Any advice would be helpful.