Wrapping Text in D3

后端 未结 4 1704
礼貌的吻别
礼貌的吻别 2020-12-09 16:50

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



        
4条回答
  •  眼角桃花
    2020-12-09 17:20

    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.

提交回复
热议问题