From 4dd0f55064955b3069a928f3ae6ca74cec65643b Mon Sep 17 00:00:00 2001 From: hanshuaikang <1758504262@qq.com> Date: Sat, 4 Jan 2025 15:03:39 +0800 Subject: [PATCH] fix: increase the latency of the display --- src/network.rs | 5 +++-- src/ui.rs | 4 ++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/network.rs b/src/network.rs index 96f0827..e69b664 100644 --- a/src/network.rs +++ b/src/network.rs @@ -92,12 +92,13 @@ impl PingTask { match result { PingResult::Pong(duration, _size) => { // calculate rtt - let rtt = ((duration.as_secs_f64() * 1000.0) as i64) as f64; + let rtt = duration.as_secs_f64() * 1000.0; + let rtt_display: f64 = format!("{:.2}", rtt).parse().unwrap(); update_stats( self.ip_data.clone(), self.index, self.addr.parse().unwrap(), - rtt, + rtt_display, ); } PingResult::Timeout(_) => { diff --git a/src/ui.rs b/src/ui.rs index e37374d..77c1590 100644 --- a/src/ui.rs +++ b/src/ui.rs @@ -165,7 +165,7 @@ pub fn draw_interface( .graph_type(ratatui::widgets::GraphType::Line) .data(&data_points)]; - let y_bounds = [0.0, (data.max_rtt * 1.2).max(50.0)]; + let y_bounds = [0.0, data.max_rtt * 1.2]; let x_range = data .rtts @@ -189,7 +189,7 @@ pub fn draw_interface( .bounds(y_bounds) .labels( (0..=5) - .map(|i| Span::raw(format!("{}ms", i * (y_bounds[1] / 5.0) as i32))) + .map(|i| Span::raw(format!("{:.2}ms", i as f64 * (y_bounds[1] / 5.0) as f64))) .collect::>(), ), )