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
135
136
137
138
139
prelude! {}
pub struct ChartDesc {
pub title: Option<String>,
pub spec: chart::ChartSpec,
}
impl ChartDesc {
pub fn new_size_over_time(title: Option<String>, spec: BTMap<uid::Line, bool>) -> Self {
Self {
title,
spec: chart::ChartSpec::new(
chart::axis::XAxis::Time,
chart::axis::YAxis::TotalSize,
spec,
),
}
}
pub fn into_chart(self, filters: &Filters) -> Res<chart::Chart> {
let Self { title, spec } = self;
chart::Chart::from_spec(title, filters, spec)
}
}
pub fn default(filters: &Filters) -> Res<Vec<chart::Chart>> {
single(filters)
}
pub fn single(filters: &Filters) -> Res<Vec<chart::Chart>> {
Ok(vec![ChartDesc::new_size_over_time(
None,
filters.uid_map(true),
)
.into_chart(filters)?])
}
pub fn alloc_file_prefix<'a>(
filters: &Filters,
file_to_filter: impl IntoIterator<Item = (&'a String, uid::Filter)>,
) -> Res<Vec<chart::Chart>> {
let mut pref_to_filters = HMap::new();
for (file, uid) in file_to_filter {
use std::path::Path;
let path = Path::new(file);
let is_new = pref_to_filters
.entry(path.parent())
.or_insert_with(HSet::new)
.insert(uid::Line::Filter(uid));
debug_assert!(is_new);
}
let all_inactive = filters.uid_map(false);
let mut pref_filters = vec![];
let mut lonely = ChartDesc::new_size_over_time(Some("others".into()), all_inactive.clone());
let mut no_pref =
ChartDesc::new_size_over_time(Some("root files".into()), all_inactive.clone());
for (pref, uids) in pref_to_filters {
debug_assert!(!uids.is_empty());
if let Some(pref) = pref {
if uids.len() > 1 {
let title = pref.to_string_lossy();
if title.is_empty() {
no_pref
.spec
.active_mut()
.extend(uids.into_iter().map(|uid| (uid, true)));
} else {
let mut active = all_inactive.clone();
for uid in uids {
active.insert(uid, true);
}
let desc = ChartDesc::new_size_over_time(Some(title.into()), active);
let chart = desc.into_chart(filters)?;
pref_filters.push(chart)
}
} else {
lonely
.spec
.active_mut()
.extend(uids.into_iter().map(|uid| (uid, true)))
}
} else {
no_pref
.spec
.active_mut()
.extend(uids.into_iter().map(|uid| (uid, true)));
}
}
if !pref_filters.is_empty() {
let mut active = all_inactive;
active.insert(uid::Line::Everything, true);
let everything = ChartDesc::new_size_over_time(None, active);
let mut res = vec![everything.into_chart(filters)?];
res.extend(pref_filters);
if lonely.spec.has_active_filters() {
res.push(lonely.into_chart(filters)?)
}
if no_pref.spec.has_active_filters() {
res.push(no_pref.into_chart(filters)?)
}
Ok(res)
} else {
single(filters)
}
}