Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions crates/app/src/ui/canvas/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -635,6 +635,7 @@ mod tests {
Figure::new("plot", Axis::new("x", 0.0, 1.0), Axis::new("y", 0.0, 1.0));
let viewport = CanvasViewport::from_figure(&figure);
PlotObject::new(
None,
plotx_core::state::SeriesId::new(1),
plotx_core::state::DataBinding { series: Vec::new() },
plotx_core::state::ChartSpec::default(),
Expand Down Expand Up @@ -669,6 +670,7 @@ mod tests {
Figure::new("plot", Axis::new("x", 0.0, 1.0), Axis::new("y", 0.0, 1.0));
let viewport = CanvasViewport::from_figure(&figure);
PlotObject::new(
None,
plotx_core::state::SeriesId::new(1),
plotx_core::state::DataBinding { series: Vec::new() },
plotx_core::state::ChartSpec::default(),
Expand Down
1 change: 1 addition & 0 deletions crates/app/src/ui/canvas/navigation_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ fn zoomed_plot_fixture() -> (PlotxApp, ObjectId, PlotRect) {
visible: true,
group: None,
kind: CanvasObjectKind::Plot(Box::new(PlotObject::new(
None,
plotx_core::state::SeriesId::new(1),
plotx_core::state::DataBinding { series: Vec::new() },
plotx_core::state::ChartSpec::default(),
Expand Down
2 changes: 1 addition & 1 deletion crates/app/src/ui/object_inspector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use geometry::geometry_section;
use plotx_core::actions::{Action, PendingInspectorEdit};
use plotx_core::state::{
CanvasObject, DataBinding, Dataset, MM_TO_PT, OVERLAY_PALETTE, ObjectFrame, ObjectId, PlotxApp,
SeriesBinding, StackSpec,
StackSpec,
};
use plotx_figure::Color;

Expand Down
123 changes: 93 additions & 30 deletions crates/app/src/ui/object_inspector/data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,52 @@ use super::*;
/// Binding edits rebuild through `SetDataBinding`; stack-layout edits through
/// `SetStackSpec`.
pub(super) fn data_section(app: &mut PlotxApp, ci: usize, object: ObjectId, ui: &mut Ui) {
let Some((binding, stack)) = app.doc.canvases[ci]
let Some((persisted_binding, display_owner, stack)) = app.doc.canvases[ci]
.object(object)
.and_then(|o| o.plot())
.map(|p| (p.binding.clone(), p.stack))
.map(|p| (p.binding.clone(), p.display_owner, p.stack))
else {
return;
};
let binding = app.display_binding(display_owner, &persisted_binding);

let is_stack = binding.series.len() > 1 && app.series_stackable(&binding);
let multiple_datasets = binding.dataset_ids().len() > 1;
let count = binding.series.len();
let mut next_binding: Option<DataBinding> = None;
let mut next_stack: Option<StackSpec> = None;
if is_stack {
ui.horizontal(|ui| {
if ui
.add_enabled(
binding.series.iter().any(|series| !series.visible),
egui::Button::new("Show all"),
)
.clicked()
{
let mut b = binding.clone();
for series in &mut b.series {
series.visible = true;
}
next_binding = Some(b);
}
if ui
.add_enabled(
binding.series.iter().any(|series| series.visible),
egui::Button::new("Hide all"),
)
.clicked()
{
let mut b = binding.clone();
for series in &mut b.series {
series.visible = false;
}
next_binding = Some(b);
}
});
}
for (i, sb) in binding.series.iter().enumerate() {
let item_options = app.series_item_options(sb);
ui.horizontal(|ui| {
if is_stack {
let mut visible = sb.visible;
Expand All @@ -39,12 +72,17 @@ pub(super) fn data_section(app: &mut PlotxApp, ci: usize, object: ObjectId, ui:
.primary_color()
.unwrap_or(OVERLAY_PALETTE[i % OVERLAY_PALETTE.len()]);
swatch(ui, color);
let name = app
.doc
.dataset_index(sb.source.resource)
.and_then(|index| app.doc.datasets.get(index))
.map(Dataset::display_name)
.unwrap_or_default();
let item_name = app.series_label(sb);
let name = if multiple_datasets {
let dataset = app
.doc
.dataset_by_id(sb.source.resource)
.map(Dataset::display_name)
.unwrap_or_default();
format!("{dataset} — {item_name}")
} else {
item_name
};
let label = if i == 0 {
format!("{name} (primary)")
} else {
Expand All @@ -64,6 +102,23 @@ pub(super) fn data_section(app: &mut PlotxApp, ci: usize, object: ObjectId, ui:
} else {
ui.label(label);
}
if item_options.len() > 1 {
egui::ComboBox::from_id_salt(("object_series_item", object, sb.id))
.selected_text("Choose trace…")
.show_ui(ui, |ui| {
for (item, option_label) in &item_options {
if ui
.selectable_label(sb.source.item == Some(*item), option_label)
.clicked()
{
let mut b = binding.clone();
b.series[i].source.item = Some(*item);
next_binding = Some(b);
ui.close();
}
}
});
}
ui.with_layout(egui::Layout::right_to_left(egui::Align::Center), |ui| {
if count > 1 && ui.small_button(icon::X).on_hover_text("Remove").clicked() {
let mut b = binding.clone();
Expand Down Expand Up @@ -115,39 +170,41 @@ pub(super) fn data_section(app: &mut PlotxApp, ci: usize, object: ObjectId, ui:
}

let candidates = app.stack_candidates(&binding);
if binding
.primary_dataset()
.and_then(|id| app.doc.dataset_by_id(id))
.map(Dataset::domain)
.is_some_and(|d| d.stack_kind().is_some())
{
if app.series_stackable(&binding) {
if candidates.is_empty() {
ui.weak("No other datasets to stack.");
} else {
egui::ComboBox::from_id_salt("object_add_series")
.selected_text("Add series…")
.show_ui(ui, |ui| {
for di in &candidates {
let label = app.doc.datasets[*di].display_name();
let dataset_name = app.doc.datasets[*di].display_name();
let options = app.stack_candidate_series_options(&binding, *di);
let label = if options.len() > 1 {
format!("{dataset_name} — All traces ({})", options.len())
} else {
dataset_name
};
if ui.selectable_label(false, label).clicked() {
let mut b = binding.clone();
let Some(series_id) = app
.doc
.canvases
.get_mut(ci)
.and_then(|canvas| canvas.object_mut(object))
.and_then(|object| object.plot_mut())
.map(|plot| plot.allocate_series_id())
else {
continue;
};
if let Some(mut series) =
SeriesBinding::from_dataset(&app.doc.datasets[*di])
{
for mut series in options {
let color = app.next_stack_color(&b);
let Some(series_id) = app
.doc
.canvases
.get_mut(ci)
.and_then(|canvas| canvas.object_mut(object))
.and_then(|object| object.plot_mut())
.map(|plot| plot.allocate_series_id())
else {
continue;
};
series.id = series_id;
series.set_primary_color(color);
b.series.push(series);
next_binding = Some(b);
}
next_binding = Some(b);
ui.close();
}
}
});
Expand All @@ -159,7 +216,13 @@ pub(super) fn data_section(app: &mut PlotxApp, ci: usize, object: ObjectId, ui:
if let Some(after) = next_binding
&& after != binding
{
app.execute_action(Action::set_data_binding(ci, object, binding, after));
let after = app.merge_display_binding(display_owner, &persisted_binding, after);
app.execute_action(Action::set_data_binding(
ci,
object,
persisted_binding,
after,
));
app.session.status = "Updated plot data.".to_owned();
} else if let Some(after) = next_stack
&& after != stack
Expand Down
42 changes: 35 additions & 7 deletions crates/app/src/ui/tools/electrophysiology.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ pub(super) fn electrophysiology_group(app: &mut PlotxApp, di: usize, ui: &mut Ui
return false;
};
let mut dirty = false;
let mut invocation_changed = false;

ui.label(crate::typography::headline("Recording"));
ui.label(format!(
Expand All @@ -37,6 +38,7 @@ pub(super) fn electrophysiology_group(app: &mut PlotxApp, di: usize, ui: &mut Ui
ui.colored_label(ui.visuals().warn_fg_color, warning);
}
}
let mut selected_channel = recording.selected_channel;
ComboBox::from_label("Recorded channel")
.selected_text(
recording
Expand All @@ -50,31 +52,54 @@ pub(super) fn electrophysiology_group(app: &mut PlotxApp, di: usize, ui: &mut Ui
for (index, channel) in recording.data.channels.iter().enumerate() {
dirty |= ui
.selectable_value(
&mut recording.selected_channel,
&mut selected_channel,
index,
format!("{} ({})", channel.name, channel.unit.symbol),
)
.changed();
}
});
recording.set_selected_channel(selected_channel);

ui.separator();
ui.label(crate::typography::headline("Sweeps"));
let item_ids = recording
.trace_items()
.iter()
.map(|item| item.id)
.collect::<Vec<_>>();
let mut selected_ids = recording
.invocation
.analysis_selection
.clone()
.unwrap_or_else(|| item_ids.clone());
ui.horizontal(|ui| {
if ui.button("Select all").clicked() {
recording.selected_sweeps.fill(true);
dirty = true;
selected_ids.clone_from(&item_ids);
invocation_changed = true;
}
if ui.button("Clear").clicked() {
recording.selected_sweeps.fill(false);
dirty = true;
selected_ids.clear();
invocation_changed = true;
}
});
ui.horizontal_wrapped(|ui| {
for (index, selected) in recording.selected_sweeps.iter_mut().enumerate() {
dirty |= ui.checkbox(selected, (index + 1).to_string()).changed();
for (index, item) in item_ids.iter().enumerate() {
let mut selected = selected_ids.contains(item);
if ui
.checkbox(&mut selected, (index + 1).to_string())
.changed()
{
if selected {
selected_ids.push(*item);
} else {
selected_ids.retain(|id| id != item);
}
invocation_changed = true;
}
}
});
recording.invocation.analysis_selection = Some(selected_ids);

ui.separator();
ui.label(crate::typography::headline("Processing"));
Expand Down Expand Up @@ -245,6 +270,9 @@ pub(super) fn electrophysiology_group(app: &mut PlotxApp, di: usize, ui: &mut Ui
Err(error) => app.session.status = error.to_string(),
}
}
if invocation_changed {
app.apply_electrophysiology_invocation_edit(di);
}
dirty
}

Expand Down
5 changes: 3 additions & 2 deletions crates/core/src/actions/app_impl/axis_overrides.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ impl PlotxApp {
after: &AxisOverrides,
) {
let after = after.clone().normalized();
let Some((before, binding, chart, stack, projections, frame)) = self
let Some((before, owner, binding, chart, stack, projections, frame)) = self
.doc
.canvases
.get(canvas)
Expand All @@ -80,6 +80,7 @@ impl PlotxApp {
object.plot().map(|plot| {
(
plot.axis_overrides.clone(),
plot.display_owner,
plot.binding.clone(),
plot.chart.clone(),
plot.stack,
Expand Down Expand Up @@ -117,7 +118,7 @@ impl PlotxApp {
frame.width / crate::state::MM_TO_PT,
frame.height / crate::state::MM_TO_PT,
];
self.build_object_figure(&binding, &chart, &stack, &projections, size)
self.build_object_figure(owner, &binding, &chart, &stack, &projections, size)
});

let Some(plot) = self
Expand Down
Loading
Loading