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