grantshandy / fdg

A Force Directed Graph Drawing Library
https://grantshandy.github.io/fdg
MIT License
192 stars 16 forks source link

How to use multiple forces at once? #16

Open micahscopes opened 11 months ago

micahscopes commented 11 months ago

I'm interested in playing with custom forces, as well as combining in some other graph layout techniques for minimizing edge crossings (stuff like this tabu search layout idea).

Is there a suggested way of combining multiple forces? Should I create multiple Simulations and step through them in a custom event loop? Or is there a shortcut for doing this kind of thing?

grantshandy commented 11 months ago

Currently, there isn't any good way to do this AFAIK. You could create a Force that runs each simulation individually inside of it, but that's not so clean. I'm planning on starting the re-write soon, and I'll consider adding support for that 🤔. Thanks!

micahscopes commented 9 months ago

I've been checking out the changes in the dev branch and I really like the API. It's clean and straightforward. I used it to create an edge-crossing minimizing optimization force that swaps positions of nearby nodes in search of an optimal permutation: https://github.com/micahscopes/cobwebs-2024/blob/main/src/grid_wanderer.rs#L25

The only thing that was a little tricky was that I needed to add a lot of type constraints for the node and edge types in order to get the position swapping to work.

(As far as layout goes, it sort of works but it's not very flexible. It only searches the node position permutation space. I think it'd be good to actually move the nodes themselves around on a grid and search that space instead as well.)