# fdg (Force Directed Graph)
A Force Directed Graph Framework for Rust. This manages your forces and event loop for a visualization of a graph. I've also created compatible visualizers for the simulation. This simulation sits on top of [`petgraph`](https://crates.io/crates/petgraph).
| `fdg-sim` | [](https://crates.io/crates/fdg-sim) | [](https://docs.rs/fdg-sim) | [](https://github.com/grantshandy/fdg/blob/main/fdg-sim/LICENSE) |
| `fdg-macroquad` | [](https://crates.io/crates/fdg-macroquad) | [](https://docs.rs/fdg-macroquad) | [](https://github.com/grantshandy/fdg/blob/main/fdg-macroquad/LICENSE) |
| `fdg-img` | [](https://crates.io/crates/fdg-img) | [](https://docs.rs/fdg-img) | [](https://github.com/grantshandy/fdg/blob/main/fdg-img/LICENSE) |

[View Demo Online](https://grantshandy.github.io/fdg)
## Basic Example
```rust
use fdg_sim::{ForceGraph, ForceGraphHelper, Simulation, SimulationParameters};
fn main() {
// initialize a graph
let mut graph: ForceGraph<(), ()> = ForceGraph::default();
let one = graph.add_force_node("one", ());
let two = graph.add_force_node("two", ());
let _three = graph.add_force_node("three", ());
graph.add_edge(one, two, ());
// create a simulation from the graph
let mut simulation = Simulation::from_graph(&graph, SimulationParameters::default());
// your event/render loop
for frame in 0..50 {
// update the nodes positions based on force algorithm
simulation.update(0.035);
// render (print) your nodes new locations.
println!("---- frame {frame} ----");
for node in simulation.get_graph().node_weights() {
println!("\"{}\" - {:?}", node.name, node.location);
}
println!("-----------------------")
}
}
```
## Related Crates
- [`fdg-macroquad`](https://crates.io/crates/fdg-macroquad) A visualizer that uses [`macroquad`](https://crates.io/crates/macroquad) for real-time rendering ([View Demo Online](https://grantshandy.github.io/fdg)).
- [`fdg-img`](https://crates.io/crates/fdg-img) An SVG visualizer for the simulation.