mirror of
https://github.com/GyulyVGC/sniffnet.git
synced 2025-12-23 14:21:28 -05:00
improvements and fixes to preview charts
This commit is contained in:
@@ -19,8 +19,6 @@ pub struct PreviewChart {
|
||||
pub ticks: u32,
|
||||
/// Packets (sent & received)
|
||||
pub packets: ChartSeries,
|
||||
/// Minimum number of packets per time interval (computed on last 30 intervals)
|
||||
pub min_packets: f32,
|
||||
/// Maximum number of packets per time interval (computed on last 30 intervals)
|
||||
pub max_packets: f32,
|
||||
/// Style of the chart
|
||||
@@ -32,7 +30,6 @@ pub fn new(style: StyleType) -> Self {
|
||||
Self {
|
||||
ticks: 0,
|
||||
packets: ChartSeries::default(),
|
||||
min_packets: 0.0,
|
||||
max_packets: 0.0,
|
||||
style,
|
||||
}
|
||||
@@ -49,7 +46,6 @@ pub fn update_charts_data(&mut self, packets: u128) {
|
||||
|
||||
// update sent bytes traffic data
|
||||
self.packets.update_series(packets_point, true, false);
|
||||
self.min_packets = self.packets.get_min();
|
||||
self.max_packets = self.packets.get_max();
|
||||
}
|
||||
|
||||
@@ -61,17 +57,6 @@ pub fn change_style(&mut self, style: StyleType) {
|
||||
self.style = style;
|
||||
}
|
||||
|
||||
fn set_margins_and_label_areas<DB: DrawingBackend>(
|
||||
&self,
|
||||
chart_builder: &mut ChartBuilder<DB>,
|
||||
) {
|
||||
chart_builder
|
||||
.margin_right(25)
|
||||
.margin_top(6)
|
||||
.set_label_area_size(LabelAreaPosition::Left, 55);
|
||||
chart_builder.set_label_area_size(LabelAreaPosition::Bottom, 40);
|
||||
}
|
||||
|
||||
fn x_axis_range(&self) -> Range<f32> {
|
||||
// if we have only one tick, we need to add a second point to draw the area
|
||||
if self.ticks == 1 {
|
||||
@@ -86,10 +71,8 @@ fn x_axis_range(&self) -> Range<f32> {
|
||||
}
|
||||
|
||||
fn y_axis_range(&self) -> Range<f32> {
|
||||
let (min, max) = (self.min_packets, self.max_packets);
|
||||
let fs = max - min;
|
||||
let gap = fs * 0.05;
|
||||
min - gap..max + gap
|
||||
let max = self.max_packets;
|
||||
0.0..max
|
||||
}
|
||||
|
||||
fn area_series<DB: DrawingBackend>(&self) -> AreaSeries<DB, f32, f32> {
|
||||
@@ -120,8 +103,6 @@ fn build_chart<DB: DrawingBackend>(
|
||||
return;
|
||||
}
|
||||
|
||||
// self.set_margins_and_label_areas(&mut chart_builder);
|
||||
|
||||
let x_axis_range = self.x_axis_range();
|
||||
let x_axis_start = x_axis_range.start;
|
||||
let x_axis_end = x_axis_range.end;
|
||||
|
||||
@@ -338,7 +338,7 @@ pub fn update(&mut self, message: Message) -> Task<Message> {
|
||||
Message::Reset => self.reset(),
|
||||
Message::Style(style) => {
|
||||
self.conf.settings.style = style;
|
||||
self.traffic_chart.change_style(style);
|
||||
self.change_charts_style();
|
||||
}
|
||||
Message::LoadStyle(path) => {
|
||||
self.conf.settings.style_path.clone_from(&path);
|
||||
@@ -347,7 +347,7 @@ pub fn update(&mut self, message: Message) -> Task<Message> {
|
||||
CustomPalette::from_palette(palette),
|
||||
));
|
||||
self.conf.settings.style = style;
|
||||
self.traffic_chart.change_style(style);
|
||||
self.change_charts_style();
|
||||
}
|
||||
}
|
||||
Message::AddOrRemoveFavorite(host, add) => self.add_or_remove_favorite(&host, add),
|
||||
@@ -892,6 +892,7 @@ fn reset(&mut self) {
|
||||
// increment capture id to ignore pending messages from previous captures
|
||||
self.current_capture_rx = (self.current_capture_rx.0 + 1, None);
|
||||
self.info_traffic = InfoTraffic::default();
|
||||
self.preview_charts = HashMap::new();
|
||||
self.addresses_resolved = HashMap::new();
|
||||
self.favorite_hosts = HashSet::new();
|
||||
self.logged_notifications = (VecDeque::new(), 0);
|
||||
@@ -1182,6 +1183,14 @@ pub fn is_capture_source_consistent(&self) -> bool {
|
||||
|| self.conf.capture_source_picklist == CaptureSourcePicklist::File
|
||||
&& matches!(self.capture_source, CaptureSource::File(_))
|
||||
}
|
||||
|
||||
fn change_charts_style(&mut self) {
|
||||
let style = self.conf.settings.style;
|
||||
self.traffic_chart.change_style(style);
|
||||
for chart in self.preview_charts.values_mut() {
|
||||
chart.change_style(style);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
||||
Reference in New Issue
Block a user