d3.js - D3 Force Layout Variable Repulsive Foces -
I am working on a graph that contains variable size nodes: (click on F2 to start the force layout Do)
Is it possible to change counteractive forces on the runtime by node size? In fact, I'd like to encourage layout overlapping nodes ...
Force layout lets you create a function Allows you to specify the charge strength for each node, the node and its indicator are passed as logic.
If you make your nodes
data in such a manner that each element has an accessible property that represents its shape (called radius of a boundary circle) , Then you use this data to determine a relative charge value. For example, if each element in your data represents an asset of its property, it can do something like:
/ P>
var force = d3.layout.force () .Node (nodes). Size ([width, height]). Charge (Task (D) {Return-5 * Dr;}). On ('Tic', Tic) Start (); One factor of
-5
is completely arbitrary, and you have to choose a value that works well for your data. Positive values represent attraction, and repulsion is represented in negative values.In this action using circles, there is a simple demo of this technique.
Comments
Post a Comment