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.
  • exec_dot: an ability to execute a cmd graphviz engine into different formats from a prepared string containing a dot graph.

Examples:

use dot_structures::*;
use dot_generator::*;
use graphviz_rust::{exec,parse, exec_dot};
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();

 }
 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![
           CommandArg::Format(format),
       ]).unwrap();

        let graph_svg = exec_dot(dot, vec![
           CommandArg::Format(format.clone()),
       ]).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

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.

Macros

Functions

Executes a given graph using a dot cmd client
Executes a given string representation of the graph using a dot cmd client
Parses a given string into a graph format that can be used afterwards or returning an string with an error description
Prints a given graph according to a given PrinterContext