简体   繁体   English

d3js强制节点起始位置

[英]d3js force node starting position

I want to load every node to it's position and then start force that will move nodes away from each other so they don't overlap. 我想将每个节点加载到其位置,然后开始施加力,以使节点彼此远离,以免它们重叠。 Currently I have working but nodes are moved all over screen at force start and not staying at their initial position when force is started. 目前,我正在工作,但是在强制启动时节点在整个屏幕上移动,并且在强制启动时并没有停留在其初始位置。 Is there a way to set initial position and then start collision detection with force? 有没有办法设置初始位置然后用力开始碰撞检测?

jsfidle example: http://jsfiddle.net/2eM8Z/ jsfidle示例: http//jsfiddle.net/2eM8Z/

I tried setting cx and cy before defining force but that did not help

In order to initialise the positions of the nodes in a force layout, you need to set the x and y attributes, as this is what the force layout uses -- not cx and cy . 为了初始化力布局中节点的位置,您需要设置xy属性,因为这是力布局使用的属性,而不是cxcy If you do that with your current code however, it won't work because the nodes will overlap initially which means that the repulsive forces are too strong. 但是,如果您使用当前代码执行此操作,则该操作将无效,因为节点最初会重叠,这意味着排斥力过大。 It works fine if you place them a small distance apart to start with. 如果您将它们分开一小段距离就可以很好地工作。

Complete demo here . 在此处完成演示。

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

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