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: 1 addition & 1 deletion crates/app/src/ui/canvas/interactions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ pub(crate) fn finish_zoom_drag(

let mut after = before.clone();
after.select(fig, x, y);
app.execute_action(Action::set_object_viewport(ci, object_id, before, after));
app.commit_object_viewport(ci, object_id, before, after);
app.session.status = "Zoomed selection.".into();
}

Expand Down
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 @@ -548,6 +548,7 @@ mod tests {
chart: plotx_core::state::ChartSpec::default(),
stack: plotx_core::state::StackSpec::default(),
projections: plotx_core::state::AxisProjections::default(),
axis_overrides: plotx_core::state::AxisOverrides::default(),
figure: Figure::new("plot", Axis::new("x", 0.0, 1.0), Axis::new("y", 0.0, 1.0)),
viewport: CanvasViewport::from_figure(&Figure::new(
"plot",
Expand Down Expand Up @@ -579,6 +580,7 @@ mod tests {
chart: plotx_core::state::ChartSpec::default(),
stack: plotx_core::state::StackSpec::default(),
projections: plotx_core::state::AxisProjections::default(),
axis_overrides: plotx_core::state::AxisOverrides::default(),
figure: Figure::new("plot", Axis::new("x", 0.0, 1.0), Axis::new("y", 0.0, 1.0)),
viewport: CanvasViewport::from_figure(&Figure::new(
"plot",
Expand Down
8 changes: 4 additions & 4 deletions crates/app/src/ui/canvas/navigation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -251,12 +251,12 @@ pub(crate) fn commit_data_pan(app: &mut PlotxApp) {
.object(drag.object)
.and_then(|object| object.plot())
{
app.execute_action(Action::set_object_viewport(
app.commit_object_viewport(
drag.canvas,
drag.object,
drag.before,
object.viewport.clone(),
));
);
}
}

Expand Down Expand Up @@ -302,7 +302,7 @@ pub(crate) fn finish_axis_zoom(
};
let mut after = before.clone();
after.select(fig, x, y);
app.execute_action(Action::set_object_viewport(ci, object_id, before, after));
app.commit_object_viewport(ci, object_id, before, after);
app.session.status = "Zoomed axis.".into();
}

Expand All @@ -328,7 +328,7 @@ pub(crate) fn reset_plot_viewport(
HitZone::Plot => after.reset_all(),
HitZone::None => return,
}
app.execute_action(Action::set_object_viewport(ci, object_id, before, after));
app.commit_object_viewport(ci, object_id, before, after);
}

/// Zoom a plot's data viewport around the cursor. The axis is chosen by hit zone
Expand Down
3 changes: 3 additions & 0 deletions crates/app/src/ui/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,9 @@ fn feedback_banner(app: &mut PlotxApp, ui: &mut Ui, dark: bool) {

fn render_sidebars(app: &mut PlotxApp, ui: &mut Ui, dark: bool, workspace_width: f32) {
let compact = workspace_width < 1200.0;
if !app.session.secondary_sidebar_visible {
app.finish_axis_overrides_edit();
}
if app.session.primary_sidebar_visible {
let panel = egui::Panel::left("primary_sidebar")
.frame(egui::Frame::NONE.inner_margin(egui::Margin {
Expand Down
36 changes: 34 additions & 2 deletions crates/app/src/ui/object_inspector.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
//! The Object inspector: geometry + per-kind style editing for the current
//! page-space selection, at the top of the Secondary Side Bar.

mod axes;
mod chart_gallery;
mod panel_note;

use axes::{axes_section, commit_if_target_changed};
use chart_gallery::chart_gallery;
use egui::{DragValue, Ui};
use egui_phosphor::regular as icon;
Expand All @@ -16,13 +18,24 @@ use plotx_core::state::{
use plotx_figure::Color;

pub(crate) fn render(app: &mut PlotxApp, ui: &mut Ui) {
let ids: Vec<ObjectId> = app.session.ui.selection.objects().to_vec();
let axis_target = app.session.active_canvas.and_then(|ci| {
(ids.len() == 1
&& app
.doc
.canvases
.get(ci)?
.object(ids[0])
.is_some_and(|object| object.plot().is_some()))
.then(|| (ci, ids[0]))
});
commit_if_target_changed(app, axis_target);
let Some(ci) = app.session.active_canvas else {
return;
};
if ci >= app.doc.canvases.len() {
return;
}
let ids: Vec<ObjectId> = app.session.ui.selection.objects().to_vec();
if ids.is_empty() {
commit_panel_note_edit(app);
return;
Expand All @@ -40,12 +53,15 @@ pub(crate) fn render(app: &mut PlotxApp, ui: &mut Ui) {
geometry_section(app, ci, &ids, ui);

let mut note_focused = false;
let mut axes_focused = false;
if ids.len() == 1
&& app.doc.canvases[ci]
.object(ids[0])
.map(|o| o.plot().is_some())
.unwrap_or(false)
{
ui.separator();
axes_focused = axes_section(app, ci, ids[0], ui);
ui.separator();
note_focused = panel_note_section(app, ci, ids[0], ui);
data_section(app, ci, ids[0], ui);
Expand Down Expand Up @@ -74,7 +90,7 @@ pub(crate) fn render(app: &mut PlotxApp, ui: &mut Ui) {
format_once_section(app, ci, primary, ui);
}

flush_inspector_edit(app, ui, text_focused || note_focused);
flush_inspector_edit(app, ui, text_focused || note_focused || axes_focused);
ui.separator();
ui.add_space(2.0);
}
Expand Down Expand Up @@ -701,3 +717,19 @@ fn rgb_of(c: Color) -> [u8; 3] {
fn color_of(rgb: [u8; 3]) -> Color {
Color::rgb(rgb[0], rgb[1], rgb[2])
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn renders_safely_during_active_canvas_transition() {
let mut app = PlotxApp::new();
app.session.active_canvas = Some(0);
assert!(app.doc.canvases.is_empty());
assert!(app.session.ui.selection.objects().is_empty());

let ctx = egui::Context::default();
let _ = ctx.run_ui(egui::RawInput::default(), |ui| render(&mut app, ui));
}
}
Loading
Loading