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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
use std::fmt;
#[derive(Copy, Clone, Debug)]
pub(crate) struct Color(pub u8, pub u8, pub u8);
impl fmt::Display for Color {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let Color(r, g, b) = self;
write!(f, "#{:02x}{:02x}{:02x}", r, g, b)
}
}
#[derive(Clone, Debug)]
pub(crate) struct ColorPalette {
pub purple: Color,
pub red: Color,
pub orange: Color,
pub yellow: Color,
pub green: Color,
pub cyan: Color,
pub blue: Color,
pub black: Color,
#[allow(dead_code)]
pub gray: Color,
#[allow(dead_code)]
pub white: Color,
}
pub(crate) fn color_palette() -> ColorPalette {
ColorPalette {
purple: Color(186, 111, 167),
red: Color(219, 83, 103),
orange: Color(254, 148, 84),
yellow: Color(248, 192, 76),
green: Color(129, 193, 105),
cyan: Color(105, 190, 210),
blue: Color(83, 151, 200),
black: Color(0, 0, 0),
gray: Color(127, 127, 127),
white: Color(255, 255, 255),
}
}
#[derive(Clone, Debug)]
pub(crate) struct NodeVisibilityStyles {
pub pub_crate: NodeStyle,
pub pub_module: NodeStyle,
pub pub_private: NodeStyle,
pub pub_global: NodeStyle,
pub pub_super: NodeStyle,
}
#[derive(Clone, Debug)]
pub(crate) struct NodeStyle {
pub fill_color: Color,
}
impl NodeStyle {
fn new(fill_color: Color) -> Self {
Self { fill_color }
}
}
#[derive(Clone, Debug)]
pub(crate) struct NodeStyles {
#[allow(dead_code)]
pub krate: NodeStyle,
pub visibility: NodeVisibilityStyles,
pub orphan: NodeStyle,
#[allow(dead_code)]
pub test: NodeStyle,
}
pub(crate) fn node_styles() -> NodeStyles {
let color_palette = color_palette();
NodeStyles {
krate: NodeStyle::new(color_palette.blue),
visibility: NodeVisibilityStyles {
pub_crate: NodeStyle::new(color_palette.yellow),
pub_module: NodeStyle::new(color_palette.orange),
pub_private: NodeStyle::new(color_palette.red),
pub_global: NodeStyle::new(color_palette.green),
pub_super: NodeStyle::new(color_palette.orange),
},
orphan: NodeStyle::new(color_palette.purple),
test: NodeStyle::new(color_palette.cyan),
}
}
#[derive(Clone, Debug)]
pub(crate) enum Stroke {
Solid,
Dashed,
}
impl fmt::Display for Stroke {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let name = match self {
Self::Solid => "solid",
Self::Dashed => "dashed",
};
write!(f, "{}", name)
}
}
#[derive(Clone, Debug)]
pub(crate) struct EdgeStyle {
pub color: Color,
pub stroke: Stroke,
}
impl EdgeStyle {
fn new(color: Color, stroke: Stroke) -> Self {
Self { color, stroke }
}
}
#[derive(Clone, Debug)]
pub(crate) struct EdgeStyles {
pub owns: EdgeStyle,
pub uses: EdgeStyle,
}
pub(crate) fn edge_styles() -> EdgeStyles {
let color_palette = color_palette();
EdgeStyles {
owns: EdgeStyle::new(color_palette.black, Stroke::Solid),
uses: EdgeStyle::new(color_palette.gray, Stroke::Dashed),
}
}