Force Based label placement/Collision Detection - Overlapping

1,379 views
Skip to first unread message

jose banks

unread,
Oct 24, 2012, 7:21:54 PM10/24/12
to d3...@googlegroups.com
So at the moment I have implemented d3.layout.force() on my circles so they do not overlap, but it doesn't work on the label that I have & if you refresh enough they eventually overlap. I've tried to implement on both with no luck .. I've based my idea on this example - http://bl.ocks.org/1377729

This is t he current attempt of the force label, but if you run it multiple times you'll see the text overlaps... http://jsfiddle.net/xwZjN/4/


I've tried to implement this code for the labels/text : 


        var force2 = d3.layout.force()
  .charge(-550)
  .linkDistance(50);

  force2 
  .nodes(json)
  .start();


But, to no avail! Am I going about it in the wrong way? Please help.

Alexander Skaburskis

unread,
Oct 25, 2012, 1:49:41 PM10/25/12
to d3...@googlegroups.com
In your fiddle you are using a force layout to place the nodes and then putting the label next to the nodes, so if you have a lot of points or long labels they will overlap.

In the example you linked there are actually 2 force layout objects at work! One for the circles (force) and one for the text-circle pairs (force2). Then for every tick on the force layout it runs the force2 layout to figure out a good spot for the labels given the current circle locations. There is a lot of subtlety in that example, read it closely! It took me several times to figure out what was going on.
Reply all
Reply to author
Forward
0 new messages