epezent / implot

Immediate Mode Plotting
MIT License
4.64k stars 516 forks source link

`SetupAxisLimitsConstraints()`'s strange behavior? #438

Open Razakhel opened 1 year ago

Razakhel commented 1 year ago

I'm having trouble figuring out the behavior of SetupAxisLimitsConstraints(). As I understood, which may well be entirely wrong, calling SetupAxisLimitsConstraints(...) was roughly equivalent to calling SetupAxisLimits(..., ImPlotCond_Always). However, this does not seem to be the case, at least for the very first frame: using SetupAxisLimits() with the _Always condition is instantly taken into account, while the *Constraints() version needs another frame to work as expected.

const double maxValCount = 4.0;

if (ImPlot::BeginPlot("Overlay", ImVec2(-1, -1), ImPlotFlags_NoMenus | ImPlotFlags_NoBoxSelect)) {
  ImPlot::SetupAxes("X", "Y");

  // Testing either of the following lines:
  ImPlot::SetupAxisLimits(ImAxis_X1, 0.0, maxValCount, ImPlotCond_Always);
  ImPlot::SetupAxisLimitsConstraints(ImAxis_X1, 0.0, maxValCount);

  ImPlot::SetupAxisLimits(ImAxis_Y1, 0.0, 100.0, ImPlotCond_Once);
  ImPlot::SetupMouseText(ImPlotLocation_NorthEast);

  // Plotting 50, 75, 25, 10 & 50 with lines
  // Plotting 15, 30, 0, 60 & 40 in shaded

  ImPlot::EndPlot();
}

With ImPlot::SetupAxisLimits(ImAxis_X1, 0.0, maxValCount, ImPlotCond_Always);, on the very first frame:

overlay3_base


With ImPlot::SetupAxisLimitsConstraints(ImAxis_X1, 0.0, maxValCount);, still on the very first frame:

overlay3_base

Rendering another frame, we get the expected result:

overlay32_base


While it's not critical, it was not something I expected. Is it a bug, or am I missing something?

Nahor commented 9 months ago

calling SetupAxisLimitsConstraints(...) was roughly equivalent to calling SetupAxisLimits(..., ImPlotCond_Always)

This is incorrect (if I'm not mistaken myself).

So it's pointless to set the "constrains" if you have "limits(...always)". And "limits(...once)" should be within the range specified by "constrains". And in your case, it's actually not expected to go from [0, 1.0] to [0, 4.0] just by setting the constrains, since [0..1] is within the [0..4] range. I suspect that you still have call to SetupAxisLimits(always) somewhere.

Personally, I cannot reproduce the issue. It might have been a bug in implot that has been fixed since (you haven't specified what version you're using, myself I used v0.16) or something else is going on in your code (posting a more complete example would be useful).