Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Y2 axis zoom is locked after setting limits once #595

Open
merravid opened this issue Oct 14, 2024 · 0 comments
Open

Y2 axis zoom is locked after setting limits once #595

merravid opened this issue Oct 14, 2024 · 0 comments

Comments

@merravid
Copy link

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();
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant