Skip to content

Commit

Permalink
Allow changing plot aspect ratio with scroll + cmd/ctrl + alt (#2742)
Browse files Browse the repository at this point in the history
<!--
Open the PR up as a draft until you feel it is ready for a proper
review.

Do not make PR:s from your own `main` branch, as that makes it difficult
for reviewers to add their own fixes.

Add any improvements to the branch as new commits to make it easier for
reviewers to follow the progress. All commits will be squashed to a
single commit once the PR is merged into `main`.

Make sure you mention any issues that this PR closes in the description,
as well as any other related issues.

To get an auto-generated PR description you can put "copilot:summary" or
"copilot:walkthrough" anywhere.
-->

### What

Wanted Shift+Cmd originally, but egui no longer see this as a scroll
then. Also, shift+scroll is already taken for translating along y.

Fixes #2148
* #2148



https://github.com/rerun-io/rerun/assets/1220815/bc078094-4bae-4980-8508-af0cff234614



### Checklist
* [x] I have read and agree to [Contributor
Guide](https://github.com/rerun-io/rerun/blob/main/CONTRIBUTING.md) and
the [Code of
Conduct](https://github.com/rerun-io/rerun/blob/main/CODE_OF_CONDUCT.md)
* [x] I've included a screenshot or gif (if applicable)
* [x] I have tested [demo.rerun.io](https://demo.rerun.io/pr/2742) (if
applicable)

- [PR Build Summary](https://build.rerun.io/pr/2742)
- [Docs
preview](https://rerun.io/preview/pr%3Aandreas%2Fsingle-axis-plot-zoom/docs)
- [Examples
preview](https://rerun.io/preview/pr%3Aandreas%2Fsingle-axis-plot-zoom/examples)
  • Loading branch information
Wumpf authored Aug 6, 2023
1 parent 272bb6d commit ac8bc41
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 0 deletions.
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

0 comments on commit ac8bc41

Please sign in to comment.