Skip to content

SetupAxisLimits when ImPlotCond_Once and plot is already Initialized #619

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions implot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2150,7 +2150,7 @@ void SetupAxisLimits(ImAxis idx, double min_lim, double max_lim, ImPlotCond cond
ImPlotPlot& plot = *gp.CurrentPlot;
ImPlotAxis& axis = plot.Axes[idx];
IM_ASSERT_USER_ERROR(axis.Enabled, "Axis is not enabled! Did you forget to call SetupAxis()?");
if (!plot.Initialized || cond == ImPlotCond_Always)
if (!plot.Initialized || cond == ImPlotCond_Always || (!axis.HasRange && cond == ImPlotCond_Once))
axis.SetRange(min_lim, max_lim);
axis.HasRange = true;
axis.RangeCond = cond;
Expand Down Expand Up @@ -2418,9 +2418,7 @@ bool BeginPlot(const char* title_id, const ImVec2& size, ImPlotFlags flags) {
plot.Axes[i].Reset();
UpdateAxisColors(plot.Axes[i]);
}
// ensure first axes enabled
plot.Axes[ImAxis_X1].Enabled = true;
plot.Axes[ImAxis_Y1].Enabled = true;

// set initial axes
plot.CurrentX = ImAxis_X1;
plot.CurrentY = ImAxis_Y1;
Expand All @@ -2429,6 +2427,10 @@ bool BeginPlot(const char* title_id, const ImVec2& size, ImPlotFlags flags) {
for (int i = 0; i < ImAxis_COUNT; ++i)
ApplyNextPlotData(i);

// ensure first axes enabled
plot.Axes[ImAxis_X1].Enabled = true;
plot.Axes[ImAxis_Y1].Enabled = true;

// clear text buffers
plot.ClearTextBuffer();
plot.SetTitle(title_id);
Expand Down