score:1

Accepted answer

You can use text-anchor attribute of SVG text to solve this problem like below:

            var text = d3.select(this.parentNode)
                        .append('text')
                        .attr('dx',parseInt(x)+3)
                        .attr('dy',y)
                        .text(d.id)
                        .attr("class","texto_circulo");

          if (text.node().getBoundingClientRect().right > d3.select('#chartProductos').node().getBoundingClientRect().right) {
            text.attr('dx', parseInt(x)-3);
            text.attr('text-anchor', 'end');
          }

https://jsfiddle.net/yLfv85rf/1/


Related Query

More Query from same tag