Just say I have a d3-force
simulation, and I add some forces like this:
const simulation = d3
.forceSimulation()
.nodes(dots)
.force("charge", d3.forceManyBody())
.force("link", d3.forceLink(links))
.force("center", d3.forceCenter());
.on("tick", tick)
Is it possible to list all those forces? Something like a simulation.getForces()
method for instance? And have it return ["charge", "link", "center"]
.
I'm afraid not. From the source it looks like the
forces
Map is not exposed at all to the outside. The only workaround I can think is to either wrap thesimulation.force
object and store your own registry (which is hacky), or to keep an array of all possible values and see ifsimulation.force(name)
returns anything: