Skip to content

Commit

Permalink
fix: increase the latency of the display
Browse files Browse the repository at this point in the history
  • Loading branch information
hanshuaikang committed Jan 4, 2025
1 parent 61577bc commit 4dd0f55
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
5 changes: 3 additions & 2 deletions src/network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(_) => {
Expand Down
4 changes: 2 additions & 2 deletions src/ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ pub fn draw_interface<B: Backend>(
.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
Expand All @@ -189,7 +189,7 @@ pub fn draw_interface<B: Backend>(
.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::<Vec<Span>>(),
),
)
Expand Down

0 comments on commit 4dd0f55

Please sign in to comment.