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

Link distance only being called a few times. #361

Open
hvent90 opened this issue Sep 3, 2024 · 1 comment
Open

Link distance only being called a few times. #361

hvent90 opened this issue Sep 3, 2024 · 1 comment

Comments

@hvent90
Copy link

hvent90 commented Sep 3, 2024

I'm not 100% sure if this is a bug.

myCoolForceGraph.d3Force('link', d3.forceLink().distance(() => console.log('test'));

test only gets logged a few times. I have confirmed that the simulation is running, including reheating the simulation.

Am I misunderstanding something? I am trying to change the line distance during runtime via a button click.

Thanks for the wonderful library :) It's hard to overstate just how large of value this is providing to me, for free no less.

Have a great day.

@vasturiano
Copy link
Owner

@hvent90 thanks for reaching out.

This is the expected behaviour as mentioned in the d3-force link distance docs:

The distance accessor is invoked for each link, being passed the link and its zero-based index. The resulting number is then stored internally, such that the distance of each link is only recomputed when the force is initialized or when this method is called with a new distance, and not on every application of the force.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants