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
58 changes: 51 additions & 7 deletions crates/app/src/ui/canvas/image_painting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,19 +79,45 @@ pub(super) fn paint_document(
) {
let canvas = &app.doc.canvases[ci];
let mut document = canvas_document(app, ci);
let highlight = crate::ui::data_navigation::highlight(app, painter.ctx(), canvas.resource_id);
let mut outline = None;
let accent = plotium_figure::Color::rgb(221, 82, 16);
let previews: Vec<_> = canvas
.objects
.iter()
.map(|object| {
let plot = object.plot()?;
let preview = super::super::nmr_phase_preview::contours(
app,
painter.ctx(),
object.dataset()?,
object.id,
)?;
let preview = object.dataset().and_then(|dataset| {
super::super::nmr_phase_preview::contours(app, painter.ctx(), dataset, object.id)
});
let target = highlight.filter(|target| target.plot == object.id);
if preview.is_none() && target.is_none() {
return None;
}
let mut figure = plot.figure().clone();
figure.contours = preview.contours.clone();
if let Some(preview) = preview {
figure.contours = preview.contours.clone();
}
if let Some(target) = target {
let origin = Some(plotium_figure::SeriesOrigin(target.series.get()));
let mut accented = false;
for series in figure.series.iter_mut().filter(|s| s.origin == origin) {
accented = true;
series.color = accent;
series.width = (series.width * 2.0).max(2.0);
series.appearance.marker_fill = Some(accent);
}
for contour in figure.contours.iter_mut().filter(|s| s.origin == origin) {
accented = true;
contour.color = accent;
contour.width = (contour.width * 2.0).max(2.0);
}
if !accented {
outline = canvas
.content_page_frame(object.id)
.map(|frame| frame.rect());
}
}
Some(figure)
})
.collect();
Expand All @@ -117,6 +143,24 @@ pub(super) fn paint_document(
},
detail,
);
if let Some(frame) = outline {
let transform = BoardTransform::from_board(app.session.board, rect);
let screen = transform.board_rect_screen(PlotRect::new(
bp[0] + frame.left,
bp[1] + frame.top,
frame.width,
frame.height,
));
painter.rect_stroke(
screen,
0.0,
egui::Stroke::new(
4.0_f32,
egui::Color32::from_rgb(accent.r, accent.g, accent.b),
),
egui::StrokeKind::Inside,
);
}
}

