Expand description
§fdg-sim
A force-directed graph simulation for Rust.
Visit the project page for more information.
§Crates
Name | Version | Docs | License | Description |
---|---|---|---|---|
fdg-sim | Runs the layout engine (simulation) and manages the position of nodes. | |||
fdg-macroquad | A demo visualizer that lets you interact with the graph in real time. (View Online) | |||
fdg-img | A simple SVG renderer for your graphs. | |||
fdg-wasm | 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
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!("-----------------------")
}
}
§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 theNode
’sdata
).E
: The edge weight (data stored directly in the graph’s edges).Ty
: The edge type,Directed
orUndirected
(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.
Re-exports§
Modules§
- dot
- Exports graphs into the DOT language for use with visualizers like Graphviz.
- force
- Change forces that define how your graph behaves.
- gml
gml
- Import and export graphs with Graph Modelling Language (GML).
- json
json
- Import and export graphs with the jsongraph specification.
Structs§
- Node
- A node on a
ForceGraph
. - Simulation
- A simulation for managing the main event loop and forces.
- Simulation
Parameters - Parameters for the simulation.
Enums§
- Dimensions
- Number of dimensions to run the simulation in.
Traits§
- Force
Graph Helper - Syntactic sugar to make adding
Node
s to aForceGraph
easier.
Type Aliases§
- Force
Graph - A helper type that creates a
StableGraph
with our customNode
as the weight.