epezent / epezent/implot

`SetupAxisLimitsConstraints()`'s strange behavior?

Open
#438 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
6.2k
Forks
693
PR merge metrics
No merged PRs in 30d

Description

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.

```cpp
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](https://user-images.githubusercontent.com/5424728/211776282-62877e89-c90f-4d22-a611-2fbf5976e0b1.png)

---

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

![overlay3_base](https://user-images.githubusercontent.com/5424728/211776479-02e55424-225f-4c75-854f-7c6323a84f36.png)

Rendering another frame, we get the expected result:

![overlay32_base](https://user-images.githubusercontent.com/5424728/211776619-e3d62ed7-761e-4f14-befb-26c28ad7e6c3.png)

---

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

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.