From d737f4eb3c379da4ec428991fc08a6e588c96200 Mon Sep 17 00:00:00 2001 From: Ygor Souza Date: Wed, 27 Mar 2024 20:01:55 +0100 Subject: [PATCH 1/2] Prevent plot from resetting one axis while zooming/dragging the other Closes #4251 --- crates/egui_plot/src/lib.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/egui_plot/src/lib.rs b/crates/egui_plot/src/lib.rs index 26567117652..6874855159b 100644 --- a/crates/egui_plot/src/lib.rs +++ b/crates/egui_plot/src/lib.rs @@ -1021,7 +1021,7 @@ impl Plot { delta.y = 0.0; } mem.transform.translate_bounds(delta); - mem.auto_bounds = !allow_drag; + mem.auto_bounds = false.into(); } // Zooming @@ -1092,7 +1092,7 @@ impl Plot { } if zoom_factor != Vec2::splat(1.0) { mem.transform.zoom(zoom_factor, hover_pos); - mem.auto_bounds = !allow_zoom; + mem.auto_bounds = false.into(); } } if allow_scroll.any() { From e772f7bfd0fea8251569a3e39464b6f33d5c3a06 Mon Sep 17 00:00:00 2001 From: Ygor Souza Date: Thu, 28 Mar 2024 06:30:59 +0100 Subject: [PATCH 2/2] Leave autobounds on if they were already on for the disabled axis This was probably the original intention of the code. --- crates/egui_plot/src/lib.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/egui_plot/src/lib.rs b/crates/egui_plot/src/lib.rs index 6874855159b..6056f46bd4e 100644 --- a/crates/egui_plot/src/lib.rs +++ b/crates/egui_plot/src/lib.rs @@ -1021,7 +1021,7 @@ impl Plot { delta.y = 0.0; } mem.transform.translate_bounds(delta); - mem.auto_bounds = false.into(); + mem.auto_bounds = mem.auto_bounds.and(!allow_drag); } // Zooming @@ -1092,7 +1092,7 @@ impl Plot { } if zoom_factor != Vec2::splat(1.0) { mem.transform.zoom(zoom_factor, hover_pos); - mem.auto_bounds = false.into(); + mem.auto_bounds = mem.auto_bounds.and(!allow_zoom); } } if allow_scroll.any() {