8 releases (4 breaking)

Uses new Rust 2021

new 0.5.0 Aug 15, 2022
0.4.2 Aug 7, 2022
0.4.0 Jul 30, 2022
0.3.1 Jul 28, 2022
0.1.0 May 4, 2022

#25 in Visualization

Download history 21/week @ 2022-05-01 5/week @ 2022-05-08 18/week @ 2022-05-15 5/week @ 2022-05-22 5/week @ 2022-05-29 8/week @ 2022-06-05 2/week @ 2022-06-12 2/week @ 2022-06-19 1/week @ 2022-07-03 3/week @ 2022-07-10 2/week @ 2022-07-17 96/week @ 2022-07-24 89/week @ 2022-07-31 55/week @ 2022-08-07

243 downloads per month
Used in 2 crates

MIT license

39KB
820 lines

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.

Name Version Docs License
fdg-sim Latest version Documentation GPL-3.0
fdg-macroquad Latest version Documentation GPL-3.0
fdg-img Latest version Documentation GPL-3.0

example screenshot

View Demo Online

Basic Example

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

Dependencies

~3.5MB
~86K SLoC