Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add an option to display the whole history of times in the graph #420

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions gping.1
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,9 @@ Default for ping is 0.2,
default for cmd is 0.5.
.TP
\f[B]-b\f[R], \f[B]--buffer\f[R] <BUFFER>
Determines the number of seconds to display in the graph.
[default: 30]
Determines the number of seconds to display in the graph. Pass 0 for
an indefinitely scaling buffer that displays the entire history.
[default: 0]
.TP
\f[B]-4\f[R]
Resolve ping targets to IPv4 address
Expand Down
9 changes: 6 additions & 3 deletions gping/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ struct Args {
#[arg(
short,
long,
default_value = "30",
help = "Determines the number of seconds to display in the graph."
default_value = "0",
help = "Determines the number of seconds to display in the graph. Pass 0 for an indefinitely scaling buffer that displays the entire history."
)]
buffer: u64,
/// Resolve ping targets to IPv4 address
Expand Down Expand Up @@ -176,7 +176,10 @@ impl App {
let now = Local::now();
let now_idx;
let before_idx;
if (now - self.started) < self.display_interval {
if self.display_interval.is_zero() {
now_idx = now.timestamp_millis() as f64 / 1_000f64;
before_idx = self.started.timestamp_millis() as f64 / 1_000f64;
} else if (now - self.started) < self.display_interval {
now_idx = (self.started + self.display_interval).timestamp_millis() as f64 / 1_000f64;
before_idx = self.started.timestamp_millis() as f64 / 1_000f64;
} else {
Expand Down
22 changes: 12 additions & 10 deletions gping/src/plot_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,18 @@ impl PlotData {
None => self.data.push((idx, f64::NAN)),
}
// Find the last index that we should remove.
let earliest_timestamp = (now - self.buffer).timestamp_millis() as f64 / 1_000f64;
let last_idx = self
.data
.iter()
.enumerate()
.filter(|(_, (timestamp, _))| *timestamp < earliest_timestamp)
.map(|(idx, _)| idx)
.last();
if let Some(idx) = last_idx {
self.data.drain(0..idx).for_each(drop)
if !self.buffer.is_zero() {
let earliest_timestamp = (now - self.buffer).timestamp_millis() as f64 / 1_000f64;
let last_idx = self
.data
.iter()
.enumerate()
.filter(|(_, (timestamp, _))| *timestamp < earliest_timestamp)
.map(|(idx, _)| idx)
.last();
if let Some(idx) = last_idx {
self.data.drain(0..idx).for_each(drop)
}
}
}

Expand Down
Loading