summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/attributes/port_position.rs10
-rw-r--r--src/attributes/rectangle.rs17
-rw-r--r--src/dot.rs27
-rw-r--r--src/lib.rs1
-rw-r--r--tests/dot.rs8
5 files changed, 32 insertions, 31 deletions
diff --git a/src/attributes/port_position.rs b/src/attributes/port_position.rs
index 8900219..1948b8e 100644
--- a/src/attributes/port_position.rs
+++ b/src/attributes/port_position.rs
@@ -37,7 +37,7 @@ impl<'a> DotString<'a> for PortPosition {
#[cfg(test)]
mod test {
- use crate::attributes::{PortPosition, CompassPoint};
+ use crate::attributes::{CompassPoint, PortPosition};
use crate::DotString;
#[test]
@@ -47,14 +47,16 @@ mod test {
PortPosition::Port {
port_name: "port_0".to_string(),
compass_point: None
- }.dot_string()
+ }
+ .dot_string()
);
assert_eq!(
"port_0:ne",
PortPosition::Port {
port_name: "port_0".to_string(),
compass_point: Some(CompassPoint::NE)
- }.dot_string()
+ }
+ .dot_string()
);
}
@@ -62,4 +64,4 @@ mod test {
fn compass_dot_string() {
assert_eq!("ne", PortPosition::Compass(CompassPoint::NE).dot_string());
}
-} \ No newline at end of file
+}
diff --git a/src/attributes/rectangle.rs b/src/attributes/rectangle.rs
index 9b36ee2..acf9ae1 100644
--- a/src/attributes/rectangle.rs
+++ b/src/attributes/rectangle.rs
@@ -19,15 +19,18 @@ impl<'a> DotString<'a> for Rectangle {
#[cfg(test)]
mod test {
- use crate::attributes::{Rectangle, Point};
+ use crate::attributes::{Point, Rectangle};
use crate::DotString;
#[test]
fn dot_string() {
- assert_eq!("0.0,0.0,1.0,1.0", Rectangle {
- lower_left: Point::new_2d(0.0, 0.0),
- upper_right: Point::new_2d(1.0, 1.0)
- }.dot_string());
+ assert_eq!(
+ "0.0,0.0,1.0,1.0",
+ Rectangle {
+ lower_left: Point::new_2d(0.0, 0.0),
+ upper_right: Point::new_2d(1.0, 1.0)
+ }
+ .dot_string()
+ );
}
-
-} \ No newline at end of file
+}
diff --git a/src/dot.rs b/src/dot.rs
index 634f24b..9b2d825 100644
--- a/src/dot.rs
+++ b/src/dot.rs
@@ -9,9 +9,9 @@ use crate::attributes::{
use indexmap::IndexMap;
use std::borrow::Cow;
use std::collections::HashMap;
+use std::fmt::{Debug, Display, Formatter};
use std::io;
use std::io::prelude::*;
-use std::fmt::{Display, Formatter, Debug};
static INDENT: &str = " ";
@@ -25,34 +25,32 @@ pub struct Dot<'a> {
}
impl<'a> Dot<'a> {
- /// Renders directed graph `g` into the writer `w` in DOT syntax.
+ /// Renders graph into the writer `w` in DOT syntax.
/// (Simple wrapper around `render_opts` that passes a default set of options.)
- //pub fn render<W>(self, g: Graph, w: &mut W) -> io::Result<()>
pub fn render<W>(self, w: &mut W) -> io::Result<()>
where
W: Write,
{
- // TODO: use default_options?
self.render_opts(w, &[])
}
- /// Renders directed graph `g` into the writer `w` in DOT syntax.
+ /// Renders graph into the writer `w` in DOT syntax.
/// (Main entry point for the library.)
- // pub fn render_opts<W>(self, graph: Graph, w: &mut W, options: &[RenderOption]) -> io::Result<()>
pub fn render_opts<W>(self, w: &mut W, options: &[RenderOption]) -> io::Result<()>
where
W: Write,
{
- self.internal_render(&self.graph, w)
+ self.internal_render(&self.graph, w, options)
}
fn internal_render<W>(
&self,
graph: &Graph,
- w: &mut W
+ w: &mut W,
+ options: &[RenderOption],
) -> io::Result<()>
- where
- W: Write,
+ where
+ W: Write,
{
if let Some(comment) = &graph.comment {
// TODO: split comment into lines of 80 or so characters
@@ -125,8 +123,8 @@ impl<'a> Dot<'a> {
impl<'a> Display for Dot<'a> {
fn fmt(&self, f: &mut Formatter) -> std::fmt::Result {
- let mut writer= Vec::new();
- self.internal_render(&self.graph, &mut writer).unwrap();
+ let mut writer = Vec::new();
+ self.internal_render(&self.graph, &mut writer, &[]).unwrap();
let mut s = String::new();
Read::read_to_string(&mut &*writer, &mut s).unwrap();
@@ -149,11 +147,6 @@ pub enum RenderOption {
EdgeIndexLabel,
}
-/// Returns vec holding all the default render options.
-pub fn default_options() -> Vec<RenderOption> {
- vec![]
-}
-
pub struct Graph<'a> {
pub id: Option<String>,
diff --git a/src/lib.rs b/src/lib.rs
index 65d98c2..575e4cf 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -42,7 +42,6 @@
//! }
//! ```
-
pub mod attributes;
pub mod dot;
diff --git a/tests/dot.rs b/tests/dot.rs
index 1ab467d..efafac8 100644
--- a/tests/dot.rs
+++ b/tests/dot.rs
@@ -1,4 +1,7 @@
-use dotavious::attributes::{AttributeText, CompassPoint, GraphAttributeStatementBuilder, GraphAttributes, NodeStyle, PortPosition, RankDir, Shape, EdgeStyle, Color};
+use dotavious::attributes::{
+ AttributeText, Color, CompassPoint, EdgeStyle, GraphAttributeStatementBuilder,
+ GraphAttributes, NodeStyle, PortPosition, RankDir, Shape,
+};
use dotavious::{
Dot, Edge, EdgeAttributeStatementBuilder, EdgeAttributes, EdgeBuilder, Graph,
GraphBuilder, Node, NodeAttributeStatementBuilder, NodeAttributes, NodeBuilder,
@@ -7,7 +10,7 @@ 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();
@@ -33,6 +36,7 @@ fn empty_digraph_without_id() {
fn display() {
let g = GraphBuilder::new_directed(None).build();
let dot = Dot { graph: g };
+
assert_eq!(
format!("{}", dot),
r#"digraph {