Expand description

fdg-img

A simple SVG renderer for fdg-sim.

Latest version Documentation GPL-3.0

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, &force::handy(45.0, 0.975, true, true), None).unwrap();

    // save the svg on disk
    fs::write("ring.svg", svg.as_bytes()).unwrap();
}

screenshot

Structs

Parameters for drawing the SVG image.

Functions

Generate an image from a graph and a force.