Accepted answer

The attractive forces of the built-in d3.forceManyBody can be modified with the strength() method so try something like

  // starts simulation
  var simulation = d3
  .force("link", d3.forceLink())
  .force("charge", d3.forceManyBody().strength(-5))
  .force("center", d3.forceCenter(width /2, height / 2))

If that constrains the other items too closely then you would have to implement your own force method which can constrain items based on the SVG size. See d3.force for a description of what is happening under-the-hood and to see how you could produce your own function.

Related Query

More Query from same tag