Expand description
The library provides functionality for interacting with the graphviz
DOT language.
§Description:
This library contains 4 primary functions:
- parse: parses a string in the dot
notation
into a Graph. - print: serializes a Graph into a string given a DotPrinter.
- exec: executes the
dot
command line executable given a Graph. - exec_dot: executes the
dot
command line executable given a string in the dotnotation
.
§Examples:
use dot_generator::*;
use dot_structures::*;
use graphviz_rust::{
attributes::*,
cmd::{CommandArg, Format},
exec, exec_dot, parse,
printer::{DotPrinter, PrinterContext},
};
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"))
)
);
let mut g = graph!(strict di id!("id"));
assert_eq!(
"strict digraph id {\n\n}".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![Format::Svg.into()],
)
.unwrap();
}
fn output_exec_from_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 dot = g.print(&mut PrinterContext::default());
println!("{}", dot);
let format = Format::Svg;
let graph_svg = exec_dot(dot.clone(), vec![format.into()]).unwrap();
let graph_svg = exec_dot(dot, vec![format.clone().into()]).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
- Utilities for executing the
dot
command line executable. - Serialize a Graph into a string according to the
graphviz
DOT language.
Macros§
Functions§
- Executes the
dot
command line executable using the given Graph, PrinterContext and command line arguments. - Executes the
dot
command line executable using the given string dot notation, PrinterContext and command line arguments. - Parses a string into a Graph.
- Serializes a Graph into a string given a DotPrinter.