epezent / implot

Immediate Mode Plotting
MIT License
4.66k stars 520 forks source link

Plot Scrolling, ImPlotAxisFlags_AutoFit don't seem to be working for my setup #354

Closed cca32 closed 2 years ago

cca32 commented 2 years ago

I apologize if this is a simple fix that I'm missing. I've tried everything possible. I'm also fairly new to the Dear ImGui and ImPlot style.

I have the following code to re-create the simple line-graph from the demo.

static double x_plot[10];
static double y_plot[10];
for(int i=0; i < 10; i++){
    x_plot[i] = i;
    y_plot[i] = 2*i;
}

ImPlot::CreateContext();
if (ImPlot::BeginPlot("P&L")) {
    ImPlot::SetupAxes("x","y");
    ImPlot::SetupAxesLimits(0.0, 15.0, 0.00, 30.00);
    ImPlot::PlotLine("y=2x", x_plot, y_plot, 10);
    ImPlot::EndPlot();
}
ImPlot::DestroyContext();

It works as expected. It graphs y = 2*x. image Problems I can't figure out: 1) the zoom-out feature from mouse scroll-wheel on the graph does not work though ( it also doesn't work in the demo. but works in the demo from the url) 2) if i replace the SetUpAxesLimits with anything else like ImPlotAxisFlags_AutoFit, the graph just defaults to some values and doesn't move. nothing works on moving it. even the auto-fit demo doesn't move. its stuck like this:

image

I am using imgui_impl_dx12.cpp backend with gcc 11.2 on windows. i'm also using the docking branch from Dear ImGui sorry if this is a configuration. i can't figure out why the graph won't move. i've tried looking through all the various plot flags, window flags, etc. there doesn't seem to be a reason why it shouldn't work. also the demo doesn't work on my machine as demonstrated on the web-page (the scroll-zoom, auto-fit)

epezent commented 2 years ago

You are creating and destroying the ImPlot context every frame. You need to call each of these only once in the application's lifetime, ideally wherever ImGui::CreateContext and ImGui::DestroyContext are called.

cca32 commented 2 years ago

omg, i'm so sorry. i should have noticed when it would let me scroll out for a millisecond then instantly snap back on the next frame. this solves the issue