summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/lib.rs96
1 files changed, 71 insertions, 25 deletions
diff --git a/src/lib.rs b/src/lib.rs
index 91c8d67..b5c4c3e 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -3,7 +3,7 @@
use AttributeText::*;
use indexmap::IndexMap;
use std;
-use std::borrow::Cow;
+use std::borrow::{Cow};
use std::collections::HashMap;
use std::io;
use std::io::prelude::*;
@@ -318,7 +318,7 @@ impl<'a> Graph<'a> {
nodes: Vec<Node<'a>>,
edges: Vec<Edge<'a>>,
) -> Self {
- Graph {
+ Self {
id,
is_directed,
strict,
@@ -722,7 +722,6 @@ pub trait GraphAttributes<'a> {
self.add_attribute("lwidth", AttributeText::attr(lwidth.to_string()))
}
- // TODO: point
/// For graphs, this sets x and y margins of canvas, in inches.
/// If the margin is a single double, both margins are set equal to the given value.
/// Note that the margin is not part of the drawing but just empty space left around the drawing.
@@ -736,6 +735,11 @@ pub trait GraphAttributes<'a> {
self
}
+ fn margin_point(&mut self, margin: Point) -> &mut Self {
+ Attributes::margin_point(self.get_attributes_mut(), margin);
+ self
+ }
+
/// Multiplicative scale factor used to alter the MinQuit (default = 8) and MaxIter (default = 24) parameters used during crossing minimization.
/// These correspond to the number of tries without improvement before quitting and the maximum number of iterations in each pass.
fn mclimit(&mut self, mclimit: f32) -> &mut Self {
@@ -868,18 +872,18 @@ pub trait GraphAttributes<'a> {
}
/// Sets direction of graph layout.
- /// For example, if rankdir="LR", and barring cycles, an edge T -> H; will go from left to right.
+ /// For example, if rankdir="LR", and barring cycles, an edge T -> H; will go from left to right.
/// By default, graphs are laid out from top to bottom.
- /// This attribute also has a side-effect in determining how record nodes are interpreted.
+ /// This attribute also has a side-effect in determining how record nodes are interpreted.
/// See record shapes.
fn rank_dir(&mut self, rank_dir: RankDir) -> &mut Self {
self.add_attribute("rankdir", AttributeText::attr(rank_dir.as_slice()))
}
/// sets the desired rank separation, in inches.
- /// This is the minimum vertical distance between the bottom of the nodes in one rank
- /// and the tops of nodes in the next. If the value contains equally,
- /// the centers of all ranks are spaced equally apart.
+ /// This is the minimum vertical distance between the bottom of the nodes in one rank
+ /// and the tops of nodes in the next. If the value contains equally,
+ /// the centers of all ranks are spaced equally apart.
/// Note that both settings are possible, e.g., ranksep="1.2 equally".
fn rank_sep(&mut self, rank_sep: String) -> &mut Self {
self.add_attribute("ranksep", AttributeText::attr(rank_sep))
@@ -1015,21 +1019,20 @@ pub trait GraphAttributes<'a> {
}
impl<'a> GraphAttributes<'a> for GraphAttributeStatementBuilder<'a> {
-
- fn get_attributes_mut(&mut self) -> &mut IndexMap<String, AttributeText<'a>> {
- &mut self.attributes
- }
-
fn add_attribute<S: Into<String>>(&mut self, key: S, value: AttributeText<'a>) -> &mut Self {
self.attributes.insert(key.into(), value);
self
}
- /// Add multiple attribures to the node.
+ /// Add multiple attributes to the node.
fn add_attributes(&'a mut self, attributes: HashMap<String, AttributeText<'a>>) -> &mut Self {
self.attributes.extend(attributes);
self
}
+
+ fn get_attributes_mut(&mut self) -> &mut IndexMap<String, AttributeText<'a>> {
+ &mut self.attributes
+ }
}
// I'm not a huge fan of needing this builder but having a hard time getting around &mut without it
@@ -1100,6 +1103,36 @@ impl ClusterMode {
}
}
+pub enum Ratio {
+ Aspect(f32),
+ Fill,
+ Compress,
+ Expand,
+ Auto,
+}
+
+impl Ratio {
+
+ // TODO: should this return AttributeText?
+ // that way we dont have to quote aspect?
+ pub fn to_string(&self) -> String {
+ match self {
+ Ratio::Aspect(aspect) => aspect.to_string(),
+ Ratio::Fill => String::from("fill"),
+ Ratio::Compress => String::from("compress"),
+ Ratio::Expand => String::from("expand"),
+ Ratio::Auto => String::from("auto"),
+ }
+ }
+}
+
+trait DotString {
+
+ fn to_text(&self) -> AttributeText;
+
+ fn to_string(&self) -> String;
+}
+
pub enum LabelJustification {
Left,
Right,
@@ -1605,13 +1638,17 @@ trait NodeAttributes<'a> {
self
}
- // color / color list
/// Basic drawing color for graphics, not text. For the latter, use the fontcolor attribute.
fn color(&mut self, color: Color) -> &mut Self {
Attributes::color(self.get_attributes_mut(), color);
self
}
+ fn color_with_colorlist(&mut self, color: ColorList) -> &mut Self {
+ Attributes::color_with_colorlist(self.get_attributes_mut(), color);
+ self
+ }
+
/// This attribute specifies a color scheme namespace: the context for interpreting color names.
/// In particular, if a color value has form "xxx" or "//xxx", then the color xxx will be evaluated
/// according to the current color scheme. If no color scheme is set, the standard X11 naming is used.
@@ -1667,7 +1704,6 @@ trait NodeAttributes<'a> {
self.add_attribute("fixedsize", AttributeText::quotted(fixed_size.to_string()))
}
- // TODO: color list
/// Color used for text.
fn font_color(&mut self, font_color: Color) -> &mut Self {
Attributes::font_color(self.get_attributes_mut(), font_color);
@@ -1706,12 +1742,6 @@ trait NodeAttributes<'a> {
self.add_attribute("height", AttributeText::attr(height.to_string()))
}
- // TODO: delete and just use url?
- /// Synonym for URL.
- fn href(&mut self, href: String) -> &mut Self {
- self.add_attribute("href", AttributeText::escaped(href))
- }
-
/// Gives the name of a file containing an image to be displayed inside a node.
/// The image file must be in one of the recognized formats,
/// typically JPEG, PNG, GIF, BMP, SVG, or Postscript, and be able to be converted
@@ -1759,7 +1789,6 @@ trait NodeAttributes<'a> {
self
}
- // TODO: point
/// For nodes, this attribute specifies space left around the node’s label.
/// If the margin is a single double, both margins are set equal to the given value.
/// Note that the margin is not part of the drawing but just empty space left around the drawing.
@@ -1771,6 +1800,11 @@ trait NodeAttributes<'a> {
self
}
+ fn margin_point(&mut self, margin: Point) -> &mut Self {
+ Attributes::margin_point(self.get_attributes_mut(), margin);
+ self
+ }
+
/// By default, the justification of multi-line labels is done within the largest context that makes sense.
/// Thus, in the label of a polygonal node, a left-justified line will align with the left side of the node (shifted by the prescribed margin).
/// In record nodes, left-justified line will line up with the left side of the enclosing column of fields.
@@ -2047,13 +2081,17 @@ trait EdgeAttributes<'a> {
self
}
- // color / color list
/// Basic drawing color for graphics, not text. For the latter, use the fontcolor attribute.
fn color(&mut self, color: Color) -> &mut Self {
Attributes::color(self.get_attributes_mut(), color);
self
}
+ fn color_with_colorlist(&mut self, color: ColorList) -> &mut Self {
+ Attributes::color_with_colorlist(self.get_attributes_mut(), color);
+ self
+ }
+
/// This attribute specifies a color scheme namespace: the context for interpreting color names.
/// In particular, if a color value has form "xxx" or "//xxx", then the color xxx will be evaluated
/// according to the current color scheme. If no color scheme is set, the standard X11 naming is used.
@@ -2846,6 +2884,10 @@ impl Attributes {
Self::add_attribute(attributes,"color", AttributeText::quotted(color.to_dot_string()))
}
+ fn color_with_colorlist<'a>(attributes: &mut IndexMap<String, AttributeText>, color: ColorList<'a>) {
+ Self::add_attribute(attributes,"color", AttributeText::quotted(color.to_dot_string()))
+ }
+
fn color_scheme(attributes: &mut IndexMap<String, AttributeText>, color_scheme: String) {
Self::add_attribute(attributes, "colorscheme", AttributeText::quotted(color_scheme))
}
@@ -2914,7 +2956,11 @@ impl Attributes {
fn margin(attributes: &mut IndexMap<String, AttributeText>, margin: f32) {
Self::add_attribute(attributes, "margin", AttributeText::attr(margin.to_string()))
}
-
+
+ fn margin_point(attributes: &mut IndexMap<String, AttributeText>, margin: Point) {
+ Self::add_attribute(attributes, "margin", AttributeText::attr(margin.to_formatted_string()))
+ }
+
fn no_justify(attributes: &mut IndexMap<String, AttributeText>, no_justify: bool) {
Self::add_attribute(attributes, "nojustify", AttributeText::attr(no_justify.to_string()))
}