dot_graph/
lib.rs

1// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
2// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
3// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
4// option. This file may not be copied, modified, or distributed
5// except according to those terms.
6
7//! A library for generating Graphviz DOT language files.
8//! 
9//! The very basic three parts of a DOT file and in this library is `Graph`,
10//! `Node` and `Edge`. `Graph` is the entry point of the library. You could
11//! generate an empty graph .dot file by simply use:
12//! 
13//! ```rust
14//! use dot_graph::{Graph, Kind};
15//! 
16//! let graph = Graph::new("empty_graph", Kind::Digraph);
17//! 
18//! let dot_string = graph.to_dot_string().unwrap();
19//! 
20//! assert_eq!(dot_string,
21//!    r#"digraph empty_graph {
22//! }
23//!"#);
24//! ```
25//!
26//! In order to add some basic nodes and edges:
27//! 
28//! ```rust
29//! use dot_graph::{Graph, Kind, Node, Edge};
30//! 
31//! let mut graph = Graph::new("single_edge", Kind::Digraph);
32//! 
33//! graph.add_node(Node::new("N0"));
34//! graph.add_node(Node::new("N1"));
35//! graph.add_edge(Edge::new("N0", "N1", "E"));
36//! 
37//! let dot_string = graph.to_dot_string().unwrap();
38//! 
39//! assert_eq!(dot_string,
40//! r#"digraph single_edge {
41//!     "N0"[label="N0"];
42//!     "N1"[label="N1"];
43//!     "N0" -> "N1"[label="E"];
44//! }
45//! "#);
46//! ```
47//! 
48//! If you want add some more attributes, like style, arrow, color,
49//! you could call these methods in a chain, like:
50//! 
51//! ```rust
52//! use dot_graph::{Graph, Kind, Node, Edge, Style};
53//! 
54//! let mut graph = Graph::new("single_edge", Kind::Digraph);
55//! 
56//! graph.add_node(Node::new("N0"));
57//! graph.add_node(Node::new("N1"));
58//! graph.add_edge(Edge::new("N0", "N1", "E").style(Style::Bold).color(Some("red")));
59//! 
60//! assert_eq!(graph.to_dot_string().unwrap(),
61//! r#"digraph single_edge {
62//!     "N0"[label="N0"];
63//!     "N1"[label="N1"];
64//!     "N0" -> "N1"[label="E"][style="bold"][color="red"];
65//! }
66//! "#);
67//! ```
68//! 
69//! After version 0.2.1, dot_graph support subgraph generation, for example:
70//! 
71//! ```rust
72//! #[test]
73//! fn test_subgraph() {
74//!     let mut graph = Graph::new("di", Kind::Digraph);
75//!     let mut c1 = Subgraph::new("cluster_0").label("");
76//!     c1.add_node(Node::new("N0"));
77//!     c1.add_node(Node::new("N1"));
78//!     let mut c2 = Subgraph::new("cluster_1").label("");
79//!     c2.add_node(Node::new("N2"));
80//!     c2.add_node(Node::new("N3"));
81//!     graph.add_subgraph(c1);
82//!     graph.add_subgraph(c2);
83//!     graph.add_edge(Edge::new("N0", "N1", ""));
84//!     graph.add_edge(Edge::new("N0", "N2", ""));
85//!     graph.add_edge(Edge::new("N1", "N3", ""));
86//!     graph.add_edge(Edge::new("N2", "N3", ""));
87//!     
88//! 
89//!     assert_eq!(graph.to_dot_string().unwrap(),
90//! r#"digraph di {
91//! subgraph cluster_0 {
92//!     label="";
93//!     "N0"[label="N0"];
94//!     "N1"[label="N1"];
95//! }
96//! subgraph cluster_1 {
97//!     label="";
98//!     "N2"[label="N2"];
99//!     "N3"[label="N3"];
100//! }
101//! "N0" -> "N1"[label=""];
102//! "N0" -> "N2"[label=""];
103//! "N1" -> "N3"[label=""];
104//! "N2" -> "N3"[label=""];
105//! }
106//! "#);
107//! }
108//! ```
109//! 
110//! For more examples, please check the tests.
111//! 
112//! The library is under active development, we'll include more dot attributes
113//! in the future.
114//! 
115//! # References
116//!
117//! * [Graphviz](http://graphviz.org/)
118//!
119//! * [DOT language](http://graphviz.org/doc/info/lang.html)
120
121mod style;
122mod arrow;
123mod node;
124mod edge;
125mod graph;
126mod utils;
127mod subgraph;
128
129pub use style::Style;
130pub use arrow::{Arrow, ArrowShape, Side, Fill};
131pub use node::{Node};
132pub use edge::{Edge};
133pub use graph::{Graph, Kind};
134pub use subgraph::Subgraph;
135