Install Asset
Install via Godot
To maintain one source of truth, Godot Asset Library is just a mirror of the old asset library so you can download directly on Godot via the integrated asset library browser
Quick Information
force-directed-graph-godot is a simple implementation of a Force-Directed Graph (or FDG for short) in the Godot Engine.- 2D implementation of a Force-Directed Graph- Flexible and easy to use Graph Nodes that can be extended and customized- Real-time graph simulation in the editor (optional)
force-directed-graph-godot
is a simple implementation of a Force-Directed Graph (or FDG for short) in the Godot Engine.
Features
- 2D implementation of a Force-Directed Graph
- Flexible and easy to use Graph Nodes that can be extended and customized
- Editor UI for adding new nodes to your graph
- Real-time graph simulation in the editor (optional)
Supported Versions
Every 4.X version of the Godot Engine should work. The plugin was tested with Godot 4.1!
What is a Force-Directed Graph?
Force-directed graph drawing algorithms are a class of algorithms for drawing graphs in an aesthetically-pleasing way. (Wikipedia)
The graph is a physical simulation of a system of bodies (nodes) connected by springs (edges). The system is simulated by applying forces to the nodes and then updating their positions.
force-directed-graph-godot uses an implementation of the method showcased in this incredible lecture by David Dobervich. You can read a more in-depth explanation of the algorithm in the
Handbook of Graph Drawing and Visualization!
Usage
Setup
- Add a
ForceDirectedGraphnode to your scene. - Add
FDGNodenodes as children of theForceDirectedGraphnode. (Make sure to add a sprite or setdraw_pointtotrue) - Add
FDGSpringnodes as children of theFDGNodenodes. - Connect the
FDGNodenodes withFDGSpringnodes by setting thenode_startandnode_endproperties of theFDGSpringnodes. - After adding new Nodes or Springs, click the
Update Graphbutton on theForceDirectedGraphnode to update the graph.
Warning: You might have to reload your scene after adding new nodes to the graph, if
Update Graphdoes not work.
Nodes
ForceDirectedGraph
The main node of the graph. It is responsible for updating the positions of the nodes and springs. When adding new nodes or springs via code, you can call the update_graph() function to update the graph.
FDGNode
A node that is part of the graph. Can have different physical properties, such as speed, drag, radius, mass, etc.
FDGSpring extends
Line2D
The connection between two FDGNode nodes. The node_start and node_end properties must be set to the FDGNode nodes that should be connected by this spring.
Example
You can find this example graph in the example folder of the project. It uses a basic setup of FDGNodes and FDGSprings including one custom node (the big Godot Logo).
A simple UI for adding new nodes to the graph is also avaiable. Hover over the buttons to see their shortcuts.
Common questions and problems
Q: Why are there still lines, even if I removed all FDGSpring nodes?
A: You might need to reload the scene or use the update_graph on the ForceDirectedGraph node.
Q: Why are the nodes invisble?
A: FDGNodes are empty nodes by default. You can either enable draw_point to draw a point with the current radius or add your own sprites/scenes as children.
Q: Why are the nodes not moving in the editor?
A: You can disable editor simulation on the ForceDirectedGraph node.
Q: Why are the connection lines looking so jagged?
A: Try activating 2D anti-aliasing on the FDGSpring nodes AND in the project settings.
Documentation
For additional information, please refer to the documentation generated by the Godot Engine (F1) or dive into the source code yourself.
Future features
Automatically update the graph when adding/connecting new nodes or springs.
An easier way to add and connect nodes. (Editor GUI or toolbar)
Further optimizations and improvements.
Contributing
If you have any ideas or suggestions, feel free to open an issue or pull request. You can also add me on Discord (thepat02) to discuss ideas or ask questions.
force-directed-graph-godot is a simple implementation of a Force-Directed Graph (or FDG for short) in the Godot Engine.
- 2D implementation of a Force-Directed Graph
- Flexible and easy to use Graph Nodes that can be extended and customized
- Real-time graph simulation in the editor (optional)
Reviews
Quick Information
force-directed-graph-godot is a simple implementation of a Force-Directed Graph (or FDG for short) in the Godot Engine.- 2D implementation of a Force-Directed Graph- Flexible and easy to use Graph Nodes that can be extended and customized- Real-time graph simulation in the editor (optional)