Skip to content

Commit

Permalink
new workspacer handling and lazyframer
Browse files Browse the repository at this point in the history
	modified:   Cargo.lock
	modified:   Cargo.toml
	modified:   src/app.rs
	modified:   src/cutter/cut_handler.rs
	modified:   src/egui_plot_stuff/egui_line.rs
	modified:   src/lazyframer.rs
	modified:   src/pane.rs
	modified:   src/processer.rs
	modified:   src/tree.rs
	modified:   src/workspacer.rs
  • Loading branch information
alconley committed Jul 5, 2024
1 parent 01a84ac commit 3eb6deb
Show file tree
Hide file tree
Showing 10 changed files with 288 additions and 114 deletions.
32 changes: 16 additions & 16 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ all-features = true
targets = ["x86_64-unknown-linux-gnu", "wasm32-unknown-unknown"]

[dependencies]
egui = "0.28"
eframe = { version = "0.28", default-features = false, features = [
egui = "0.28.1"
eframe = { version = "0.28.1", default-features = false, features = [
"default_fonts", # Embed the default egui fonts.
"glow", # Use the glow rendering backend. Alternative: "wgpu".
"persistence", # Enable restoring app state when restarting the app.
Expand All @@ -21,9 +21,9 @@ log = "0.4"
# You only need serde if you want app persistence:
serde = { version = "1", features = ["derive"] }

egui_plot = {version = "0.28", features = ["serde"] }
egui_plot = {version = "0.28.1", features = ["serde"] }
egui_tiles = "0.9.0"
epaint = "0.28"
epaint = "0.28.1"

# native:
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
Expand Down
46 changes: 11 additions & 35 deletions src/app.rs
Original file line number Diff line number Diff line change
@@ -1,30 +1,23 @@
use super::pane::Pane;
use super::tree::TreeBehavior;

use super::processer::Processer;
use super::workspacer::Workspacer;
use super::tree::TreeBehavior;

#[derive(serde::Deserialize, serde::Serialize)]
#[serde(default)] // if we add new fields, give them default values when deserializing old state
pub struct NATApp {
tree: egui_tiles::Tree<Pane>,
workspacer: Workspacer,
processer: Processer,
behavior: TreeBehavior,
side_panel_open: bool,
}

impl Default for NATApp {
fn default() -> Self {
let workspacer = Workspacer::new();
let processer = Processer::new();

let tree = egui_tiles::Tree::empty("Empty tree");

Self {
tree,
workspacer,
processer,
processer: Processer::new(),
behavior: Default::default(),
side_panel_open: true,
}
Expand All @@ -42,9 +35,11 @@ impl NATApp {
Default::default()
}

fn add_histograms_to_tree(&mut self) {
fn add_histograms_to_tree_from_processer(&mut self) {
self.tree = self.processer.histogrammer.histogrammer_tree();
self.behavior.tile_map.clone_from(&self.processer.histogrammer.tile_map);
self.behavior
.tile_map
.clone_from(&self.processer.histogrammer.tile_map);
}
}

Expand Down Expand Up @@ -76,34 +71,17 @@ impl eframe::App for NATApp {

ui.separator();

if !self.workspacer.selected_files.borrow().is_empty() {
// Properly clone the shared state for processing
self.processer
.files
.clone_from(&self.workspacer.selected_files.borrow());

if ui.button("Calculate Histograms").clicked() {
self.processer.calculate_histograms();
self.add_histograms_to_tree();
}

if ui.button("Calculate Histograms with Cuts").clicked() {
self.processer.calculate_histograms_with_cuts();
self.add_histograms_to_tree();
}

self.processer.ui(ui);
self.processer.ui(ui);

ui.separator();
// check to see if processer.is_ready -> get the tree from the histogrammer
if self.processer.is_ready {
self.add_histograms_to_tree_from_processer();
self.processer.is_ready = false;
}

egui::ScrollArea::vertical()
.id_source("LeftPanel")
.show(ui, |ui| {
self.workspacer.workspace_ui(ui);

ui.separator();

self.behavior.ui(ui);

// ui.collapsing("Tree", |ui| {
Expand All @@ -123,8 +101,6 @@ impl eframe::App for NATApp {
// }
// });

ui.separator();

if let Some(root) = self.tree.root() {
tree_ui(ui, &mut self.behavior, &mut self.tree.tiles, root);
}
Expand Down
2 changes: 2 additions & 0 deletions src/cutter/cut_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ impl CutHandler {
}
});
}

ui.separator();
}

pub fn filter_lf_with_selected_cuts(
Expand Down
1 change: 1 addition & 0 deletions src/egui_plot_stuff/egui_line.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ impl EguiLine {
ui.checkbox(&mut self.highlighted, "Highlighted");

self.color_selection_buttons(ui);
// ui.color_edit_button_srgba(&mut self.color); // add this when the bug is fixed
ui.add(Slider::new(&mut self.width, 0.0..=10.0).text("Line Width"));

// self.stroke_color_selection_buttons(ui);
Expand Down
28 changes: 21 additions & 7 deletions src/lazyframer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ impl LazyFramer {
self.columns.clone()
}

// Adjusted signature to match context
pub fn get_column_names_from_lazyframe(lazyframe: &LazyFrame) -> Vec<String> {
let lf: LazyFrame = lazyframe.clone().limit(1);
let df: DataFrame = lf.collect().unwrap();
Expand Down Expand Up @@ -79,12 +78,6 @@ impl LazyFramer {
pub fn ui(&mut self, ui: &mut egui::Ui) {
ui.heading("LazyFrame");

ui.horizontal(|ui| {
ui.label("Columns:");
ui.separator();
ui.label(format!("{:?}", self.columns));
});

if ui.button("Save LazyFrame").clicked() {
if let Some(_lf) = &self.lazyframe {
let output_path = rfd::FileDialog::new()
Expand All @@ -103,5 +96,26 @@ impl LazyFramer {
}
}
}

ui.label("Columns:");
if self.columns.is_empty() {
ui.label("No columns");
if let Some(lf) = &self.lazyframe {
if ui.button("Get Columns").clicked() {
self.columns = Self::get_column_names_from_lazyframe(lf);
}
}
} else {
egui::ScrollArea::vertical()
.max_height(100.0)
.id_source("LazyframerColumnNameScrollArea")
.show(ui, |ui| {
for column in &self.columns {
ui.label(column);
}
});
}

ui.separator();
}
}
6 changes: 0 additions & 6 deletions src/pane.rs
Original file line number Diff line number Diff line change
@@ -1,21 +1,15 @@
use super::histoer::histogram1d::Histogram;
use super::histoer::histogram2d::Histogram2D;
use crate::workspacer::Workspacer;

#[derive(Clone, serde::Serialize, serde::Deserialize)]
pub enum Pane {
Workspace(Workspacer),
Histogram(Box<Histogram>),
Histogram2D(Box<Histogram2D>),
}

impl Pane {
pub fn ui(&mut self, ui: &mut egui::Ui) -> egui_tiles::UiResponse {
match self {
Pane::Workspace(workspace) => {
workspace.workspace_ui(ui);
}

Pane::Histogram(hist) => {
hist.render(ui);
}
Expand Down
44 changes: 32 additions & 12 deletions src/processer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,32 @@ use super::cutter::cut_handler::CutHandler;
use super::histoer::histogram_script::add_histograms;
use super::histoer::histogrammer::Histogrammer;
use super::lazyframer::LazyFramer;

use std::path::PathBuf;
use super::workspacer::Workspacer;

#[derive(Default, serde::Deserialize, serde::Serialize)]
pub struct Processer {
pub workspacer: Workspacer,
#[serde(skip)]
pub lazyframer: Option<LazyFramer>,
pub files: Vec<PathBuf>,
pub histogrammer: Histogrammer,
pub cut_handler: CutHandler,
pub histogrammer: Histogrammer,
#[serde(skip)]
pub is_ready: bool,
}

impl Processer {
pub fn new() -> Self {
Self {
workspacer: Workspacer::default(),
lazyframer: None,
files: Vec::new(),
histogrammer: Histogrammer::new(),
cut_handler: CutHandler::default(),
histogrammer: Histogrammer::new(),
is_ready: false,
}
}

fn create_lazyframe(&mut self) {
self.lazyframer = Some(LazyFramer::new(self.files.clone()));
self.lazyframer = Some(LazyFramer::new(self.workspacer.selected_files.clone()));
}

fn perform_histogrammer_from_lazyframe(&mut self) {
Expand All @@ -50,6 +52,7 @@ impl Processer {
pub fn calculate_histograms(&mut self) {
self.create_lazyframe();
self.perform_histogrammer_from_lazyframe();
self.is_ready = true;
}

pub fn calculate_histograms_with_cuts(&mut self) {
Expand All @@ -60,6 +63,7 @@ impl Processer {
Ok(filtered_lf) => {
lazyframer.set_lazyframe(filtered_lf);
self.perform_histogrammer_from_lazyframe();
self.is_ready = true;
}
Err(e) => {
log::error!("Failed to filter LazyFrame with cuts: {}", e);
Expand All @@ -68,7 +72,7 @@ impl Processer {
}
}

self.perform_histogrammer_from_lazyframe();
// self.perform_histogrammer_from_lazyframe();
}

pub fn save_current_lazyframe(&mut self) {
Expand All @@ -89,12 +93,28 @@ impl Processer {
}

pub fn ui(&mut self, ui: &mut egui::Ui) {
// if let Some(lazyframer) = &mut self.lazyframer {
// lazyframer.ui(ui);
// }
if !self.workspacer.selected_files.is_empty() {
// Properly clone the shared state for processing

ui.separator();
ui.horizontal(|ui| {
if ui.button("Calculate Histograms").clicked() {
self.calculate_histograms();
}

if !self.cut_handler.cuts.is_empty() && ui.button("with Cuts").clicked() {
self.calculate_histograms_with_cuts();
}
});

ui.separator();
}

self.workspacer.workspace_ui(ui);

self.cut_handler.cut_ui(ui);

if let Some(lazyframer) = &mut self.lazyframer {
lazyframer.ui(ui);
}
}
}
Loading

0 comments on commit 3eb6deb

Please sign in to comment.