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

d3.forceCenter should have an alpha parameter. #81

Closed
DavidBruant opened this issue Dec 27, 2016 · 3 comments · Fixed by #164
Closed

d3.forceCenter should have an alpha parameter. #81

DavidBruant opened this issue Dec 27, 2016 · 3 comments · Fixed by #164

Comments

@DavidBruant
Copy link

My use case is that I'm building a UI where people can add a node by double-clicking. The node appears where the mouse is.
I tried using d3.forceCenter, but when the node appears, it just recenters everything instantly which I find a bit aggressive. I want to provide a smoother experience (the whole graph gradually recenters)

Filing this issue for various reasons:

  • knowing whether this is the wanted behavior for default d3
  • whether the d3 project is interested in a PR on this topic (if so let's discuss what the new behavior would be)
  • if it's not a PR for the project, where should people gather if they want to create a library of forces for d3-force? Maybe just npm with the d3-force keyword?
@ekawahyu
Copy link

@DavidBruant: do you have a temporary workaround for it? I find it a bit annoying as well when adding and removing nodes. Thanks.

@mbostock
Copy link
Member

mbostock commented Jan 12, 2017

I think it’d be reasonable to implement an alpha (blend) parameter for d3.forceCenter so that it smoothly shifts to the new center. (Or maybe it could even use the simulation’s current alpha? You’d have to try it and see what works.) For example, each application of the force it would move 20% of the way to the new center. That way there’s a little bit of hysteresis for discontinuous changes such as adding a node.

I also think it’s a great idea to use the d3-force keyword to publish additional forces on npm.

@mbostock mbostock changed the title d3.forceCenter is too aggressive when a node is being added dynamically to the graph d3.forceCenter should have an alpha parameter. Mar 3, 2017
Fil added a commit that referenced this issue Jun 25, 2020
@Fil
Copy link
Member

Fil commented Jun 25, 2020

In my experiments having strength = 0.05 and multiplying sx, sy by alpha * strength results in a quite agreeable movement.
See PR #164 and demo https://observablehq.com/d/674136693ce67301

At this point I don't see the necessity to make it configurable?

Fil added a commit that referenced this issue Jul 27, 2020
@Fil Fil mentioned this issue Jul 27, 2020
5 tasks
Fil added a commit that referenced this issue Jul 28, 2020
@Fil Fil mentioned this issue Jul 28, 2020
4 tasks
Fil added a commit that referenced this issue Jul 30, 2020
and change x,y not vx, vy.
- this makes #81 non-breaking
- strength=1 recenters "at once" for non-interactive graphs (or, for example, the initial phyllotaxis layout)
- strength=0.05 recenters gently for interactive situations such as https://observablehq.com/d/674136693ce67301
Fil added a commit that referenced this issue Jul 30, 2020
and change x,y not vx, vy.
- this makes #81 non-breaking
- strength=1 recenters "at once" for non-interactive graphs (or, for example, the initial phyllotaxis layout)
- strength=0.05 recenters gently for interactive situations such as https://observablehq.com/d/674136693ce67301
Fil added a commit that referenced this issue Aug 1, 2020
and change x,y not vx, vy.
- this makes #81 non-breaking
- strength=1 recenters "at once" for non-interactive graphs (or, for example, the initial phyllotaxis layout)
- strength=0.05 recenters gently for interactive situations such as https://observablehq.com/d/674136693ce67301

fixes #81
@Fil Fil mentioned this issue Aug 1, 2020
3 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging a pull request may close this issue.

4 participants