Expand description

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 it. This simulation sits on top of petgraph.

NameVersionDocsLicense
fdg-simLatest versionDocumentationMIT
fdg-macroquadLatest versionDocumentationGPL-3.0
fdg-imgLatest versionDocumentationGPL-3.0
fdg-wasmNPM PackageView ReadmeMIT

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();

    // 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
        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!("-----------------------")
    }
}

Re-exports

pub use glam;
pub use petgraph;

Modules

Exports graphs into the DOT language for use with visualizers like Graphviz.

Change forces that define how your graph behaves.

gmlgml

Import and export graphs with Graph Modelling Language (GML).

jsonjson

Import and export graphs with the jsongraph specification.

Structs

A node on a ForceGraph.

A simulation for managing the main event loop and forces.

Parameters for the simulation.

Enums

Number of dimensions to run the simulation in.

Traits

Syntactic sugar to make adding Nodes to a ForceGraph easier.

Type Definitions

A helper type that creates a StableGraph with our custom Node as the weight.