I've read the api here that says x.strength and y.strength will set the strength of gravity: https://github.com/d3/d3-force/blob/master/README.md#x_strength
But I how to apply it?
simulation = d3.forceSimulation()
.force("link", d3.forceLink().id(function (d) {
return d.id;
}).distance(10))
.force("charge", d3.forceManyBody().strength(-15))
.force("center", d3.forceCenter(width * 0.5, height / 2))
I did a quick search on GitHub:
https://github.com/search?l=JavaScript&q=forceX+strength&ref=searchresults&type=Code&utf8=%E2%9C%93
This looks like the correct syntax:
const forceX = d3.forceX(width / 2).strength(0.015)
const forceY = d3.forceY(height / 2).strength(0.015)
const simulation = d3.forceSimulation()
.force('x', forceX)
.force('y', forceY)
(from https://github.com/ivarmlee11/d3quake/blob/5f332d1d82d25b21097af78b4d1740bb092b4bb9/public/js/app.js#L17)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With