4 releases

new 0.1.3 Apr 24, 2025
0.1.2 Feb 28, 2024
0.1.1 Oct 29, 2022
0.1.0 Oct 29, 2022

#48 in Visualization

Download history 964/week @ 2025-01-01 1385/week @ 2025-01-08 1589/week @ 2025-01-15 3059/week @ 2025-01-22 1611/week @ 2025-01-29 1029/week @ 2025-02-05 1154/week @ 2025-02-12 1337/week @ 2025-02-19 2570/week @ 2025-02-26 1509/week @ 2025-03-05 2301/week @ 2025-03-12 1717/week @ 2025-03-19 1090/week @ 2025-03-26 1881/week @ 2025-04-02 1905/week @ 2025-04-09 1935/week @ 2025-04-16

6,996 downloads per month
Used in 10 crates (8 directly)

MIT license

190KB
5K SLoC

Layout

Layout is a rust library and a stand alone utility that draws graphs. Layout can parse Graphviz dot files and render them.

Latest Version Docs Badge

Library Usage

Add the following to Cargo.toml:

layout-rs = "0.1.2" # or
layout-rs = { version = "0.1.2", features = ["log"] }

Load, parse and print the AST:

use layout::gv;

let contents = "digraph { a -> b [label=\"foo\"]; }";
let mut parser = gv::DotParser::new(&contents);

match parser.process() {
    Ok(g) => gv::dump_ast(&g),
    Err(err) => {
        parser.print_error();
        # #[cfg(feature = "log")]
        log::error!("Error: {}", err);
    }
}

The example above would print the program AST, or a readable error message, such as:

digraph {

node [fillcolor="purple"] A B;
node [fillcolor="orange"] Z;
node [fillcolor="green"] G; a = ;
                                ^
Error: Expected an identifier.

Command Line Usage

Build the crate and render some dot files with the command

cargo run --bin layout ./inputs/bk.dot -o output.svg

This section presents a few graphs that were rendered from dot files:

A simple graph.

A simple graph with multiple shapes and labels.

A graph with a few style properties.

A large graph that demonstrates the edge crossing elimination optimization.

Unicode, emoji and right-to-left languages:

Support for Records (nested structures):

Debug-mode rendering that helps to visualize the layout decisions:

Dependencies