Skip to content

Commit 422bfab

Browse files
committed
allow to plot only every n-th point (max points is 5000, if dataset is larger, it will reduce it by showing only every 2nd point. if it is larger than 10000 only every 3rd point etc...)
1 parent 4736165 commit 422bfab

File tree

1 file changed

+33
-1
lines changed

1 file changed

+33
-1
lines changed

src/gui.rs

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ pub struct MyApp {
123123
device_idx: usize,
124124
serial_devices: SerialDevices,
125125
plotting_range: usize,
126+
max_points: usize,
126127
plot_serial_display_ratio: f32,
127128
picked_path: PathBuf,
128129
plot_location: Option<egui::Rect>,
@@ -237,6 +238,7 @@ impl MyApp {
237238
send_tx,
238239
gui_cmd_tx,
239240
plotting_range: usize::MAX,
241+
max_points: 5000,
240242
plot_serial_display_ratio: 0.45,
241243
command: "".to_string(),
242244
show_sent_cmds: true,
@@ -390,14 +392,23 @@ impl MyApp {
390392
.y_grid_spacer(log_grid_spacer(10))
391393
.x_axis_formatter(t_fmt);
392394

395+
let n = (self.data.prints.len() / self.max_points).max(1);
396+
393397
let plot_inner = signal_plot.show(ui, |signal_plot_ui| {
394398
for (i, (_label, graph)) in self.data.plots.iter().enumerate() {
395399
// this check needs to be here for when we change devices (not very elegant)
396400
if i < self.labels.len() {
397401
signal_plot_ui.line(
398402
Line::new(
399403
self.labels[i].to_string(),
400-
PlotPoints::Owned(graph[window..].to_vec()),
404+
PlotPoints::Owned(
405+
graph
406+
.iter()
407+
.skip(window)
408+
.step_by(n)
409+
.cloned()
410+
.collect(),
411+
),
401412
)
402413
.color(self.colors[i]),
403414
);
@@ -1017,6 +1028,27 @@ impl MyApp {
10171028
}
10181029
});
10191030
ui.end_row();
1031+
1032+
1033+
ui.label("Max Points [#]: ");
1034+
1035+
ui.horizontal(|ui| {
1036+
ui.add(
1037+
egui::DragValue::new(&mut self.max_points).custom_formatter(window_fmt),
1038+
)
1039+
.on_hover_text(
1040+
"Select the maximum number of points to be displayed in the plot. The actual displayed points will be less than this value (only every 2nd, 3rd, etc. point will be displayed).",
1041+
);
1042+
if ui
1043+
.button("Full Dataset")
1044+
.on_hover_text("Show the full dataset.")
1045+
.clicked()
1046+
{
1047+
self.max_points = usize::MAX;
1048+
}
1049+
});
1050+
ui.end_row();
1051+
10201052
ui.label("Number of plots [#]: ");
10211053

10221054
ui.horizontal(|ui| {

0 commit comments

Comments
 (0)