Skip to content

Commit

Permalink
feat: error bars for lost probes (#1247) - WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
fujiapple852 committed Aug 15, 2024
1 parent 2427a86 commit 735f0c7
Show file tree
Hide file tree
Showing 4 changed files with 417 additions and 5 deletions.
1 change: 1 addition & 0 deletions crates/trippy-tui/src/frontend/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ pub mod splash;
pub mod table;
pub mod tabs;
pub mod util;
pub mod widgets;
pub mod world;
14 changes: 9 additions & 5 deletions crates/trippy-tui/src/frontend/render/history.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
use crate::frontend::tui_app::TuiApp;
use ratatui::layout::Rect;
use ratatui::style::Style;
use ratatui::widgets::{Block, BorderType, Borders, Sparkline};
use ratatui::style::{Color, Style};
use ratatui::widgets::{Block, BorderType, Borders};
use ratatui::Frame;

use crate::frontend::render::widgets::sparkline::{EmptyBarSymbol, Sparkline};

/// Render the ping history for the final hop which is typically the target.
pub fn render(f: &mut Frame<'_>, app: &TuiApp, rect: Rect) {
let selected_hop = app.selected_hop_or_target();
let data = selected_hop
.samples()
.iter()
.take(rect.width as usize)
.map(|s| (s.as_secs_f64() * 1000_f64) as u64)
.map(|s| if s.as_secs_f64() > 0_f64 {Some((s.as_secs_f64() * 1000_f64) as u64)} else {None})
.collect::<Vec<_>>();
let history = Sparkline::default()
.block(
Expand All @@ -26,11 +28,13 @@ pub fn render(f: &mut Frame<'_>, app: &TuiApp, rect: Rect) {
.border_type(BorderType::Rounded)
.border_style(Style::default().fg(app.tui_config.theme.border)),
)
.data(&data)
.data(data.as_slice())
.style(
Style::default()
.bg(app.tui_config.theme.bg)
.fg(app.tui_config.theme.samples_chart),
);
)
.empty_bar_style(Style::default().fg(Color::Red))
.empty_bar_symbol(EmptyBarSymbol::Full);
f.render_widget(history, rect);
}
2 changes: 2 additions & 0 deletions crates/trippy-tui/src/frontend/render/widgets.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#[allow(dead_code)]
pub mod sparkline;
Loading

0 comments on commit 735f0c7

Please sign in to comment.