Crate tabbycat

Source
Expand description

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

This crate implements a subset of the attributes list of the dot language. You can 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;};}

Modules§

attributes
This module implements a subset of dot language attributes. These functions will generate some predefined AttrPairs that be used together with the add_attrpair function of Edge and the add_pair function of AttrList. Notice that only an incomplete subset is implemented due to the limitations of the function prototype and type system. To add other attributes, you can use an unsafe way to construct an identity pair.

Structs§

AttrList
The list of attributes
Edge
An edge in the dot language.
EdgeBody
A body part of edge
Graph
Graph in the dot language. You can construct it with the GraphBuilder.
GraphBuilder
Builder for Graph.
StmtList
The list of statements, including:

Enums§

AttrType
The types of global attributes
Compass
Directions
EdgeNode
A node of the edge
EdgeOp
The tag of the edge operation
GraphType
The types of graphs
Identity
An identity in the dot language. You are recommended to construct it in one of the following ways:
Port
The port suffix.
Stmt
A single line of statement. You should not construct it directly in most cases. We still expose this type because we only implement a subset of dot language so you may need to write special statements on your own.
SubGraph
A subgraph in the dot language

Type Aliases§

AttrPair