문제

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.

도움이 되었습니까?

해결책

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;
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top