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
Run force layout synchronously. #419
Comments
Any thought about the specific implementation? Cause right now a worker like this could already work and returned the positioned nodes (not tested): var force = ... self.addEventListener('message', function(e) { |
Yeah, I think it's just a question of making the internal |
Yep, that would work. So far when I wanted to do something similar I had a function listening to tick events that had a condition to check when alpha was smaller than a predefined value. |
I'm not sure this entirely fixes the problem. Seems to me that before you can call force.tick() you still need to call force.start() once to initialize everything. However, start() calls resume() which calls d3.timer(force.tick()), which means you're going to have both your synchronous method and the timer-driven async method both poking at the layout. |
Well, assuming you run the force layout synchronously to completion, the timer will get called back once after that, and will only run once because Also, you can cancel the timer by calling I could see adding an optional argument so that you could |
What bothers me is that by calling |
There's no race condition, because JavaScript is single-threaded. It's impossible to receive a callback while your code is still running. |
Ahh, yes, that would be the forest I was missing while examining the tree in front of me. Never mind... |
I finally got out from under my other projects and got back to this one. Turns out that I need a way to call start() without getting the call to resume(). Doing this cleanly will require at least one more API change. I can see three solutions:
I was going to send you pull request for #3, but I figured you might prefer #2, or maybe something else. Let me know if you want me to code something up. |
The "one call to tick" was fixed in 2.7.5. See #510. |
It might be nice to have the ability to run the force layout synchronously, so that you could (say) run it a fixed number of iterations, or until the alpha dropped below a certain value. Then you could initialize a force layout synchronously on page layout, or externalize the computation to a webworker.
The text was updated successfully, but these errors were encountered: