简体   繁体   English

如何在 d3JS 中更改 position 节点的级别

[英]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.我正在使用 d3js(我是 javascript 中的新功能)创建组织结构图,查看此示例Interactive d3.js 树图,但我想更改节点的 position 级别。 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.链接样本围绕 D3 树布局构建,因此,每个节点的 position 由其父节点定义。

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.换句话说,您只需要构建自己的布局:根据您的指导计算每个节点的xy位置。

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)当你有一个节点数组[{x, y, ...}, {x, y, ...}, ...]和链接数组[{source: node, target: node}, ...]您可以像在示例中一样渲染它们(下面的代码// Update the nodes…行)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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