fix: avoid crashing history graph on empty plot with throttling data

This commit is contained in:
Ilya Zlobintsev 2025-01-12 11:23:35 +02:00
parent 204dcb47fc
commit 4a35ffbde1
2 changed files with 35 additions and 29 deletions

View File

@ -105,7 +105,7 @@ impl PlotData {
self.push_secondary_line_series_with_time(name, point, chrono::Local::now().naive_local());
}
pub fn push_line_series_with_time(&mut self, name: &str, point: f64, time: NaiveDateTime) {
fn push_line_series_with_time(&mut self, name: &str, point: f64, time: NaiveDateTime) {
self.line_series
.entry(name.to_owned())
.or_default()
@ -183,4 +183,8 @@ impl PlotData {
self.throttling
.retain(|(time_point, _)| ((maximum_point - *time_point) / 1000) < last_seconds);
}
pub fn is_empty(&self) -> bool {
self.line_series.is_empty() && self.secondary_line_series.is_empty()
}
}

View File

@ -293,6 +293,7 @@ impl RenderRequest {
.context("Failed to draw mesh")?;
// Draw the throttling histogram as a series of bars.
if !data.is_empty() {
chart
.draw_series(
data.throttling_iter()
@ -321,6 +322,7 @@ impl RenderRequest {
}),
)
.context("Failed to draw throttling histogram")?;
}
// Draw the main line series using cubic spline interpolation.
for (idx, (caption, data)) in (0..).zip(data.line_series_iter()) {