Skip to content

Commit 12b12c6

Browse files
committed
notifications page: use relative bar lengths
1 parent 7233cc9 commit 12b12c6

2 files changed

Lines changed: 43 additions & 6 deletions

File tree

src/gui/pages/notifications_page.rs

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ use crate::networking::types::traffic_type::TrafficType;
2424
use crate::notifications::types::logged_notification::{
2525
DataThresholdExceeded, FavoriteTransmitted, LoggedNotification,
2626
};
27+
use crate::report::types::sort_type::SortType;
2728
use crate::translations::translations::{
2829
bytes_exceeded_translation, clear_all_translation, favorite_transmitted_translation,
2930
no_notifications_received_translation, no_notifications_set_translation,
@@ -143,6 +144,7 @@ fn body_no_notifications_received(
143144

144145
fn packets_notification_log<'a>(
145146
logged_notification: DataThresholdExceeded,
147+
first_entry_data_info: DataInfo,
146148
language: Language,
147149
font: Font,
148150
) -> Container<'a, Message, StyleType> {
@@ -187,7 +189,7 @@ fn packets_notification_log<'a>(
187189
.push(threshold_bar(
188190
logged_notification.data_info,
189191
ChartType::Packets,
190-
logged_notification.data_info,
192+
first_entry_data_info,
191193
font,
192194
language,
193195
));
@@ -200,6 +202,7 @@ fn packets_notification_log<'a>(
200202

201203
fn bytes_notification_log<'a>(
202204
logged_notification: DataThresholdExceeded,
205+
first_entry_data_info: DataInfo,
203206
language: Language,
204207
font: Font,
205208
) -> Container<'a, Message, StyleType> {
@@ -244,7 +247,7 @@ fn bytes_notification_log<'a>(
244247
.push(threshold_bar(
245248
logged_notification.data_info,
246249
ChartType::Bytes,
247-
logged_notification.data_info,
250+
first_entry_data_info,
248251
font,
249252
language,
250253
));
@@ -257,6 +260,7 @@ fn bytes_notification_log<'a>(
257260

258261
fn favorite_notification_log<'a>(
259262
logged_notification: FavoriteTransmitted,
263+
first_entry_data_info: DataInfo,
260264
chart_type: ChartType,
261265
language: Language,
262266
font: Font,
@@ -265,7 +269,7 @@ fn favorite_notification_log<'a>(
265269
&logged_notification.host,
266270
&logged_notification.data_info_host,
267271
chart_type,
268-
logged_notification.data_info_host.data_info,
272+
first_entry_data_info,
269273
font,
270274
language,
271275
);
@@ -339,16 +343,39 @@ fn logged_notifications<'a>(sniffer: &Sniffer) -> Column<'a, Message, StyleType>
339343
.spacing(10)
340344
.align_x(Alignment::Center);
341345

346+
let first_entry_data_info = sniffer
347+
.logged_notifications
348+
.iter()
349+
.map(LoggedNotification::data_info)
350+
.max_by(|d1, d2| d1.compare(d2, SortType::Ascending, chart_type))
351+
.unwrap_or_default();
352+
342353
for logged_notification in &sniffer.logged_notifications {
343354
ret_val = ret_val.push(match logged_notification {
344355
LoggedNotification::PacketsThresholdExceeded(packet_threshold_exceeded) => {
345-
packets_notification_log(packet_threshold_exceeded.clone(), language, font)
356+
packets_notification_log(
357+
packet_threshold_exceeded.clone(),
358+
first_entry_data_info,
359+
language,
360+
font,
361+
)
346362
}
347363
LoggedNotification::BytesThresholdExceeded(byte_threshold_exceeded) => {
348-
bytes_notification_log(byte_threshold_exceeded.clone(), language, font)
364+
bytes_notification_log(
365+
byte_threshold_exceeded.clone(),
366+
first_entry_data_info,
367+
language,
368+
font,
369+
)
349370
}
350371
LoggedNotification::FavoriteTransmitted(favorite_transmitted) => {
351-
favorite_notification_log(favorite_transmitted.clone(), chart_type, language, font)
372+
favorite_notification_log(
373+
favorite_transmitted.clone(),
374+
first_entry_data_info,
375+
chart_type,
376+
language,
377+
font,
378+
)
352379
}
353380
});
354381
}

src/notifications/types/logged_notification.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,16 @@ pub enum LoggedNotification {
1212
FavoriteTransmitted(FavoriteTransmitted),
1313
}
1414

15+
impl LoggedNotification {
16+
pub fn data_info(&self) -> DataInfo {
17+
match self {
18+
LoggedNotification::BytesThresholdExceeded(d)
19+
| LoggedNotification::PacketsThresholdExceeded(d) => d.data_info,
20+
LoggedNotification::FavoriteTransmitted(f) => f.data_info_host.data_info,
21+
}
22+
}
23+
}
24+
1525
#[derive(Clone)]
1626
pub struct DataThresholdExceeded {
1727
pub(crate) threshold: u64,

0 commit comments

Comments
 (0)