1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
use crate::dot::DotString;
use std::borrow::Cow;

pub enum NodeStyle {
    Bold,
    Dashed,
    Diagonals,
    Dotted,
    Filled,
    Invisible,
    Rounded,
    Solid,
    Stripped,
    Radical,
    Wedged,
}

impl<'a> DotString<'a> for NodeStyle {
    fn dot_string(&self) -> Cow<'a, str> {
        match self {
            NodeStyle::Bold => "bold".into(),
            NodeStyle::Dashed => "dashed".into(),
            NodeStyle::Diagonals => "diagonals".into(),
            NodeStyle::Dotted => "dotted".into(),
            NodeStyle::Filled => "filled".into(),
            NodeStyle::Invisible => "invisible".into(),
            NodeStyle::Rounded => "rounded".into(),
            NodeStyle::Solid => "solid".into(),
            NodeStyle::Stripped => "stripped".into(),
            NodeStyle::Radical => "radical".into(),
            NodeStyle::Wedged => "wedged".into(),
        }
    }
}

pub enum EdgeStyle {
    Bold,
    Dashed,
    Dotted,
    Invisible,
    Solid,
    Tapered,
}

impl<'a> DotString<'a> for EdgeStyle {
    fn dot_string(&self) -> Cow<'a, str> {
        match self {
            EdgeStyle::Bold => "bold".into(),
            EdgeStyle::Dashed => "dashed".into(),
            EdgeStyle::Dotted => "dotted".into(),
            EdgeStyle::Invisible => "invisible".into(),
            EdgeStyle::Solid => "solid".into(),
            EdgeStyle::Tapered => "tapered".into(),
        }
    }
}

pub enum GraphStyle {
    Filled,
    Radical,
    Rounded,
    Striped,
}

impl<'a> DotString<'a> for GraphStyle {
    fn dot_string(&self) -> Cow<'a, str> {
        match self {
            GraphStyle::Filled => "filled".into(),
            GraphStyle::Radical => "radical".into(),
            GraphStyle::Rounded => "rounded".into(),
            GraphStyle::Striped => "striped".into(),
        }
    }
}

// TODO: this might be a bit much to in order to avoid some duplication
// probably not worth it but is pattern is cool nonetheless
pub enum Styles {
    Edge(EdgeStyle),
    Node(NodeStyle),
    Graph(GraphStyle),
}

impl<'a> DotString<'a> for Styles {
    fn dot_string(&self) -> Cow<'a, str> {
        match self {
            Styles::Edge(s) => s.dot_string(),
            Styles::Node(s) => s.dot_string(),
            Styles::Graph(s) => s.dot_string(),
        }
    }
}