diff --git a/implot.cpp b/implot.cpp index f2f7f40c..b2a7e2ab 100644 --- a/implot.cpp +++ b/implot.cpp @@ -2026,6 +2026,9 @@ bool UpdateInput(ImPlotPlot& plot) { float tx = ImRemap(IO.MousePos.x, plot.PlotRect.Min.x, plot.PlotRect.Max.x, 0.0f, 1.0f); float ty = ImRemap(IO.MousePos.y, plot.PlotRect.Min.y, plot.PlotRect.Max.y, 0.0f, 1.0f); + // Track which axis to use as reference for equal aspect + ImPlotAxis* equal_ref_axis = nullptr; + for (int i = 0; i < IMPLOT_NUM_X_AXES; i++) { ImPlotAxis& x_axis = plot.XAxis(i); const bool equal_zoom = axis_equal && x_axis.OrthoAxis != nullptr; @@ -2033,13 +2036,12 @@ bool UpdateInput(ImPlotPlot& plot) { if (x_hov[i] && !x_axis.IsInputLocked() && !equal_locked) { ImGui::SetKeyOwner(ImGuiKey_MouseWheelY, plot.ID); if (zoom_rate != 0.0f) { - float correction = (plot.Hovered && equal_zoom) ? 0.5f : 1.0f; - const double plot_l = x_axis.PixelsToPlot(plot.PlotRect.Min.x - rect_size.x * tx * zoom_rate * correction); - const double plot_r = x_axis.PixelsToPlot(plot.PlotRect.Max.x + rect_size.x * (1 - tx) * zoom_rate * correction); + const double plot_l = x_axis.PixelsToPlot(plot.PlotRect.Min.x - rect_size.x * tx * zoom_rate); + const double plot_r = x_axis.PixelsToPlot(plot.PlotRect.Max.x + rect_size.x * (1 - tx) * zoom_rate); x_axis.SetMin(x_axis.IsInverted() ? plot_r : plot_l); x_axis.SetMax(x_axis.IsInverted() ? plot_l : plot_r); - if (axis_equal && x_axis.OrthoAxis != nullptr) - x_axis.OrthoAxis->SetAspect(x_axis.GetAspect()); + if (equal_zoom) + equal_ref_axis = &x_axis; changed = true; } } @@ -2051,17 +2053,21 @@ bool UpdateInput(ImPlotPlot& plot) { if (y_hov[i] && !y_axis.IsInputLocked() && !equal_locked) { ImGui::SetKeyOwner(ImGuiKey_MouseWheelY, plot.ID); if (zoom_rate != 0.0f) { - float correction = (plot.Hovered && equal_zoom) ? 0.5f : 1.0f; - const double plot_t = y_axis.PixelsToPlot(plot.PlotRect.Min.y - rect_size.y * ty * zoom_rate * correction); - const double plot_b = y_axis.PixelsToPlot(plot.PlotRect.Max.y + rect_size.y * (1 - ty) * zoom_rate * correction); + const double plot_t = y_axis.PixelsToPlot(plot.PlotRect.Min.y - rect_size.y * ty * zoom_rate); + const double plot_b = y_axis.PixelsToPlot(plot.PlotRect.Max.y + rect_size.y * (1 - ty) * zoom_rate); y_axis.SetMin(y_axis.IsInverted() ? plot_t : plot_b); y_axis.SetMax(y_axis.IsInverted() ? plot_b : plot_t); - if (axis_equal && y_axis.OrthoAxis != nullptr) - y_axis.OrthoAxis->SetAspect(y_axis.GetAspect()); + if (equal_zoom) + equal_ref_axis = &y_axis; changed = true; } } } + + // Apply equal aspect constraint after zooming both axes + if (equal_ref_axis != nullptr && equal_ref_axis->OrthoAxis != nullptr) { + equal_ref_axis->OrthoAxis->SetAspect(equal_ref_axis->GetAspect()); + } } // BOX-SELECTION ----------------------------------------------------------