This is a fork of Mike Bostock's Block/Gist showing how to wrap long labels in D3. However, I've adapted it to use D3 v4 (latest version of D3 at time of writing).
This demonstration uses satirical data from The Onion.
The changes to Bostock's code are not substantial.
- Some method names and usages had to change to be compatible with D3 v4.
- I decluttered most of the JavaScript semicolons.
- I replaced many of the pure
function
declarations with easier-to-read arrow functions.
Hello!
I'd suggest to modify line 105 check with:
if (tspan.node().getComputedTextLength() > width && line.length > 1) {
Current code will create empty lead tspan if first word on the list has bigger width, than it can take.
Thanks! Hope it will help someone :)