layout/
lib.rs

1/*!
2This crate provides a library for parsing and rendering GraphViz files.  It
3supports many of the GraphViz features, like records, edge styles and
4left-to-right graphs, but lacks other features, such as nested graphs or
5embedded html. This crate also provides an API for constructing and rendering
6graphs.
7
8For more specific details on the API for regular expressions, see the
9documentation for the specific sub modules.
10
11The project also comes with a command line utility for rendering .DOT files to
12.svg.
13
14# Parser example: parse a dot file
15
16This crate provides an API for parsing DOT files.
17
18Add the following to `Cargo.toml`:
19
20```toml
21layout-rs = "0.1.1" # or
22layout-rs = { version = "0.1.1", features = ["log"] }
23```
24
25Load, parse and print the AST:
26
27```rust
28use layout::gv;
29
30let contents = "digraph { a -> b [label=\"foo\"]; }";
31let mut parser = gv::DotParser::new(&contents);
32
33match parser.process() {
34    Ok(g) => gv::dump_ast(&g),
35    Err(err) => {
36        parser.print_error();
37        # #[cfg(feature = "log")]
38        log::error!("Error: {}", err);
39    }
40}
41```
42
43The example above would print the program AST, or a readable error message,
44such as:
45
46```txt
47digraph {
48
49node [fillcolor="purple"] A B;
50node [fillcolor="orange"] Z;
51node [fillcolor="green"] G; a = ;
52                                ^
53Error: Expected an identifier.
54```
55
56
57# Graph Builder example: create a new graph
58
59This crate provides an API creating and rendering graphs. For example, this
60code builds a graph with two nodes that are connected with an edge.
61
62```rust
63fn simple_graph() {
64    use layout::backends::svg::SVGWriter;
65    use layout::core::base::Orientation;
66    use layout::core::geometry::Point;
67    use layout::core::style::*;
68    use layout::core::utils::save_to_file;
69    use layout::std_shapes::shapes::*;
70    use layout::topo::layout::VisualGraph;
71    use layout::topo::placer::Placer;
72    use std::fs;
73
74    // Create a new graph:
75    let mut vg = VisualGraph::new(Orientation::LeftToRight);
76
77    // Define the node styles:
78    let sp0 = ShapeKind::new_box("one");
79    let sp1 = ShapeKind::new_box("two");
80    let look0 = StyleAttr::simple();
81    let look1 = StyleAttr::simple();
82    let sz = Point::new(100., 100.);
83    // Create the nodes:
84    let node0 = Element::create(sp0, look0, Orientation::LeftToRight, sz);
85    let node1 = Element::create(sp1, look1, Orientation::LeftToRight, sz);
86
87    // Add the nodes to the graph, and save a handle to each node.
88    let handle0 = vg.add_node(node0);
89    let handle1 = vg.add_node(node1);
90
91    // Add an edge between the nodes.
92    let arrow = Arrow::simple("123");
93    vg.add_edge(arrow, handle0, handle1);
94
95    // Render the nodes to some rendering backend.
96    let mut svg = SVGWriter::new();
97    vg.do_it(false, false, false, &mut svg);
98
99    // Save the output.
100    let _ = save_to_file("/tmp/graph.svg", &svg.finalize());
101}
102```
103
104*/
105
106#![warn(missing_debug_implementations)]
107
108pub mod adt;
109pub mod backends;
110pub mod core;
111pub mod gv;
112pub mod std_shapes;
113pub mod topo;