graphviz_dot_builder/item/node/
style.rs1use strum_macros::IntoStaticStr;
20use crate::colors::GraphvizColor;
21use crate::traits::DotTranslatable;
22
23
24#[derive(IntoStaticStr,Eq,PartialEq,Clone)]
25pub enum GvNodeStyleKind {
26 Solid,
27 Dashed,
28 Dotted,
29 Bold,
30 Rounded,
31 Diagonals,
32 Filled,
33 Striped,
34 Wedged,
35 Invis
36}
37
38impl DotTranslatable for GvNodeStyleKind {
39 fn to_dot_string(&self) -> String {
40 let as_static_str : &'static str = self.into();
41 as_static_str.to_string().to_lowercase()
42 }
43}
44
45pub type GvNodeStyle = Vec<GvNodeStyleKind>;
46
47impl DotTranslatable for GvNodeStyle {
48 fn to_dot_string(&self) -> String {
49 let elements : Vec<String> = self.iter().map(
50 |item| item.to_dot_string()).collect();
51 format!("\"{}\"", elements.join(","))
52 }
53}
54
55
56#[derive(IntoStaticStr,Eq,PartialEq,Clone)]
57pub enum GvNodeShape {
58 Ellipse,
59 Circle,
60 DoubleCircle,
61 Triangle,
62 Diamond,
63 Trapezium,
64 Parallelogram,
65 House,
66 Pentagon,
67 Hexagon,
68 Septagon,
69 Octagon,
70 Rectangle,
71 Square,
72 InvTriangle,
73 InvTrapezium,
74 InvHouse,
75 Star,
76 PlainText,
77 Point
78}
79
80impl DotTranslatable for GvNodeShape {
81 fn to_dot_string(&self) -> String {
82 let as_static_str : &'static str = self.into();
83 as_static_str.to_string().to_lowercase()
84 }
85}
86
87
88
89
90#[derive(Eq,PartialEq,Clone)]
91pub enum GraphvizNodeStyleItem {
92 Style(GvNodeStyle),
93 Shape(GvNodeShape),
94 Label(String),
95 Image(String),
96 Color(GraphvizColor),
97 FillColor(GraphvizColor),
98 FontColor(GraphvizColor),
99 FontSize(u32),
100 FontName(String),
101 Height(u32),
102 Width(u32),
103 Peripheries(u32),
104 PenWidth(u32)
105}
106
107impl DotTranslatable for GraphvizNodeStyleItem {
108 fn to_dot_string(&self) -> String {
109 match self {
110 GraphvizNodeStyleItem::PenWidth(pw) => {
111 format!("penwidth={:}",pw)
112 },
113 GraphvizNodeStyleItem::Height(height) => {
114 format!("height={:}",height)
115 },
116 GraphvizNodeStyleItem::Width(width) => {
117 format!("width={:}",width)
118 },
119 GraphvizNodeStyleItem::Peripheries(per) => {
120 format!("peripheries={:}",per)
121 },
122 GraphvizNodeStyleItem::Style(node_style) => {
123 format!("style={:}",node_style.to_dot_string())
124 },
125 GraphvizNodeStyleItem::Shape(node_shape) => {
126 format!("shape={:}",node_shape.to_dot_string())
127 },
128 GraphvizNodeStyleItem::Label(label) => {
129 format!("label=\"{}\"",label)
130 },
131 GraphvizNodeStyleItem::Image(imgpath) => {
132 format!("imagescale=true;image=\"{}\"",imgpath)
133 },
134 GraphvizNodeStyleItem::Color(graphviz_color) => {
135 format!("color={:}",graphviz_color.to_dot_string())
136 },
137 GraphvizNodeStyleItem::FillColor(graphviz_color) => {
138 format!("style=filled;fillcolor={:}",graphviz_color.to_dot_string())
139 },
140 GraphvizNodeStyleItem::FontColor(graphviz_color) => {
141 format!("fontcolor={:}",graphviz_color.to_dot_string())
142 },
143 GraphvizNodeStyleItem::FontSize(size) => {
144 format!("fontsize={:}",size)
145 },GraphvizNodeStyleItem::FontName(fname) => {
146 format!("fontname=\"{}\"",fname)
147 }
148 }
149 }
150}
151
152pub type GraphvizNodeStyle = Vec<GraphvizNodeStyleItem>;
153
154