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
use crate::query::GraphQuery;
use crate::{domain::types::BaseEvent, graph::*};
use uuid::Uuid;
pub trait EiffelGraph:
Graph<Key = Uuid, Data = BaseEvent, EdgeData = String> + Indexable<usize>
{
}
impl<T> EiffelGraph for T where
T: Graph<Key = Uuid, Data = BaseEvent, EdgeData = String> + Indexable<usize>
{
}
impl Key for Uuid {}
pub trait EiffelVisApp: EiffelGraph {
fn push(&mut self, event: BaseEvent);
fn get_event(&self, id: Uuid) -> Option<&BaseEvent>;
fn dump<'a, T: From<&'a BaseEvent>>(&'a self) -> Vec<T>;
fn get_subgraph_with_roots<'a, T: From<&'a BaseEvent>>(&'a self, roots: &[Uuid]) -> Vec<T>;
}
impl<G: EiffelGraph> EiffelVisApp for G {
fn push(&mut self, event: BaseEvent) {
let links = event.links.clone();
self.add_node_with_edges(
event.meta.id,
event,
links.into_iter().map(|link| (link.target, link.link_type)),
);
println!("Graph size: {}", self.node_count());
}
fn get_event(&self, id: Uuid) -> Option<&BaseEvent> {
Some(self.get(id)?.data())
}
fn dump<'a, T: From<&'a BaseEvent>>(&'a self) -> Vec<T> {
self.items().map(|node| T::from(node.data())).collect()
}
fn get_subgraph_with_roots<'a, T: From<&'a BaseEvent>>(&'a self, roots: &[Uuid]) -> Vec<T> {
roots
.iter()
.filter_map(|i| self.get(*i))
.roots_for_graph(self)
.map(|node| T::from(node.data()))
.collect()
}
}