fn loading_image_placeholder(
Expand Down
15 changes: 15 additions & 0 deletions crates/app/src/ui/command_exec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,21 @@ fn execute_inner(
}
CommandId::ImportTable => super::file_dialogs::import_delimited_table(app),
CommandId::ImportResults => super::import_feedback::open_results(app, ctx, None),
CommandId::EditDatasetMetadata(dataset) => super::dataset_editor::open(app, ctx, dataset),
CommandId::LocateDatasetPlot(dataset) => {
if let Some(dataset) = dataset.or_else(|| {
app.active_dataset()
.and_then(|i| app.doc.datasets.get(i))
.map(|d| d.resource_id())
}) {
app.session.primary_sidebar_visible = true;
app.session.view = plotium_core::state::PrimaryView::Data;
super::data_navigation::locate_dataset(app, ctx, dataset);
}
}
CommandId::GoToDatasetPlot(target) => super::data_navigation::navigate(app, ctx, target),
CommandId::RevealDatasetPlot(target) => super::data_navigation::reveal(app, ctx, target),
CommandId::ViewImportBatch(batch) => super::import_feedback::view_batch(app, ctx, batch),
CommandId::RetryImportBatch(batch) => {
if let Some(retry) = app.retry_failed_import(batch) {
super::import_feedback::open_results(app, ctx, Some(retry));
Expand Down
20 changes: 13 additions & 7 deletions crates/app/src/ui/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ pub enum CommandId {
HelpManual,
ImportTable,
ImportResults,
EditDatasetMetadata(Option<plotium_core::state::DatasetId>),
LocateDatasetPlot(Option<plotium_core::state::DatasetId>),
GoToDatasetPlot(super::data_navigation::Destination),
RevealDatasetPlot(super::data_navigation::Destination),
ViewImportBatch(plotium_core::state::ImportBatchId),
RetryImportBatch(plotium_core::state::ImportBatchId),
RecomputeScientificTask(plotium_core::state::ActivityId),
ImportImage,
Expand Down Expand Up @@ -198,13 +203,12 @@ pub struct CommandDescriptor {
pub fn catalog(app: &PlotiumApp) -> Vec<CommandDescriptor> {
command_ids(app.session.recent_files.len())
.into_iter()
.chain(
app.session
.data_imports
.batches()
.iter()
.map(|batch| CommandId::RetryImportBatch(batch.id)),
)
.chain(app.session.data_imports.batches().iter().flat_map(|batch| {
[
CommandId::RetryImportBatch(batch.id),
CommandId::ViewImportBatch(batch.id),
]
}))
.chain(super::scientific_task_feedback::commands(app))
.map(|id| {
debug_assert!(!id.stable_id().is_empty());
Expand Down Expand Up @@ -286,6 +290,8 @@ pub fn describe(app: &PlotiumApp, id: CommandId) -> CommandDescriptor {
!app.session.data_imports.batches().is_empty(),
"Import data before viewing import results.",
),
CommandId::EditDatasetMetadata(_) | CommandId::LocateDatasetPlot(_) | CommandId::GoToDatasetPlot(_)
| CommandId::RevealDatasetPlot(_) | CommandId::ViewImportBatch(_) => helpers::data_navigation_gate(app, id),
CommandId::RetryImportBatch(batch) => requires(
app.session.data_imports.batches().iter().any(|item| {
item.id == batch
Expand Down
26 changes: 26 additions & 0 deletions crates/app/src/ui/commands/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,3 +166,29 @@ pub(super) fn palette_available(app: &PlotiumApp, id: super::CommandId) -> bool
&& app.session.ui.trace_composer.is_none()
&& !app.session.ui.interaction.is_active())
}

pub(super) fn data_navigation_gate(app: &PlotiumApp, id: CommandId) -> Result<(), &'static str> {
match id {
CommandId::EditDatasetMetadata(Some(dataset)) => requires(
app.doc.dataset_index(dataset).is_some(),
"Choose an available dataset.",
),
CommandId::EditDatasetMetadata(None) | CommandId::LocateDatasetPlot(None) => requires(
app.active_dataset().is_some(),
"Select data in the Data List first.",
),
CommandId::LocateDatasetPlot(Some(_)) => Ok(()),
CommandId::GoToDatasetPlot(target) => requires(
target.hidden(app).is_some(),
"Choose an available plot series.",
),
CommandId::RevealDatasetPlot(target) => requires(
target.hidden(app) == Some(true),
"Choose a hidden plot series to reveal.",
),
CommandId::ViewImportBatch(batch) => {
crate::ui::import_feedback::view_batch_gate(app, batch)
}
_ => unreachable!("not a data navigation command"),
}
}
15 changes: 15 additions & 0 deletions crates/app/src/ui/commands/identity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ impl CommandId {
pub fn stable_id(self) -> String {
match self {
Self::OpenRecent(i) => format!("file.open_recent.{i}"),
Self::EditDatasetMetadata(_) => "data.edit_metadata".into(),
Self::LocateDatasetPlot(_) => "data.locate_plot".into(),
Self::GoToDatasetPlot(_) => "data.go_to_plot".into(),
Self::RevealDatasetPlot(_) => "data.reveal_plot".into(),
Self::ViewImportBatch(id) => format!("file.view_import.{id}"),
Self::RetryImportBatch(id) => format!("file.retry_import.{id}"),
Self::RecomputeScientificTask(id) => format!("analysis.recompute_task.{}", id.0),
Self::NewCanvas(i) => format!("file.new_canvas.{i}"),
Expand Down Expand Up @@ -81,6 +86,16 @@ pub(super) fn command_identity(
CommandId::HelpManual => plain("User Manual", Some(icon::BOOK_OPEN)),
CommandId::ImportTable => plain("Import Table…", Some(icon::FILE_CSV)),
CommandId::ImportResults => plain("Import Results", Some(icon::LIST_CHECKS)),
CommandId::EditDatasetMetadata(_) => plain("Edit experiment and tags…", None),
CommandId::LocateDatasetPlot(_) => plain("Locate plot", None),
CommandId::GoToDatasetPlot(target) => plain(
&target
.label(app)
.unwrap_or_else(|| "Plot unavailable".into()),
None,
),
CommandId::RevealDatasetPlot(_) => plain("Reveal", None),
CommandId::ViewImportBatch(id) => plain(&format!("View this import — Batch {id}"), None),
CommandId::RetryImportBatch(id) => plain(
&format!("Retry Failed Imports — Batch {id}"),
Some(icon::ARROWS_CLOCKWISE),
Expand Down
2 changes: 2 additions & 0 deletions crates/app/src/ui/commands/roster.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ pub(super) fn command_ids(recent_files: usize) -> Vec<CommandId> {
CommandId::ImportTiffPages,
CommandId::PasteImage,
CommandId::CancelDataImport,
CommandId::EditDatasetMetadata(None),
CommandId::LocateDatasetPlot(None),
CommandId::CancelImageImport,
CommandId::ReplaceImage,
CommandId::PasteTable,
Expand Down
Loading
Loading