diff --git a/README.md b/README.md index 2558d8f..883d9f0 100644 --- a/README.md +++ b/README.md @@ -96,7 +96,6 @@ Keybinds (cursor must be in the plot): - Data is evaluated at the bin center for the background marker. - O: Peak find - Peak find settings are located in the context menu. - - Use with caution, lol. - F: Fit Gaussians - Settings and results can be found in the context menu. - Requires 2 region markers. Data will be evaluated between the markers. @@ -104,7 +103,6 @@ Keybinds (cursor must be in the plot): - If no peak markers are between the region markers, the program will assume there is only 1 peak approximately at the max value in the data. - If there is no background fit when the fit button is clicked, the selected background model will be used and fitted. This can result in longer and potentially incorrect fits due to more parameters being fit. A fix would be adjusting the initial guess', min, and max value or fiting the background with the background markers. - The lmfit fit report, fit stats, and fit lines can be viewed in the Fits menu. - - S: Store Fit - Saves the fit. - Can save/load the fit to/from a file in the context menu. diff --git a/src/egui_plot_stuff/egui_horizontal_line.rs b/src/egui_plot_stuff/egui_horizontal_line.rs index a3a2020..e64d5c1 100644 --- a/src/egui_plot_stuff/egui_horizontal_line.rs +++ b/src/egui_plot_stuff/egui_horizontal_line.rs @@ -23,6 +23,7 @@ pub struct EguiHorizontalLine { pub stroke_rgb: Rgb, pub interactive_dragging: bool, + pub mid_point_radius: f32, #[serde(skip)] pub is_dragging: bool, @@ -44,6 +45,7 @@ impl Default for EguiHorizontalLine { color_rgb: Rgb::from_color32(Color32::BLUE), stroke_rgb: Rgb::from_color32(Color32::BLUE), interactive_dragging: true, + mid_point_radius: 3.0, is_dragging: false, } } @@ -89,7 +91,7 @@ impl EguiHorizontalLine { let mid_point = egui_plot::Points::new(mid_point_pos) .color(self.color) .highlight(self.highlighted) - .radius(3.0) + .radius(self.mid_point_radius) .id(Id::new(self.name.clone())); plot_ui.points(mid_point); diff --git a/src/egui_plot_stuff/egui_vertical_line.rs b/src/egui_plot_stuff/egui_vertical_line.rs index 7edbe30..56fee54 100644 --- a/src/egui_plot_stuff/egui_vertical_line.rs +++ b/src/egui_plot_stuff/egui_vertical_line.rs @@ -23,6 +23,7 @@ pub struct EguiVerticalLine { pub stroke_rgb: Rgb, pub interactive_dragging: bool, + pub mid_point_radius: f32, #[serde(skip)] pub is_dragging: bool, @@ -44,6 +45,7 @@ impl Default for EguiVerticalLine { color_rgb: Rgb::from_color32(Color32::BLUE), stroke_rgb: Rgb::from_color32(Color32::BLUE), interactive_dragging: true, + mid_point_radius: 3.0, is_dragging: false, } } @@ -89,7 +91,7 @@ impl EguiVerticalLine { let mid_point = egui_plot::Points::new(mid_point_pos) .color(self.color) .highlight(self.highlighted) - .radius(3.0) + .radius(self.mid_point_radius) .id(Id::new(self.name.clone())); plot_ui.points(mid_point); diff --git a/src/histoer/histo1d/histogram1d.rs b/src/histoer/histo1d/histogram1d.rs index bf007f3..1442f12 100644 --- a/src/histoer/histo1d/histogram1d.rs +++ b/src/histoer/histo1d/histogram1d.rs @@ -240,9 +240,7 @@ impl Histogram { self.plot_settings.cursor_position = None; } - // if self.plot_settings.egui_settings.limit_scrolling { self.limit_scrolling(plot_ui); - // } } pub fn draw_other_histograms( @@ -298,7 +296,8 @@ impl Histogram { pub fn render(&mut self, ui: &mut egui::Ui) { // Display progress bar while hist is being filled - self.plot_settings.progress_ui(ui); + // disabled since the row calculation is done in chucks + // self.plot_settings.progress_ui(ui); self.update_line_points(); // Ensure line points are updated for projections self.keybinds(ui); // Handle interactive elements @@ -323,9 +322,23 @@ impl Histogram { let plot_response = plot.show(ui, |plot_ui| { self.draw(plot_ui); - // if progress is updating, turn on the auto bounds if self.plot_settings.progress.is_some() { - plot_ui.set_auto_bounds(Vec2b::new(true, true)); + let y_max = self.bins.iter().max().cloned().unwrap_or(0) as f64; + let mut plot_bounds = plot_ui.plot_bounds(); + plot_bounds.extend_with_y(y_max * 1.1); + plot_ui.set_plot_bounds(plot_bounds); + } + + if self.plot_settings.egui_settings.reset_axis { + // let y_min = self.bins.iter().min().cloned().unwrap_or(0) as f64; + // let y_max = self.bins.iter().max().cloned().unwrap_or(0) as f64; + // let plot_bounds = egui_plot::PlotBounds::from_min_max( + // [self.range.0 * 1.1, y_min * 1.1], + // [self.range.1 * 1.1, y_max * 1.1], + // ); + // plot_ui.set_plot_bounds(plot_bounds); + plot_ui.auto_bounds(); + self.plot_settings.egui_settings.reset_axis = false; } if self.plot_settings.cursor_position.is_some() { @@ -334,6 +347,10 @@ impl Histogram { plot_ui.zoom_bounds_around_hovered(egui::Vec2::new(1.1, 1.0)); } else if delta_pos.y < 0.0 { plot_ui.zoom_bounds_around_hovered(egui::Vec2::new(0.9, 1.0)); + } else if delta_pos.x > 0.0 { + plot_ui.zoom_bounds_around_hovered(egui::Vec2::new(1.1, 1.0)); + } else if delta_pos.x < 0.0 { + plot_ui.zoom_bounds_around_hovered(egui::Vec2::new(0.9, 1.0)); } } } diff --git a/src/histoer/histo1d/plot_settings.rs b/src/histoer/histo1d/plot_settings.rs index 4197cfd..25717f0 100644 --- a/src/histoer/histo1d/plot_settings.rs +++ b/src/histoer/histo1d/plot_settings.rs @@ -39,14 +39,14 @@ impl PlotSettings { self.markers.interactive_dragging(response); } - pub fn progress_ui(&mut self, ui: &mut egui::Ui) { - if let Some(progress) = self.progress { - ui.add( - egui::ProgressBar::new(progress) - .show_percentage() - .animate(true) - .text(format!("{:.0}%", progress * 100.0)), - ); - } - } + // pub fn progress_ui(&mut self, ui: &mut egui::Ui) { + // if let Some(progress) = self.progress { + // ui.add( + // egui::ProgressBar::new(progress) + // .show_percentage() + // .animate(true) + // .text(format!("{:.0}%", progress * 100.0)), + // ); + // } + // } } diff --git a/src/histoer/histo2d/histogram2d.rs b/src/histoer/histo2d/histogram2d.rs index a2dcd90..bf536c9 100644 --- a/src/histoer/histo2d/histogram2d.rs +++ b/src/histoer/histo2d/histogram2d.rs @@ -226,6 +226,18 @@ impl Histogram2D { self.plot_settings.recalculate_image = false; } + let (scroll, _pointer_down, _modifiers) = ui.input(|i| { + let scroll = i.events.iter().find_map(|e| match e { + egui::Event::MouseWheel { + unit: _, + delta, + modifiers: _, + } => Some(*delta), + _ => None, + }); + (scroll, i.pointer.primary_down(), i.modifiers) + }); + let mut plot = egui_plot::Plot::new(self.name.clone()); plot = self.plot_settings.egui_settings.apply_to_plot(plot); @@ -238,6 +250,20 @@ impl Histogram2D { let plot_response = plot.show(ui, |plot_ui| { self.draw(plot_ui); + + if self.plot_settings.cursor_position.is_some() { + if let Some(delta_pos) = scroll { + if delta_pos.y > 0.0 { + plot_ui.zoom_bounds_around_hovered(egui::Vec2::new(1.1, 1.1)); + } else if delta_pos.y < 0.0 { + plot_ui.zoom_bounds_around_hovered(egui::Vec2::new(0.9, 0.9)); + } else if delta_pos.x > 0.0 { + plot_ui.zoom_bounds_around_hovered(egui::Vec2::new(1.1, 1.1)); + } else if delta_pos.x < 0.0 { + plot_ui.zoom_bounds_around_hovered(egui::Vec2::new(0.9, 0.9)); + } + } + } }); plot_response.response.context_menu(|ui| { diff --git a/src/histoer/histo2d/projections.rs b/src/histoer/histo2d/projections.rs index 33b216d..21b90d6 100644 --- a/src/histoer/histo2d/projections.rs +++ b/src/histoer/histo2d/projections.rs @@ -162,6 +162,7 @@ impl Histogram2D { let bins = self.x_projection(min_y, max_y); x_histogram.bins = bins.clone(); x_histogram.original_bins = bins; + x_histogram.plot_settings.egui_settings.reset_axis = true; self.plot_settings.projections.x_projection = Some(x_histogram); @@ -192,10 +193,12 @@ impl Projections { y_projection: None, y_projection_line_1: EguiVerticalLine { name: "Y Projection Line 1".to_string(), + mid_point_radius: 5.0, ..EguiVerticalLine::default() }, y_projection_line_2: EguiVerticalLine { name: "Y Projection Line 2".to_string(), + mid_point_radius: 5.0, ..EguiVerticalLine::default() }, @@ -203,46 +206,17 @@ impl Projections { x_projection: None, x_projection_line_1: EguiHorizontalLine { name: "X Projection Line 1".to_string(), + mid_point_radius: 5.0, ..EguiHorizontalLine::default() }, x_projection_line_2: EguiHorizontalLine { name: "X Projection Line 2".to_string(), + mid_point_radius: 5.0, ..EguiHorizontalLine::default() }, } } - // this pops out a new window with the y projection - - // fn show_y_projection(&mut self, ui: &mut egui::Ui) { - // if self.add_y_projection && self.y_projection.is_some() { - // ui.ctx().show_viewport_immediate( - // egui::ViewportId::from_hash_of("Y Projection".to_string()), - // egui::ViewportBuilder::default() - // .with_title(self.y_projection.as_ref().unwrap().name.clone()) - // .with_inner_size([600.0, 400.0]), - // |ctx, class| { - // assert!( - // class == egui::ViewportClass::Immediate, - // "This egui backend doesn't support multiple viewports" - // ); - - // egui::CentralPanel::default().show(ctx, |ui| { - // if let Some(histogram) = &mut self.y_projection { - // histogram.render(ui); - // } - // }); - - // if ctx.input(|i| i.viewport().close_requested()) { - // // Tell parent viewport that we should not show next frame: - // self.y_projection = None; - // self.add_y_projection = false; - // } - // }, - // ); - // } - // } - fn show_y_projection(&mut self, ui: &mut egui::Ui) { if self.add_y_projection && self.y_projection.is_some() { let name = if let Some(histogram) = &self.y_projection { diff --git a/src/histoer/histogrammer.rs b/src/histoer/histogrammer.rs index 86fa440..4bccae8 100644 --- a/src/histoer/histogrammer.rs +++ b/src/histoer/histogrammer.rs @@ -484,6 +484,11 @@ impl Histogrammer { if passes_all_cuts { hist.fill(value); } + + hist.plot_settings.progress = Some( + (row_start as f32 + index as f32) + / (df.height() as f32), + ); } } } @@ -549,6 +554,11 @@ impl Histogrammer { hist.plot_settings.recalculate_image = true; } + for hist in &hist1d_map { + let mut hist = hist.0.lock().unwrap(); + hist.plot_settings.progress = None; + } + println!("\tProcessed rows {} to {}", row_start, row_start + height); }