rudof_rdf/rdf_core/visualizer/style/
arrow_style.rs1use crate::rdf_core::visualizer::style::{ThicknessStyle, UmlColor};
2use serde::{Deserialize, Serialize};
3
4const DEFAULT_ARROW_LINE_THICKNESS: ThicknessStyle = ThicknessStyle::Normal;
6const DEFAULT_ARROW_LINE_COLOR: UmlColor = UmlColor::Black;
8const DEFAULT_ARROW_TEXT_COLOR: UmlColor = UmlColor::Black;
10
11pub const DEFAULT_SUBJECT_ARROW_STYLE: ArrowStyle = ArrowStyle {
13 line_color: Some(UmlColor::Blue),
14 line_thickness: Some(ThicknessStyle::Dashed),
15 text_color: Some(UmlColor::Blue),
16};
17pub const DEFAULT_PREDICATE_ARROW_STYLE: ArrowStyle = ArrowStyle {
19 line_color: Some(UmlColor::Red),
20 line_thickness: Some(ThicknessStyle::Dashed),
21 text_color: Some(UmlColor::Red),
22};
23pub const DEFAULT_OBJECT_ARROW_STYLE: ArrowStyle = ArrowStyle {
25 line_color: Some(UmlColor::Green),
26 line_thickness: Some(ThicknessStyle::Dashed),
27 text_color: Some(UmlColor::Green),
28};
29
30#[derive(Serialize, Deserialize, PartialEq, Debug, Clone)]
32pub struct ArrowStyle {
33 pub line_color: Option<UmlColor>,
35 pub line_thickness: Option<ThicknessStyle>,
37 pub text_color: Option<UmlColor>,
39}
40
41impl ArrowStyle {
42 pub fn new() -> Self {
44 ArrowStyle {
45 line_color: Some(DEFAULT_ARROW_LINE_COLOR),
46 line_thickness: Some(DEFAULT_ARROW_LINE_THICKNESS),
47 text_color: Some(DEFAULT_ARROW_TEXT_COLOR),
48 }
49 }
50
51 pub fn with_line_color(mut self, color: UmlColor) -> Self {
53 self.line_color = Some(color);
54 self
55 }
56
57 pub fn with_line_thickness(mut self, thickness: ThicknessStyle) -> Self {
59 self.line_thickness = Some(thickness);
60 self
61 }
62
63 pub fn with_text_color(mut self, color: UmlColor) -> Self {
65 self.text_color = Some(color);
66 self
67 }
68
69 pub fn as_plantuml(&self) -> String {
74 format!(
75 "#line:{};{}text:{}",
76 self.line_color
77 .as_ref()
78 .map(|c| c.as_plantuml().to_lowercase())
79 .unwrap_or_default(),
80 self.line_thickness
81 .as_ref()
82 .map(|t| t.as_plantuml().to_lowercase())
83 .unwrap_or_default(),
84 self.text_color
85 .as_ref()
86 .map(|c| c.as_plantuml().to_lowercase())
87 .unwrap_or_default()
88 )
89 }
90}
91
92impl Default for ArrowStyle {
93 fn default() -> Self {
94 Self::new()
95 }
96}