I am using d3 to create collapsable tree. Pretty much following this guide.
I am trying to add labels to path.
Here is my code to add labels to path.
var text = this.svg.append("text")
.append("textPath")
.attr("text-anchor", "middle")
.attr("xlink:href", "#blahblah")
.text((d)=> { return d.weight; });
The labels are rendered upside down the path. Not sure, what exactly is wrong. Any suggestions?
Update
Here is my path code
let link = this.svg.selectAll('path.link')
.data(links, function (d) {
return d.id;
});
// Enter any new links at the parent's previous position.
let linkEnter = link.enter().insert('path', 'g')
.attr('class', 'link')
.attr('id', (d) => {
return d.id;
})
.attr('d', (d) => {
let o = { x: source.x0, y: source.y0 };
return this.diagonal(o, o);
});
let linkUpdate = linkEnter.merge(link);
// Transition back to the parent element position
linkUpdate.transition()
.duration(this.duration)
.attr('d', (d) => {
return this.diagonal(d, d.parent);
});
// Remove any exiting links
let linkExit = link.exit().transition()
.duration(this.duration)
.attr('d', (d) => {
let o = { x: source.x, y: source.y };
return this.diagonal(o, o);
})
.remove();
private diagonal = (s, d) => {
let path = `M ${s.y},${s.x}
C ${(s.y + d.y) / 2},${s.x},
${(s.y + d.y) / 2},${d.x},
${d.y},${d.x}`;
return path;
}