10 unstable releases (3 breaking)

0.4.2 May 31, 2023
0.4.1 Sep 9, 2022
0.3.0 Sep 7, 2022
0.2.0 Sep 6, 2022
0.1.1 Jul 30, 2022

#97 in Visualization

GPL-3.0 license

110KB
1.5K SLoC

fdg-img

A simple SVG renderer for fdg-sim.

Latest version Documentation GPL-3.0

Visit the project page for more information.

Basic Example

use std::fs;

use fdg_sim::{ForceGraph, ForceGraphHelper, force};

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

    // create a circle
    let nodes = 10;

    graph.add_force_node("0", ());
    for x in 1..nodes {
        graph.add_force_node(x.to_string(), ());
        graph.add_edge(x.into(), (x - 1).into(), ());
    }
    graph.add_edge(0.into(), (nodes - 1).into(), ());

    // generate svg text for your graph
    let svg = fdg_img::gen_image(graph, None).unwrap();

    // save the svg on disk (or send it to an svg renderer)
    fs::write("ring.svg", svg.as_bytes()).unwrap();
}

screenshot screenshot

Webassembly API

This library can be used in Javascript though a WASM interface. I'll be setting up a demo for it soon. For now you can see how to use it in the web example.

Dependencies

~22MB
~272K SLoC