Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow changing plot aspect ratio with scroll + cmd/ctrl + alt #2742

Merged
merged 1 commit into from
Aug 6, 2023
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
4 changes: 4 additions & 0 deletions crates/re_space_view/src/controls.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
/// Modifier to press for scroll to zoom.
pub const ZOOM_SCROLL_MODIFIER: egui::Modifiers = egui::Modifiers::COMMAND;

/// Modifier to press for scroll to change aspect ratio.
pub const ASPECT_SCROLL_MODIFIER: egui::Modifiers =
egui::Modifiers::ALT.plus(egui::Modifiers::COMMAND);

/// Modifier to press for scroll to pan horizontally.
pub const HORIZONTAL_SCROLL_MODIFIER: egui::Modifiers = egui::Modifiers::SHIFT;

Expand Down
10 changes: 10 additions & 0 deletions crates/re_space_view_bar_chart/src/space_view_class.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ impl SpaceViewClass for BarChartSpaceView {
layout.add(controls::ZOOM_SCROLL_MODIFIER);
layout.add(".\n");

layout.add("Scroll + ");
layout.add(controls::ASPECT_SCROLL_MODIFIER);
layout.add(" to change the aspect ratio.\n");

layout.add("Drag ");
layout.add(controls::SELECTION_RECT_ZOOM_BUTTON);
layout.add(" to zoom in/out using a selection.\n\n");
Expand Down Expand Up @@ -84,10 +88,16 @@ impl SpaceViewClass for BarChartSpaceView {

let charts = &parts.get::<BarChartViewPartSystem>()?.charts;

let zoom_both_axis = !ui.input(|i| i.modifiers.contains(controls::ASPECT_SCROLL_MODIFIER));

ui.scope(|ui| {
Plot::new("bar_chart_plot")
.legend(Legend::default())
.clamp_grid(true)
.allow_zoom(egui::plot::AxisBools {
x: true,
y: zoom_both_axis,
})
.show(ui, |plot_ui| {
fn create_bar_chart<N: Into<f64>>(
ent_path: &EntityPath,
Expand Down
10 changes: 10 additions & 0 deletions crates/re_space_view_time_series/src/space_view_class.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ impl SpaceViewClass for TimeSeriesSpaceView {
layout.add(controls::ZOOM_SCROLL_MODIFIER);
layout.add(".\n");

layout.add("Scroll + ");
layout.add(controls::ASPECT_SCROLL_MODIFIER);
layout.add(" to change the aspect ratio.\n");

layout.add("Drag ");
layout.add(controls::SELECTION_RECT_ZOOM_BUTTON);
layout.add(" to zoom in/out using a selection.\n");
Expand Down Expand Up @@ -121,7 +125,13 @@ impl SpaceViewClass for TimeSeriesSpaceView {
// use timeline_name as part of id, so that egui stores different pan/zoom for different timelines
let plot_id_src = ("plot", &timeline_name);

let zoom_both_axis = !ui.input(|i| i.modifiers.contains(controls::ASPECT_SCROLL_MODIFIER));

let mut plot = Plot::new(plot_id_src)
.allow_zoom(egui::plot::AxisBools {
x: true,
y: zoom_both_axis,
})
.legend(Legend {
position: egui::plot::Corner::RightBottom,
..Default::default()
Expand Down