diff options
-rw-r--r-- | src/attributes/mod.rs | 14 | ||||
-rw-r--r-- | src/dot.rs | 5 | ||||
-rw-r--r-- | src/lib.rs | 44 | ||||
-rw-r--r-- | tests/dot.rs | 11 |
4 files changed, 60 insertions, 14 deletions
diff --git a/src/attributes/mod.rs b/src/attributes/mod.rs index d01d246..ea4427a 100644 --- a/src/attributes/mod.rs +++ b/src/attributes/mod.rs @@ -1,3 +1,5 @@ +// TODO: docs + mod arrow_type; mod cluster_mode; mod color; @@ -39,6 +41,7 @@ pub use crate::attributes::shape::Shape; pub use crate::attributes::spline_type::SplineType; pub use crate::attributes::splines::Splines; pub use crate::attributes::style::{EdgeStyle, GraphStyle, NodeStyle, Styles}; +#[doc(hidden)] pub use crate::attributes::AttributeText::{AttrStr, EscStr, HtmlStr, QuotedStr}; use crate::dot::DotString; use indexmap::map::IndexMap; @@ -441,7 +444,7 @@ pub trait GraphAttributes<'a> { /// Color used to fill the background, with a gradient, of a node or cluster assuming /// style=filled, or a filled arrowhead. /// TODO: example - /// [crate::GraphAttributes::dpi] + /// [crate::attributes::GraphAttributes::dpi] fn fill_color_with_iter<I>(&mut self, fill_colors: I) -> &mut Self where I: IntoIterator, @@ -573,7 +576,7 @@ pub trait GraphAttributes<'a> { /// Sets x and y margins of canvas, in inches. /// Both margins are set equal to the given value. - /// See [`crate::GraphAttributes::margin_point`] + /// See [`crate::attributes::GraphAttributes::margin_point`] fn margin(&mut self, margin: f32) -> &mut Self { self.margin_point(Point::new_2d(margin, margin)) } @@ -662,9 +665,6 @@ pub trait GraphAttributes<'a> { } // TODO: constrain to 0 - 360. Docs say min is 360 which should be max right? - /// When used on nodes: Angle, in degrees, to rotate polygon node shapes. - /// For any number of polygon sides, 0 degrees rotation results in a flat base. - /// When used on graphs: If "[lL]*", sets graph orientation to landscape. /// Used only if rotate is not defined. /// Default: 0.0 and minimum: 360.0 fn orientation(&mut self, orientation: f32) -> &mut Self { @@ -705,7 +705,7 @@ pub trait GraphAttributes<'a> { /// Specifies how much, in inches, to extend the drawing area around the minimal area needed /// to draw the graph. /// Both the x and y pad values are set equal to the given value. - /// See [`crate::GraphAttributes::pad_point`] + /// See [`crate::attributes::GraphAttributes::pad_point`] fn pad(&mut self, pad: f32) -> &mut Self { self.pad_point(Point::new_2d(pad, pad)) } @@ -794,7 +794,7 @@ pub trait GraphAttributes<'a> { /// If desired_min is true, and both both dimensions of the drawing /// are less than size, the drawing is scaled up uniformly until at /// least one dimension equals its dimension in size. - /// See [`crate::GraphAttributes::size_point`] + /// See [`crate::attributes::GraphAttributes::size_point`] fn size(&mut self, size: u32, desired_min: bool) -> &mut Self { self.size_point(Point { x: size as f32, @@ -1,3 +1,5 @@ +// TODO: docs + use crate::attributes::{ ArrowType, AttributeStatement, AttributeText, AttributeType, Attributes, Color, ColorList, Direction, EdgeStyle, GraphAttributeStatement, ImagePosition, ImageScale, @@ -786,9 +788,8 @@ pub trait NodeAttributes<'a> { } // TODO: constrain to 0 - 360. Docs say min is 360 which should be max right? - /// When used on nodes: Angle, in degrees, to rotate polygon node shapes. + /// Angle, in degrees, to rotate polygon node shapes. /// For any number of polygon sides, 0 degrees rotation results in a flat base. - /// When used on graphs: If "[lL]*", sets graph orientation to landscape. /// Used only if rotate is not defined. /// Default: 0.0 and minimum: 360.0 fn orientation(&mut self, orientation: f32) -> &mut Self { @@ -1,8 +1,50 @@ -//! Simple graphviz dot file format output. +#![doc(html_root_url = "https://docs.rs/dotavious/0.1.0")] +#![cfg_attr(docsrs, deny(broken_intra_doc_links))] + +//! Dotavious provides bindings to generate [DOT](https://graphviz.org/doc/info/lang.html) +//! code used by the Graphviz (http://graphviz.org/) for visualising graphs. +//! +//! Main features of the graphviz library include: +//! * Almost complete coverage of all Graphviz attributes and syntax. +//! +//! # Example +//! +//! ```rust +//! use dotavious::attributes::{AttributeText, GraphAttributeStatementBuilder, GraphAttributes}; +//! use dotavious::{ +//! Dot, Edge, EdgeAttributeStatementBuilder, EdgeAttributes, EdgeBuilder, Graph, +//! GraphBuilder, Node, NodeAttributeStatementBuilder, NodeAttributes, NodeBuilder, +//! }; +//! use std::io; +//! use std::io::Read; +//! +//! let g = GraphBuilder::new_directed(Some("single_edge".to_string())) +//! .add_node(Node::new("N0".to_string())) +//! .add_node(Node::new("N1".to_string())) +//! .add_edge(Edge::new("N0".to_string(), "N1".to_string())) +//! .build(); +//! +//! let mut writer= Vec::new(); +//! let dot = Dot { graph: g }; +//! dot.render(&mut writer).unwrap(); +//! +//! // output to graphviz DOT formatted string +//! let mut dot_string = String::new(); +//! Read::read_to_string(&mut &*writer, &mut dot_string).unwrap(); +//! println!("{}", dot_string); +//! +//! // digraph graph_attributes { +//! // N0; +//! // N1; +//! // N0 -> N1; +//! // } +//! ``` + pub mod attributes; pub mod dot; +#[doc(hidden)] pub use crate::dot::{ Dot, DotString, Edge, EdgeAttributeStatementBuilder, EdgeAttributes, EdgeBuilder, Graph, GraphBuilder, Node, NodeAttributeStatementBuilder, NodeAttributes, diff --git a/tests/dot.rs b/tests/dot.rs index fdd9545..fb97175 100644 --- a/tests/dot.rs +++ b/tests/dot.rs @@ -1,4 +1,4 @@ -use dotavious::attributes::{AttributeText, CompassPoint, GraphAttributeStatementBuilder, GraphAttributes, NodeStyle, PortPosition, RankDir, Shape, EdgeStyle}; +use dotavious::attributes::{AttributeText, CompassPoint, GraphAttributeStatementBuilder, GraphAttributes, NodeStyle, PortPosition, RankDir, Shape, EdgeStyle, Color}; use dotavious::{ Dot, Edge, EdgeAttributeStatementBuilder, EdgeAttributes, EdgeBuilder, Graph, GraphBuilder, Node, NodeAttributeStatementBuilder, NodeAttributes, NodeBuilder, @@ -7,10 +7,11 @@ use std::io; use std::io::Read; fn test_input(g: Graph) -> io::Result<String> { - let mut writer = Vec::new(); + let mut writer= Vec::new(); let dot = Dot { graph: g }; dot.render(&mut writer).unwrap(); + let mut s = String::new(); Read::read_to_string(&mut &*writer, &mut s)?; Ok(s) @@ -285,7 +286,9 @@ fn graph_attributes() { let node_attributes = NodeAttributeStatementBuilder::new() .style(NodeStyle::Filled) .build(); - let edge_attributes = EdgeAttributeStatementBuilder::new().min_len(1).build(); + let edge_attributes = EdgeAttributeStatementBuilder::new() + .color(Color::Named("red")) + .build(); let g = GraphBuilder::new_directed(Some("graph_attributes".to_string())) .add_graph_attributes(graph_attributes) @@ -300,7 +303,7 @@ fn graph_attributes() { r#"digraph graph_attributes { graph [rankdir=LR]; node [style=filled]; - edge [minlen=1]; + edge [color="red"]; } "# ); |