javascriptdagre-d3dagre

dagre-d3- make the long text to fit inside node


In the setNode we can specify the html as well. if i mention width and height, and if it a long text, it is moving out.

g.setNode(0, {
    labelType: "html",
    label: '<div style="color: red; width: 90px; height: 30px;">test data overlapping</div>',
    width: 70,
    height: 35
});

I tried to give width to the div but it is not working sample Fiddle

How can i make the text to fit inside node?


Solution

  • Use the auto property on width and height like this:

    Sample Fiddle

    using auto the element will automatically adjust its height and width to allow its content to be displayed correctly.