mirror of https://github.com/terhechte/postsack
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
58 lines
1.9 KiB
Rust
58 lines
1.9 KiB
Rust
3 years ago
|
use eframe::egui::{self, Widget};
|
||
|
use eyre::Report;
|
||
3 years ago
|
use ps_core::model::{segmentations, Engine};
|
||
3 years ago
|
|
||
|
pub struct SegmentationBar<'a> {
|
||
|
engine: &'a mut Engine,
|
||
|
error: &'a mut Option<Report>,
|
||
|
}
|
||
|
|
||
|
impl<'a> SegmentationBar<'a> {
|
||
|
pub fn new(engine: &'a mut Engine, error: &'a mut Option<Report>) -> Self {
|
||
|
Self { engine, error }
|
||
|
}
|
||
|
}
|
||
|
|
||
|
impl<'a> Widget for SegmentationBar<'a> {
|
||
|
fn ui(self, ui: &mut egui::Ui) -> egui::Response {
|
||
|
ui.horizontal(|ui| {
|
||
|
ui.set_height(30.0);
|
||
|
|
||
3 years ago
|
ui.label("Group By:");
|
||
|
|
||
3 years ago
|
let groupings = segmentations::aggregated_by(self.engine);
|
||
|
let has_back = groupings.len() > 1;
|
||
|
for (id_index, group) in groupings.iter().enumerate() {
|
||
|
let alternatives = segmentations::aggregation_fields(self.engine, group);
|
||
|
if let Some(value) = group.value() {
|
||
3 years ago
|
ui.add_enabled(
|
||
|
false,
|
||
|
egui::Button::new(format!("{} {}", group.name(), value))
|
||
|
.text_color(egui::Color32::WHITE),
|
||
|
);
|
||
3 years ago
|
} else if let Some(mut selected) = group.index(&alternatives) {
|
||
|
let p = egui::ComboBox::from_id_source(&id_index).show_index(
|
||
|
ui,
|
||
|
&mut selected,
|
||
|
alternatives.len(),
|
||
3 years ago
|
|i| alternatives[i].name().to_string(),
|
||
3 years ago
|
);
|
||
|
if p.changed() {
|
||
|
*self.error = segmentations::set_aggregation(
|
||
|
self.engine,
|
||
|
group,
|
||
|
&alternatives[selected],
|
||
|
)
|
||
|
.err();
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
3 years ago
|
if has_back && ui.button("\u{2716}").clicked() {
|
||
3 years ago
|
self.engine.pop();
|
||
|
}
|
||
|
})
|
||
|
.response
|
||
|
}
|
||
|
}
|