#dot #graphviz #visual #render #graphics

tabbycat

A rust crate for generating graph scripts with dot language

4 releases

0.1.3 Apr 23, 2022
0.1.2 Dec 29, 2020
0.1.1 Jun 27, 2020
0.1.0 Jun 27, 2020

#205 in Visualization

Download history 2030/week @ 2024-07-22 1730/week @ 2024-07-29 1503/week @ 2024-08-05 2286/week @ 2024-08-12 1587/week @ 2024-08-19 1631/week @ 2024-08-26 2030/week @ 2024-09-02 1825/week @ 2024-09-09 1111/week @ 2024-09-16 1716/week @ 2024-09-23 1027/week @ 2024-09-30 749/week @ 2024-10-07 920/week @ 2024-10-14 789/week @ 2024-10-21 1226/week @ 2024-10-28 660/week @ 2024-11-04

3,607 downloads per month
Used in 13 crates (6 directly)

MIT license

100KB
3K SLoC

tabbycat

About

This crate is used to generate dot graphs with types defined in rust. The whole crate is implemented following the dot language specification listed at graphviz's website.

Attributes

There is an optional feature attributes which implemented a subset of the attributes list of the dot language. By enabling this feature, you will be able to write something like:

use tabbycat::attributes::*;
use tabbycat::AttrList;
let attrlist =  AttrList::new()
    .add_pair(fontsize(12.0))
    .add_pair(label("test"))
    .new_bracket()
    .add_pair(fillcolor(Color::Blue))
    .add_pair(arrowhead(ArrowShape::Orinv));
assert_eq!("[fontsize=12;label=\"test\";][fillcolor=blue;arrowhead=orinv;]", attrlist.to_string())

Example

use tabbycat::attributes::*;
use tabbycat::{AttrList, GraphBuilder, GraphType, Identity, StmtList, Edge, SubGraph};
let graph = GraphBuilder::default()
    .graph_type(GraphType::DiGraph)
    .strict(false)
    .id(Identity::id("G").unwrap())
    .stmts(StmtList::new()
        .add_node(Identity::id("A").unwrap(), None, Some(AttrList::new().add_pair(color(Color::Red))))
        .add_edge(Edge::head_node(Identity::id("B").unwrap(), None)
            .arrow_to_node(Identity::id("C").unwrap(), None)
            .add_attrpair(arrowhead(ArrowShape::Diamond)))
        .add_subgraph(SubGraph::subgraph(Some(Identity::id("D").unwrap()),
            StmtList::new()
                .add_edge(Edge::head_node(Identity::id("E").unwrap(), None)
                    .arrow_to_node(Identity::id("F").unwrap(), None)))))
    .build()
    .unwrap();
println!("{}", graph);

This will generate an output like:

digraph G{A[color=red;];B->C[arrowhead=diamond;];subgraph D{E->F;};}

Dependencies

~5.5MB
~104K SLoC