wolf_graph_dot/
edge_attributes.rs1use std::fmt;
2
3use crate::{ArrowDirection, ArrowType, Color, EdgeStyle};
4
5#[derive(Debug, Clone, PartialEq)]
6pub struct EdgeAttributes {
7 pub label: Option<String>,
8 pub color: Option<Color>,
9 pub style: Option<EdgeStyle>,
10 pub shape: Option<String>,
11 pub arrow_direction: Option<ArrowDirection>,
12 pub arrow_head: Option<ArrowType>,
13 pub arrow_tail: Option<ArrowType>,
14}
15
16impl EdgeAttributes {
17 pub fn new(
18 label: Option<String>,
19 color: Option<Color>,
20 style: Option<EdgeStyle>,
21 shape: Option<String>,
22 arrow_direction: Option<ArrowDirection>,
23 arrow_head: Option<ArrowType>,
24 arrow_tail: Option<ArrowType>,
25 ) -> Self {
26 Self {
27 label,
28 color,
29 style,
30 shape,
31 arrow_direction,
32 arrow_head,
33 arrow_tail,
34 }
35 }
36
37 pub fn attributes(&self) -> Option<String> {
38 crate::details::encode::encode_attributes(
39 &[
40 ("label", self.label.as_ref().map(|s| s as &dyn ToString)),
41 ("color", self.color.as_ref().map(|c| c as &dyn ToString)),
42 ("style", self.style.as_ref().map(|s| s as &dyn ToString)),
43 ("shape", self.shape.as_ref().map(|s| s as &dyn ToString)),
44 ("dir", self.arrow_direction.as_ref().map(|s| s as &dyn ToString)),
45 ("arrowhead", self.arrow_head.as_ref().map(|s| s as &dyn ToString)),
46 ("arrowtail", self.arrow_tail.as_ref().map(|s| s as &dyn ToString)),
47 ],
48 true,
49 )
50 }
51}
52
53impl Default for EdgeAttributes {
54 fn default() -> Self {
55 Self::new(None, None, None, None, None, None, None)
56 }
57}
58
59impl fmt::Display for EdgeAttributes {
60 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
61 if let Some(encoded) = self.attributes() {
62 write!(f, "{}", encoded)
63 } else {
64 Ok(())
65 }
66 }
67}