Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Should forces just be listeners? #9

Closed
mbostock opened this issue Apr 6, 2016 · 0 comments
Closed

Should forces just be listeners? #9

mbostock opened this issue Apr 6, 2016 · 0 comments
Assignees

Comments

@mbostock
Copy link
Member

mbostock commented Apr 6, 2016

It seems weird to just piggyback on dispatch.on:

var simulation = d3.forceSimulation(nodes)
    .on("beforetick.charge", d3.forceManyBody(nodes))
    .on("beforetick.link", d3.forceLink(nodes, links))
    .on("beforetick.position", d3.forcePosition(nodes).position([width / 2, height / 2]))
    .on("tick", draw);

Maybe the simulation should track named forces, allowing us to develop a more specific interface for forces?

var simulation = d3.forceSimulation(nodes)
    .force("charge", d3.forceManyBody(nodes))
    .force("link", d3.forceLink(nodes, links))
    .force("position", d3.forcePosition(nodes).position([width / 2, height / 2]))
    .on("tick", draw);

Or, if per #8 forces inherit nodes from the simulation:

var simulation = d3.forceSimulation(nodes)
    .force("charge", d3.forceManyBody)
    .force("link", d3.forceLink(links))
    .force("position", d3.forcePosition.position([width / 2, height / 2]))
    .on("tick", draw);

And if per #7 forces are mutable:

var simulation = d3.forceSimulation(nodes)
    .force("charge", d3.forceManyBody())
    .force("link", d3.forceLink(links))
    .force("position", d3.forcePosition().position([width / 2, height / 2]))
    .on("tick", draw);

Related: it’s a little annoying to give each force a name.

@mbostock mbostock self-assigned this Apr 6, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant