سؤال

The description of this example: http://bl.ocks.org/mbostock/4062045 (find image below), states that it is "A physical simulation of charged particles and springs places related characters in closer proximity."

enter image description here

I was just curious which part of that code (on that same page) implements or defines the spring forces, especially based on related characters?

I ask this because i was under the impression that D3.js does not implement spring forces for the Force directed layouts, as mentioned in its API documentation:

"Links are not implemented as "spring forces", as in common in other force-directed layouts, but as weak geometric constraints." -https://github.com/mbostock/d3/wiki/Force-Layout#wiki-linkDistance

هل كانت مفيدة؟

المحلول

In D3 force-directed layout, the spring forces are defined using the gravity method that defaults to 0.1 if not set.

Check out this fiddle of the same example you mentioned with gravity set to 0.9.

The "weak geometric constraints" mentioned in the linkDistance documentation are talked about further here.

"gravity is implemented as a weak geometric constraint similar to a virtual spring connecting each node to the center of the layout's size. "

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top