简体   繁体   中英

How change position node for level in d3JS

I'm using using d3js (i new in javascript) for create organization chart, looking this example Interactive d3.js tree diagram , but i want to change level position of node. I'm looking for something like:

具有级别和节点的树

Any help would be much appreciated. Thanks.
I'm Sorry foy my English

The linked sample is built around D3 tree layout, thus, every node's position is defined by its parent node.

const tree = d3.layout.tree()
    .size([height, width]);

const nodes = tree.nodes(root).reverse()
const links = tree.links(nodes);

What you want to achieve contradicts the tree layout by definition . In other words, you just need to build a layout of your own: calculate x and y positions for every node according to your guidelines.

When you have an array of nodes [{x, y, ...}, {x, y, ...}, ...] and array of links [{source: node, target: node}, ...] you can render them exactly like in the sample (the code below // Update the nodes… line)

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