在D3力引导布局中固定节点位置

阅读时长 2 分钟读完

Infinite RecursionElijah提出了一个问题:Fix Node Position in D3 Force-Directed Layout,或许与您遇到的问题类似。

回答者mbostock给出了该问题的处理方式:

Set d.fixed on the desired nodes to true, and initialize d.x and d.y to the desired position. These nodes will then still be part of the simulation, and you can use the normal display code (e.g., setting a transform attribute); however, because they are marked as fixed, they can only be moved by dragging and not by the simulation.

See the force layout documentation for more details, and also see how the root node is positioned in this example.

希望本文对你有帮助,欢迎支持JavaScript中文网

来源:JavaScript中文网 ,转载请注明来源 https://www.javascriptcn.com/post/13933

纠错
反馈