0๐
โ
I found a workaround for it.
I created a function getMyCentroid.
function getMyCentroid(element) {
var bbox = element.node().getBBox();
return [bbox.x + bbox.width/2, bbox.y + bbox.height/2];
}
And call it instead of centroid function
.attr("x", function(d) {
return getMyCentroid(d3.select(`#${d.id}`))[0];
})
.attr("y", function(d) {
return getMyCentroid(d3.select(`#${d.id}`))[1];
})
Source:stackexchange.com