From e4fea66df6a8d63fae2f7d8f6c7fddcba06b198c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Stefa=C5=84ski?= Date: Sun, 24 May 2026 20:01:01 +0200 Subject: [PATCH] improvements 2 --- libsvld/src/lib.rs | 12 ++++++------ svldplotter/src/plot.rs | 36 +++++++++++++++++++++++++++++++++++- svldplotter/src/tree.rs | 2 +- 3 files changed, 42 insertions(+), 8 deletions(-) diff --git a/libsvld/src/lib.rs b/libsvld/src/lib.rs index 98c3e56..fce7425 100644 --- a/libsvld/src/lib.rs +++ b/libsvld/src/lib.rs @@ -255,6 +255,11 @@ pub fn decode(dbc: &Dbc, // println!("{:?}", unknown_ids); // println!("{:?}", error_frames); + for (_, frames) in &mut data { + // frames.voracious_mt_sort(thread_count); + frames.voracious_sort(); + } + DecodeResult { data, metadata, @@ -274,7 +279,7 @@ pub fn decode_to_motec(dbc: &Dbc, asc_path: &Path, output_dir: &Path) -> DecodeProcessInfo { let DecodeResult { - mut data, + data, metadata, info, } = decode(dbc, asc_path); @@ -285,11 +290,6 @@ pub fn decode_to_motec(dbc: &Dbc, .and_utc() .to_rfc3339_opts(chrono::SecondsFormat::Secs, true); - for (_, frames) in &mut data { - // frames.voracious_mt_sort(thread_count); - frames.voracious_sort(); - } - let msgs: Vec = metadata.values().cloned().collect(); // println!("Messages: {}", msgs.len()); diff --git a/svldplotter/src/plot.rs b/svldplotter/src/plot.rs index 677215f..6d2f9c3 100644 --- a/svldplotter/src/plot.rs +++ b/svldplotter/src/plot.rs @@ -1,7 +1,7 @@ use eframe::egui; use egui::ecolor::Hsva; use egui::{Color32, Vec2b}; -use egui_plot::{AxisHints, Legend, Line, Plot, PlotPoint, PlotPoints, VPlacement}; +use egui_plot::{AxisHints, Legend, Line, Plot, PlotBounds, PlotPoint, PlotPoints, VPlacement}; use crate::plot_list::{majority_unit, PlotGroup}; use crate::signal::{decimate, nearest_y, PlottedSignal}; @@ -62,6 +62,39 @@ fn line_label(sig: &PlottedSignal, cursor_x: Option) -> String { } } +/// Clamp the visible x-range to [0, x_max]. Preserves the current zoom +/// width when possible; if the zoomed-out width exceeds the data range, +/// just snaps to the full range. +fn clamp_x_bounds(plot_ui: &mut egui_plot::PlotUi, x_max: f64) { + let bounds = plot_ui.plot_bounds(); + let lo = bounds.min(); + let hi = bounds.max(); + let mut new_lo_x = lo[0]; + let mut new_hi_x = hi[0]; + let width = new_hi_x - new_lo_x; + + if width >= x_max { + new_lo_x = 0.0; + new_hi_x = x_max; + } else { + if new_lo_x < 0.0 { + new_lo_x = 0.0; + new_hi_x = new_lo_x + width; + } + if new_hi_x > x_max { + new_hi_x = x_max; + new_lo_x = new_hi_x - width; + } + } + + if new_lo_x != lo[0] || new_hi_x != hi[0] { + plot_ui.set_plot_bounds(PlotBounds::from_min_max( + [new_lo_x, lo[1]], + [new_hi_x, hi[1]], + )); + } +} + pub fn show_plot_panel( ui: &mut egui::Ui, plots: &[PlotGroup], @@ -112,6 +145,7 @@ pub fn show_plot_panel( ]); let response = plot.show(ui, |plot_ui| { + clamp_x_bounds(plot_ui, full_max); if plot_group.signals.is_empty() { plot_ui.line( Line::new( diff --git a/svldplotter/src/tree.rs b/svldplotter/src/tree.rs index fad90b5..7024004 100644 --- a/svldplotter/src/tree.rs +++ b/svldplotter/src/tree.rs @@ -92,7 +92,7 @@ pub fn show_dbc_tree( .desired_width(f32::INFINITY), ); let needle = filter.trim(); - let matcher = SkimMatcherV2::default(); + let matcher = SkimMatcherV2::default().ignore_case(); ScrollArea::both() .scroll([true, true]) .scroll_bar_visibility(egui::scroll_area::ScrollBarVisibility::VisibleWhenNeeded)