16 releases (8 breaking)

0.9.1 Dec 17, 2022
0.9.0 Oct 8, 2022
0.8.0 Sep 8, 2022
0.4.0 Jul 30, 2022

#144 in Visualization

Download history 25/week @ 2024-01-01 13/week @ 2024-01-08 4/week @ 2024-01-22 2/week @ 2024-01-29 26/week @ 2024-02-12 31/week @ 2024-02-19 52/week @ 2024-02-26 17/week @ 2024-03-04 36/week @ 2024-03-11 67/week @ 2024-03-18 43/week @ 2024-03-25

167 downloads per month
Used in 2 crates

MIT license

984 lines


A force-directed graph simulation for Rust.

Visit the project page for more information.



Name Version Docs License Description
fdg-sim Latest version Documentation MIT Runs the layout engine (simulation) and manages the position of nodes.
fdg-macroquad Latest version Documentation GPL-3.0 A demo visualizer that lets you interact with the graph in real time. (View Online)
fdg-img Latest version Documentation GPL-3.0 A simple SVG renderer for your graphs.
fdg-wasm NPM Package View Readme MIT A simple Webassembly wrapper of fdg-sim for use in Javascript.

Basic Example

use fdg_sim::{ForceGraph, ForceGraphHelper, Simulation, SimulationParameters};

fn main() {
    // initialize a graph
    let mut graph: ForceGraph<(), ()> = ForceGraph::default();

    // add nodes to it
    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

        // render (print) your nodes new locations.
        println!("---- frame {frame} ----");
        for node in simulation.get_graph().node_weights() {
            println!("\"{}\" - {:?}", node.name, node.location);

What are N, E, and Ty?

You may notice that structs and types like Simulation, ForceGraph, and Force have generic type parameters <N, E, Ty>.

  • N: The node weight (data stored in the Node's data).
  • E: The edge weight (data stored directly in the graph's edges).
  • Ty: The edge type, Directed or Undirected (set by default).

These type names from the petgraph documentation here. Because Ty is set by default, you won't have to mess with it most of the time.


~145K SLoC