Skip to content

Y2 axis zoom is locked after setting limits once #595

@merravid

Description

@merravid

If you want to control the limits of the Y2 axis yourself, and call "SetupAxisLimits(ImAxis_Y2...)" only on those frames when you actually want to change those limits, you are unable to zoom in or out on that axis.

This behaviour is different from that on the Y1 axis which zooms as expected.

This is some sample code. Once the "Reset Zoom" button is pressed once, the zoom on the Y2 axis is permanently locked.

void Demo_AxisLockIssue() {
    static float limits_x[2] = { 0, 1.0 };
    static float limits_y1[2] = { 0, 10.0 };
    static float limits_y2[2] = { 10.0, 20.0 };
    
    float data_x[5] = { 0.0f, 0.25f, 0.5f, 0.75f, 1.0f };
    float data_y1[5] = { 0.0f, 2.5f, 5.0f, 7.5f, 10.0f };
    float data_y2[5] = { 20.0f, 17.5f, 15.0f, 12.5f, 10.0f };

    bool reset_zoom = false;
    if (ImGui::Button("Reset Zoom"))
        reset_zoom = true;

    if (ImPlot::BeginPlot("##AxisLockIssue"))
    {
        ImPlot::SetupAxes("X", "Y1");
        ImPlot::SetupAxis(ImAxis_Y2, "Y2", ImPlotAxisFlags_AuxDefault);

        if (reset_zoom)
        {
            ImPlot::SetupAxisLimits(ImAxis_X1, limits_x[0], limits_x[1], ImGuiCond_Always);
            ImPlot::SetupAxisLimits(ImAxis_Y1, limits_y1[0], limits_y1[1], ImGuiCond_Always);
            ImPlot::SetupAxisLimits(ImAxis_Y2, limits_y2[0], limits_y2[1], ImGuiCond_Always);
        }
        
        ImPlot::PlotLine("Y1", data_x, data_y1, 5);

        ImPlot::SetAxes(ImAxis_X1, ImAxis_Y2);
        ImPlot::PlotLine("Y2", data_x, data_y2, 5);

        ImPlot::EndPlot();
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions