From 5817f702bacbd0637673bea2b2d68dde453d22df Mon Sep 17 00:00:00 2001 From: the_a Date: Sat, 14 Dec 2024 14:09:46 -0500 Subject: [PATCH] Added a scroll bar to display all AB1 data --- src/gui/ab1.rs | 50 +++++++++++++++++++++++++++++++++----------------- src/main.rs | 2 ++ 2 files changed, 35 insertions(+), 17 deletions(-) diff --git a/src/gui/ab1.rs b/src/gui/ab1.rs index 75128a8..e5aabc9 100644 --- a/src/gui/ab1.rs +++ b/src/gui/ab1.rs @@ -4,7 +4,7 @@ use copypasta::{ClipboardContext, ClipboardProvider}; use eframe::{ egui::{ pos2, vec2, Align2, Color32, FontFamily, FontId, Frame, Pos2, Rect, RichText, Sense, Shape, - Stroke, Ui, + Slider, Stroke, Ui, }, emath::RectTransform, epaint::PathShape, @@ -47,16 +47,16 @@ fn nt_color_map(nt: Nucleotide) -> Color32 { /// Map sequence index to a horizontal pixel. fn index_to_posit(i: usize, num_nts: usize, ui: &Ui) -> f32 { // todo: Cap if width too small for nt len. Varying zoom, etc. - let width = ui.available_width(); - - let num_nts_disp = width / NT_WIDTH; + // let width = ui.available_width(); + // + // let num_nts_disp = width / NT_WIDTH; // let scale_factor = width / num_nts as f32; i as f32 * NT_WIDTH } /// Plot the peaks and confidence values; draw letters -fn plot(data: &SeqRecordAb1, to_screen: &RectTransform, ui: &mut Ui) -> Vec { +fn plot(data: &SeqRecordAb1, to_screen: &RectTransform, start_i: usize, ui: &mut Ui) -> Vec { let mut result = Vec::new(); let nt_y = 160.; @@ -86,20 +86,25 @@ fn plot(data: &SeqRecordAb1, to_screen: &RectTransform, ui: &mut Ui) -> Vec 400 { - // todo: Sloppy performance saver. - continue; + for i_pos in 0..num_nts_disp as usize { + let i = start_i + i_pos; + if i > data.sequence.len() - 1 { + break; } - let x_pos = index_to_posit(i, data.sequence.len(), ui); + let nt = data.sequence[i]; + + let x_pos = index_to_posit(i_pos, data.sequence.len(), ui); if x_pos > ui.available_width() - 15. { continue; // todo: QC the details, if you need to_screen here etc. } - let nt_color = nt_color_map(*nt); + let nt_color = nt_color_map(nt); result.push(ui.ctx().fonts(|fonts| { Shape::text( @@ -117,13 +122,13 @@ fn plot(data: &SeqRecordAb1, to_screen: &RectTransform, ui: &mut Ui) -> Vec 2_000 { - // todo: Sloppy performance saver. - continue; + for i_pos in 0..num_nts_disp as usize * 4 { + let i = start_i * 4 + i_pos; + if i > data.data_ch1.len() - 1 { + break; } - let x_pos = index_to_posit(i, data.sequence.len(), ui) / 4.; + let x_pos = index_to_posit(i_pos, data.sequence.len(), ui) / 4.; if x_pos > ui.available_width() - 15. { continue; // todo: QC the details, if you need to_screen here etc. } @@ -226,6 +231,17 @@ pub fn ab1_page(state: &mut State, ui: &mut Ui) { }); ui.add_space(ROW_SPACING / 2.); + let data = &state.ab1_data[state.active]; + let width = ui.available_width(); + let num_nts_disp = width / NT_WIDTH; + ui.spacing_mut().slider_width = width - 60.; + ui.add(Slider::new( + &mut state.ui.ab1_start_i, + 0..=data.sequence.len() - num_nts_disp as usize + 1, + )); + + ui.add_space(ROW_SPACING / 2.); + let mut shapes = Vec::new(); Frame::canvas(ui.style()) @@ -246,7 +262,7 @@ pub fn ab1_page(state: &mut State, ui: &mut Ui) { let rect_size = response.rect.size(); - shapes.append(&mut plot(data, &to_screen, ui)); + shapes.append(&mut plot(data, &to_screen, state.ui.ab1_start_i, ui)); ui.painter().extend(shapes); }); diff --git a/src/main.rs b/src/main.rs index 195c226..73bcc43 100644 --- a/src/main.rs +++ b/src/main.rs @@ -198,6 +198,7 @@ struct StateUi { re: ReUi, backbone_filters: BackboneFilters, seq_edit_lock: bool, + ab1_start_i: usize, } impl Default for StateUi { @@ -235,6 +236,7 @@ impl Default for StateUi { re: Default::default(), backbone_filters: Default::default(), seq_edit_lock: true, + ab1_start_i: Default::default(), } } }