graphviz_dot_builder/item/node/
node.rs1use crate::item::node::style::GraphvizNodeStyle;
20use crate::traits::{DotTranslatable, RenameableWithPrefix};
21
22#[derive(Eq,PartialEq,Clone)]
23pub struct GraphVizNode {
24 pub id : String,
25 pub style : GraphvizNodeStyle
26}
27
28impl GraphVizNode {
29 pub fn new(id : String,
30 style : GraphvizNodeStyle) -> GraphVizNode {
31 GraphVizNode{id,style}
32 }
33}
34
35impl DotTranslatable for GraphVizNode {
36 fn to_dot_string(&self) -> String {
37 let style : Vec<String> = self.style.iter().map(
38 |item| item.to_dot_string()).collect();
39
40 if style.is_empty() {
41 format!("{};", self.id)
42 } else {
43 format!("{} [{}];", self.id, style.join(","))
44 }
45 }
46}
47
48impl RenameableWithPrefix for GraphVizNode {
49 fn rename_with_prefix(&self, prefix: &str) -> Self {
50 GraphVizNode::new(format!("{}{}",prefix,self.id),self.style.clone())
51 }
52}
53