Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 16 additions & 10 deletions implot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2026,20 +2026,22 @@ 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;
const bool equal_locked = (equal_zoom != false) && x_axis.OrthoAxis->IsInputLocked();
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;
}
}
Expand All @@ -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 ----------------------------------------------------------
Expand Down