最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - d3js force node starting position - Stack Overflow

programmeradmin0浏览0评论

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: /

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

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/2eM8Z/

I tried setting cx and cy before defining force but that did not help
Share Improve this question asked Feb 13, 2014 at 20:54 PainFlyPainFly 552 silver badges4 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 4

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. 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.

发布评论

评论列表(0)

  1. 暂无评论