From 981fdb393224af0b05ac7b40911cf93d112e656d Mon Sep 17 00:00:00 2001 From: Tobias Schmitz Date: Sun, 2 Oct 2022 14:32:37 +0200 Subject: [PATCH] fix: default to changing y axis when changing data aspect (#2087) --- crates/egui/src/widgets/plot/mod.rs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/crates/egui/src/widgets/plot/mod.rs b/crates/egui/src/widgets/plot/mod.rs index 14d1fa0f..c114d594 100644 --- a/crates/egui/src/widgets/plot/mod.rs +++ b/crates/egui/src/widgets/plot/mod.rs @@ -79,6 +79,13 @@ struct AxisBools { y: bool, } +impl AxisBools { + #[inline] + fn any(&self) -> bool { + self.x || self.y + } +} + impl From for AxisBools { fn from(val: bool) -> Self { AxisBools { x: val, y: val } @@ -843,8 +850,10 @@ impl Plot { if let Some(linked_axes) = &linked_axes { let change_x = linked_axes.link_y && !linked_axes.link_x; transform.set_aspect_by_changing_axis(data_aspect as f64, change_x); - } else { + } else if auto_bounds.any() { transform.set_aspect_by_expanding(data_aspect as f64); + } else { + transform.set_aspect_by_changing_axis(data_aspect as f64, false); } }