From 4151cfed48f57f183bc9e628d8fea91c0a5a9b64 Mon Sep 17 00:00:00 2001 From: "Christopher N. Hesse" Date: Sat, 14 Dec 2024 23:47:04 +0100 Subject: [PATCH] Fix axis labels for multiple X or Y axes Previously, the axis widgets and the plot memory would calculate conflicting thickness values for an axis because a reverse iterator was used to push the axis values. Later, the axis thickness would be inserted using an index-based operation into plot memory, which did not take into account the reverse order. See: `mem.y_axis_thickness.insert(i, thickness);` Signed-off-by: Christopher N. Hesse --- egui_plot/src/lib.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/egui_plot/src/lib.rs b/egui_plot/src/lib.rs index 1f43f26..8f22bbc 100644 --- a/egui_plot/src/lib.rs +++ b/egui_plot/src/lib.rs @@ -1343,6 +1343,12 @@ fn axis_widgets<'a>( } } + // The loops iterated through {x,y}_axes in reverse order, so we have to reverse the + // {x,y}_axis_widgets vec as well. Otherwise, the indices are messed up and the plot memory + // (mem.{x,y}_axis_thickness) will access the wrong axis given an index. + x_axis_widgets.reverse(); + y_axis_widgets.reverse(); + let mut plot_rect = rect_left; // If too little space, remove axis widgets