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 be parameterized per node? #8

Closed
mbostock opened this issue Apr 6, 2016 · 1 comment
Closed

Should forces be parameterized per node? #8

mbostock opened this issue Apr 6, 2016 · 1 comment
Assignees

Comments

@mbostock
Copy link
Member

mbostock commented Apr 6, 2016

In the new design, you pass each force the array of nodes (and in some cases links):

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);

This has the benefit that you can give each force a different subset of the nodes, but it raises some questions:

  1. What if I want each node’s forces to have different parameters? Do I need to register separate forces for each node? Or should the force be parameterizable, e.g., forceLink.strength takes a function that is evaluated for each link?
  2. If the force is parameterizable, does that mean the parameters are re-evaluated when the array of nodes (or links) changes, or are the parameters evaluated every time the force is invoked? Is it worth trying to optimize the common case of constant-value forces?
  3. If forces are parameterizable, why do we also need to specify the array of nodes to each force—couldn’t they just always use the array of nodes associated with the simulation, and you could define the strength as zero if you didn’t want the force to apply to those nodes?
  4. If forces do always use the simulation’s array of nodes, should the simulation also keep track of the links? (Probably not, since I think links only need to be known by d3.forceLink, whereas multiple parties care about nodes?)
@mbostock mbostock self-assigned this Apr 6, 2016
@mbostock mbostock changed the title Per-node forces? Per-node parameterized forces? Apr 6, 2016
@mbostock mbostock changed the title Per-node parameterized forces? Should forces be parameterized per node? Apr 6, 2016
@mbostock
Copy link
Member Author

  1. Forces should be parameterized per node (or per link).
  2. The parameters should be re-evaluated when the nodes (or links) or parameters change.
  3. The forces should receive the nodes from the simulation (via the optional force.nodes method).
  4. The simulation will not track links because these are only used by the link force.

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