Crate graphviz_rust
source · [−]Expand description
The library allows to interact with graphviz
format.
Description:
Essentially, it starts from 3 base methods:
- parse: a source of a dot file in the dot
notation
. The output format is a Graph. - print: Graph and DotPrinter provides an ability to transform a graph into string
following the
notation
- exec: an ability to
execute
a cmd graphviz engine into different formats and etc.
Examples:
use dot_structures::*;
use dot_generator::*;
use graphviz_rust::{exec, parse};
use graphviz_rust::cmd::{CommandArg, Format};
use graphviz_rust::printer::{PrinterContext,DotPrinter};
use graphviz_rust::attributes::*;
fn parse_test() {
let g: Graph = parse(r#"
strict digraph t {
aa[color=green]
subgraph v {
aa[shape=square]
subgraph vv{a2 -> b2}
aaa[color=red]
aaa -> bbb
}
aa -> be -> subgraph v { d -> aaa}
aa -> aaa -> v
}
"#).unwrap();
assert_eq!(
g,
graph!(strict di id!("t");
node!("aa";attr!("color","green")),
subgraph!("v";
node!("aa"; attr!("shape","square")),
subgraph!("vv"; edge!(node_id!("a2") => node_id!("b2"))),
node!("aaa";attr!("color","red")),
edge!(node_id!("aaa") => node_id!("bbb"))
),
edge!(node_id!("aa") => node_id!("be") => subgraph!("v"; edge!(node_id!("d") => node_id!("aaa")))),
edge!(node_id!("aa") => node_id!("aaa") => node_id!("v"))
)
)
}
fn print_test() {
let mut g = graph!(strict di id!("id"));
assert_eq!("strict digraph id {}".to_string(), g.print(&mut PrinterContext::default()));
}
fn output_test(){
let mut g = graph!(id!("id");
node!("nod"),
subgraph!("sb";
edge!(node_id!("a") => subgraph!(;
node!("n";
NodeAttributes::color(color_name::black), NodeAttributes::shape(shape::egg))
))
),
edge!(node_id!("a1") => node_id!(esc "a2"))
);
let graph_svg = exec(g, &mut PrinterContext::default(), vec![
CommandArg::Format(Format::Svg),
]).unwrap();
}
Re-exports
pub extern crate dot_generator;
pub extern crate dot_structures;
pub extern crate into_attr;
pub extern crate into_attr_derive;
Modules
graphviz
attributes
It allows to execute cmd engine passing extra parameters
It allows to transform a graph into a string carrying dot info according
to the notation.