Question

Is there a way to alter the formula D3 uses for calculating the charge's repulsive force in a force layout?

It was previously stated that the D3 charge force follows the inverse-square law. But, I want to make the force decay even faster as the distance between nodes increases. I want to make the formula behave something more like charge/distance^3 or charge/distance^4 so that nodes only significantly repel each other when they're very close to each other.

Was it helpful?

Solution

Yes, you can modify the source code. The relevant file is here, in particular the repulse function. What's currently

var k = quad.charge * dn * dn;

you could change to

var k = quad.charge * dn * dn * dn;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top