D3 v4 force layout rect overlapping

495 views
Skip to first unread message

Luis Mexin

unread,
May 16, 2017, 2:47:08 AM5/16/17
to d3-js
Hello! 

I created a force layout with rects containing text inside of them, my main problem now is that I don't want rects to overlap is there any example of collision detection that I could apply to this, I found so far only examples for d3 v3 and to be honest I'm fairly new using D3 v4, so I have no idea how to make this work the way I want, any help will be highly appreciated! 

I'm attaching a screenshot of my force layout marked on red what I would like to avoid.


Thanks again for the help! Have a nice day! 
Screen Shot 2017-05-16 at 1.40.35 AM.jpg

steve rickus

unread,
May 16, 2017, 11:47:47 AM5/16/17
to d3-js
It looks like the collision detector is just using the distance between the center of the boxes, not taking the length into account. Here is an example block that seems to have much better detector logic...

Luis Mexin

unread,
May 17, 2017, 3:27:00 AM5/17/17
to d3-js
Thanks a lot Steve! the example you added was perfect! I got it working, still I need to optimize some minor things, but now the nodes are working repelling each other! 
Reply all
Reply to author
Forward
0 new messages