简体   繁体   中英

d3.js tree layout need to expand as nodes open, not compress

I'm using the tree layout and code similar to http://mbostock.github.io/d3/talk/20111018/tree.html

I modified it for a top down orientation. As each node is opened/expanded, the other open nodes compress to fit everything within the SVG element. Is it possible to prevent that? I would think modifying the x component of each node would be the approach but have not been able to accomplish that. The nodes move over, but are still compressed together.

Also wondering how to change the linking lines from a bezier to right angles/straight lines. Perhaps a separate question is needed.

The compression is automatic in the tree layout (and part of its point). There's no way to turn that off. However, you can simply make your SVG large enough to contain the entire expanded tree without compression. Note that this means that unless your screen is large enough scroll bars will be displayed even when everything that is visible fits onto the screen.

The links connecting the nodes are generated using the diagonal line generator in the example. In principle, you can replace this with any other line generator (eg d3.svg.line ), but in practice some changes will be necessary because the diagonal line generator accesses source and target nodes in a special way. For a normal line generator, you would need to convert this structure to a two-element array and for each element specify how to access x/y coordinates. Then you can use any of the interpolations to get the curve you want.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM