title: Wrapping long text labels in D3 without extra new lines
body: <p>Utilizing <a href="http://bl.ocks.org/mbostock/7555321" rel="nofollow noreferrer">Mike Bostock’s Wrapping Long Labels function</a> I was able to wrap long text labels in D3.js. However I see that my D3 chart inserts extra new lines when a particular text needs to be wrapped into more than two lines. Can you please help me to wrap without these extra new lines? <a href="https://i.stack.imgur.com/9s0R1.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/9s0R1.jpg" alt="enter image description here"></a></p>
  
  <p>Here are my label data and Mike Bostock’s code I used.</p>
  
  <pre><code>treeData = {
      'name': 'Good Short Label',
      'parent': 'null',
      '_children': [
          {'name': 'Very Very Long Good Wapped Label'},
          {'name': 'Very Very Very Very Very Very Very Very Very Long Label With Extra New Line'},
          {'name': 'Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Long Label With Extra New Lines'}
      ]
  };
  
  function wrap(text, width) {
      text.each(function () {
          var text = d3.select(this),
              words = text.text().split(/\s+/).reverse(),
              word,
              line = [],
              lineNumber = 0,
              lineHeight = 1.1, // ems
              x = text.attr('x'),
              y = text.attr('y'),
              dy = 0, //parseFloat(text.attr('dy')),
              tspan = text.text(null)
                  .append('tspan')
                  .attr('x', x)
                  .attr('y', y)
                  .attr('dy', dy + 'em');
          while (word = words.pop()) {
              line.push(word);
              tspan.text(line.join(' '));
              if (tspan.node().getComputedTextLength() &gt; width) {
                  line.pop();
                  tspan.text(line.join(' '));
                  line = [word];
                  tspan = text.append('tspan')
                      .attr('x', x)
                      .attr('y', y)
                      .attr('dy', ++lineNumber * lineHeight + dy + 'em')
                      .text(word);
              }
          }
      });
  }
  </code></pre>
  
  <p>Here is the <a href="http://jsfiddle.net/Qh9X5/8589/" rel="nofollow noreferrer">jsfiddle link</a> to replicate this.</p>