Simple API for creating GraphViz DOT language files.
TBD
The goal of this crate is to provide an ergonomic interface in a builder style to make creation of DOT files easy. This sacrifices performance and certainly memory usage is higher than a crate like dot.
``` rust use crate::writer::write_graph; use crate::graph::{Cluster, Graph, RootGraph}; use crate::node::Node; use crate::style::{ ClusterAttributes, ClusterStyles, Color, EdgeAttributes, FontName, GraphAttributes, LabelString, NodeAttributes, NodeStyles, Shape, Styled, }; use crate::writer::Indenter; use crate::Identifier; use std::str::FromStr;
let fonts = FontName::list(vec![ FontName::family("Helvetica").unwrap(), FontName::family("Arial").unwrap(), FontName::family("sans-serif").unwrap(), ]); let root = RootGraph::new(Identifier::fromstr("G").unwrap(), false, true) .setattributes(GraphAttributes::default().fontname(fonts.clone())) .setdefaultnodeattributes(NodeAttributes::default().fontname(fonts.clone())) .setdefaultedgeattributes(EdgeAttributes::default().fontname(fonts.clone())) .addsubgraph( Cluster::new(0i64.into()) .setattributes( ClusterAttributes::default() .label(LabelString::fromstr("process #1").unwrap()) .color(Color::named("lightgrey").unwrap().into()) .style(vec![ClusterStyles::Filled]), ) .setdefaultnodeattributes( NodeAttributes::default() .color(Color::named("white").unwrap().into()) .style(vec![NodeStyles::Filled]), ) .chain(vec![ Node::new(Identifier::fromstr("a0").unwrap()), Node::new(Identifier::fromstr("a1").unwrap()), Node::new(Identifier::fromstr("a2").unwrap()), Node::new(Identifier::fromstr("a3").unwrap()), ]), ) .addsubgraph( Cluster::new(1i64.into()) .setattributes( ClusterAttributes::default() .label(LabelString::fromstr("process #2").unwrap()) .color(Color::named("blue").unwrap().into()), ) .setdefaultnodeattributes( NodeAttributes::default().style(vec![NodeStyles::Filled]), ) .chain(vec![ Node::new(Identifier::fromstr("b0").unwrap()), Node::new(Identifier::fromstr("b1").unwrap()), Node::new(Identifier::fromstr("b2").unwrap()), Node::new(Identifier::fromstr("b3").unwrap()), ]), ) .addnode( Node::new(Identifier::fromstr("start").unwrap()) .setattributes(NodeAttributes::default().shape(Shape::mdiamond())), ) .addnode( Node::new(Identifier::fromstr("end").unwrap()) .setattributes(NodeAttributes::default().shape(Shape::msquare())), ) .addedgebetween( Identifier::fromstr("start").unwrap(), Identifier::fromstr("a0").unwrap(), ) .addedgebetween( Identifier::fromstr("start").unwrap(), Identifier::fromstr("b0").unwrap(), ) .addedgebetween( Identifier::fromstr("a1").unwrap(), Identifier::fromstr("b3").unwrap(), ) .addedgebetween( Identifier::fromstr("b2").unwrap(), Identifier::fromstr("a3").unwrap(), ) .addedgebetween( Identifier::fromstr("a3").unwrap(), Identifier::fromstr("a0").unwrap(), ) .addedgebetween( Identifier::fromstr("a3").unwrap(), Identifier::fromstr("end").unwrap(), ) .addedgebetween( Identifier::fromstr("b3").unwrap(), Identifier::from_str("end").unwrap(), );
write_graph(&root, &mut std::io::stdout()).unwrap(); ```
``` graphviz-(dot) digraph G { fontname = "Helvetica,Arial,sans-serif";
node [ fontname = "Helvetica,Arial,sans-serif"; ];
edge [ fontname = "Helvetica,Arial,sans-serif"; ];
subgraph cluster_0 { label = "process #1"; color = lightgrey; style = filled;
node [
color = white;
style = filled;
];
a0 -> a1;
a1 -> a2;
a2 -> a3;
} subgraph cluster_1 { label = "process #2"; color = blue;
node [
style = filled;
];
b0 -> b1;
b1 -> b2;
b2 -> b3;
}
start [ shape = Mdiamond; ]; end [ shape = Msquare; ];
start -> a0; start -> b0; a1 -> b3; b2 -> a3; a3 -> a0; a3 -> end; b3 -> end; } ```
Version 0.1.0