avoid d3.js circles overlapping

user1249791 picture user1249791 · Jul 5, 2012 · Viewed 23.9k times · Source

You can see in this bl.ock http://bl.ocks.org/3012590 that there are many points geo-referenced in Paris, with the big circle over the little ones:

enter image description here

I would like to get something similar to http://vallandingham.me/vis/gates/ , so that circles get closely appended by its border.

enter image description here

Sorry, I could not find the answer in this code, i am missing something I think.

Is there an easy fix to get that? tried different negative charge forces, causing problems if circle size changes (if all circles in Paris become little, then they become too far away each other)?

Answer

mbostock picture mbostock · Jul 6, 2012

If your goal is to prevent overlap, then detecting collisions is a more direct way of satisfying that constraint. This will produce a more precise result than repulsive charge forces. Here’s another example:

You don't need a force layout to accomplish this, though the two are often used together. You can iterate over the nodes a fixed number of times to resolve any collisions on initialization.