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
use Graph;
#[derive(Clone, Copy, Default, Debug)]
pub struct Point {
pub x: f64,
pub y: f64,
}
#[derive(Clone, Default, Debug)]
pub struct NodeInfo {
pub name: Option<String>,
pub point: Option<Point>,
pub label: Option<usize>,
pub value: Option<String>,
}
impl NodeInfo {
pub fn update(&mut self, info: NodeInfo) {
if info.name.is_some() {
self.name = info.name;
}
if info.point.is_some() {
self.point = info.point;
}
if info.label.is_some() {
self.label = info.label;
}
if info.value.is_some() {
self.value = info.value;
}
}
}
#[derive(Clone, Default, Debug)]
pub struct EdgeInfo {
pub label: Option<usize>,
pub value: Option<String>,
}
impl EdgeInfo {
pub fn update(&mut self, info: EdgeInfo) {
if info.label.is_some() {
self.label = info.label;
}
if info.value.is_some() {
self.value = info.value;
}
}
}
pub trait GraphDrawer<'a, G>
where G: Graph<'a>
{
fn set_node(&mut self, u: G::Node, info: NodeInfo);
fn set_node_point(&mut self, u: G::Node, point: Point) {
self.set_node(u, NodeInfo { point: Some(point), ..Default::default() });
}
fn set_node_name(&mut self, u: G::Node, name: String) {
self.set_node(u, NodeInfo { name: Some(name), ..Default::default() });
}
fn set_node_label(&mut self, u: G::Node, label: usize) {
self.set_node(u, NodeInfo { label: Some(label), ..Default::default() });
}
fn set_node_value(&mut self, u: G::Node, value: String) {
self.set_node(u, NodeInfo { value: Some(value), ..Default::default() });
}
fn set_edge(&mut self, a: G::Edge, info: EdgeInfo);
fn set_edge_label(&mut self, u: G::Edge, label: usize) {
self.set_edge(u, EdgeInfo { label: Some(label), ..Default::default() });
}
fn set_edge_value(&mut self, e: G::Edge, value: String) {
self.set_edge(e, EdgeInfo { value: Some(value), ..Default::default() });
}
fn add_drawing(&mut self);
}