I would like to get the text to wrap on the following D3 tree so that instead of
Foo is not a long word
each line is wrapped to
Another option, if you're willing to add another JS lib, is to use D3plus, a D3 addon. It has built-in text wrapping functionality. It even supports padding and resizing text to fill the available space.
d3plus.textwrap()
.container(d3.select("#rectWrap"))
.draw();
I've used it. It sure beats calculating the wrapping yourself.
There's another d3 plugin available for text wrapping but I've never used it so I can't speak to it's usefulness.