Skip to content

Commit

Permalink
some experiments
Browse files Browse the repository at this point in the history
  • Loading branch information
ClementTsang committed Nov 29, 2022
1 parent e59b4fc commit 5626d69
Showing 1 changed file with 17 additions and 15 deletions.
32 changes: 17 additions & 15 deletions src/components/tui_widget/time_chart.rs
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,8 @@ impl<'a> Widget for TimeChart<'a> {
.y_bounds(self.y_axis.bounds)
.paint(|ctx| {
for dataset in &self.datasets {
let color = dataset.style.fg.unwrap_or(Color::Reset);

let start_bound = self.x_axis.bounds[0];
let end_bound = self.x_axis.bounds[1];

Expand All @@ -436,11 +438,6 @@ impl<'a> Widget for TimeChart<'a> {

let data_slice = &dataset.data[start_index..end_index];

ctx.draw(&Points {
coords: data_slice,
color: dataset.style.fg.unwrap_or(Color::Reset),
});

if let Some(interpolate_start) = interpolate_start {
if let (Some(older_point), Some(newer_point)) = (
dataset.data.get(interpolate_start),
Expand All @@ -451,11 +448,6 @@ impl<'a> Widget for TimeChart<'a> {
interpolate_point(older_point, newer_point, self.x_axis.bounds[0]),
);

ctx.draw(&Points {
coords: &[interpolated_point],
color: dataset.style.fg.unwrap_or(Color::Reset),
});

if let GraphType::Line = dataset.graph_type {
ctx.draw(&Line {
x1: interpolated_point.0,
Expand All @@ -464,6 +456,11 @@ impl<'a> Widget for TimeChart<'a> {
y2: newer_point.1,
color: dataset.style.fg.unwrap_or(Color::Reset),
});
} else {
ctx.draw(&Points {
coords: &[interpolated_point],
color: dataset.style.fg.unwrap_or(Color::Reset),
});
}
}
}
Expand All @@ -478,6 +475,11 @@ impl<'a> Widget for TimeChart<'a> {
color: dataset.style.fg.unwrap_or(Color::Reset),
});
}
} else {
ctx.draw(&Points {
coords: data_slice,
color,
});
}

if let Some(interpolate_end) = interpolate_end {
Expand All @@ -490,11 +492,6 @@ impl<'a> Widget for TimeChart<'a> {
interpolate_point(older_point, newer_point, self.x_axis.bounds[1]),
);

ctx.draw(&Points {
coords: &[interpolated_point],
color: dataset.style.fg.unwrap_or(Color::Reset),
});

if let GraphType::Line = dataset.graph_type {
ctx.draw(&Line {
x1: older_point.0,
Expand All @@ -503,6 +500,11 @@ impl<'a> Widget for TimeChart<'a> {
y2: interpolated_point.1,
color: dataset.style.fg.unwrap_or(Color::Reset),
});
} else {
ctx.draw(&Points {
coords: &[interpolated_point],
color: dataset.style.fg.unwrap_or(Color::Reset),
});
}
}
}
Expand Down

0 comments on commit 5626d69

Please sign in to comment.