summaryrefslogtreecommitdiff
path: root/src/attributes/compass_point.rs
blob: 6a8dbd756a59db98fb59e42c443b6d0091dff32b (plain)
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
use crate::dot::DotString;
use std::borrow::Cow;

// TODO: not sure we need this enum but should support setting nodeport either via
// headport / tailport attributes e.g. a -> b [tailport=se]
// or via edge declaration using the syntax node name:port_name e.g. a -> b:se
// aka compass
#[derive(Clone, PartialEq, Eq, Debug)]
pub enum CompassPoint {
    N,
    NE,
    E,
    SE,
    S,
    SW,
    W,
    NW,
    /// pecifies the center of the node or port
    C,
    /// specifies that an appropriate side of the port adjacent to the exterior of the node should
    /// be used, if such exists.
    None,
}

impl<'a> DotString<'a> for CompassPoint {
    fn dot_string(&self) -> Cow<'a, str> {
        match self {
            CompassPoint::N => "n".into(),
            CompassPoint::NE => "ne".into(),
            CompassPoint::E => "e".into(),
            CompassPoint::SE => "se".into(),
            CompassPoint::S => "s".into(),
            CompassPoint::SW => "sw".into(),
            CompassPoint::W => "w".into(),
            CompassPoint::NW => "nw".into(),
            CompassPoint::C => "c".into(),
            CompassPoint::None => "_".into(),
        }
    }
}