Skip to content

Commit 8e77ea2

Browse files
committed
fix: initial plot data fit
1 parent 396af68 commit 8e77ea2

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

implot3d.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1254,8 +1254,11 @@ bool BeginPlot(const char* title_id, const ImVec2& size, ImPlot3DFlags flags) {
12541254
plot.JustCreated = just_created;
12551255
if (just_created) {
12561256
plot.Rotation = init_rotation;
1257-
for (int i = 0; i < 3; i++)
1257+
plot.FitThisFrame = true;
1258+
for (int i = 0; i < 3; i++) {
12581259
plot.Axes[i] = ImPlot3DAxis();
1260+
plot.Axes[i].FitThisFrame = true;
1261+
}
12591262
}
12601263
if (plot.PreviousFlags != flags)
12611264
plot.Flags = flags;
@@ -1396,7 +1399,7 @@ void SetupAxisLimits(ImAxis3D idx, double min_lim, double max_lim, ImPlot3DCond
13961399
"SetupAxisLimits() needs to be called after BeginPlot and before any setup locking functions (e.g. PlotX)!"); // get plot and axis
13971400
ImPlot3DPlot& plot = *gp.CurrentPlot;
13981401
ImPlot3DAxis& axis = plot.Axes[idx];
1399-
if (plot.JustCreated || cond == ImPlot3DCond_Always) {
1402+
if (!plot.Initialized || cond == ImPlot3DCond_Always) {
14001403
axis.SetRange(min_lim, max_lim);
14011404
axis.RangeCond = cond;
14021405
axis.FitThisFrame = false;
@@ -2005,6 +2008,8 @@ void SetupLock() {
20052008
plot.Rotation = ImPlot3DQuat::Slerp(plot.Rotation, plot.RotationAnimationEnd, t);
20062009
}
20072010

2011+
plot.Initialized = true;
2012+
20082013
// Handle user input
20092014
HandleInput(plot);
20102015

implot3d_internal.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -516,6 +516,7 @@ struct ImPlot3DPlot {
516516
ImPlot3DFlags PreviousFlags;
517517
ImGuiTextBuffer Title;
518518
bool JustCreated;
519+
bool Initialized;
519520
// Bounding rectangles
520521
ImRect FrameRect; // Outermost bounding rectangle that encapsulates whole the plot/title/padding/etc
521522
ImRect CanvasRect; // Frame rectangle reduced by padding
@@ -546,6 +547,7 @@ struct ImPlot3DPlot {
546547
ImPlot3DPlot() {
547548
PreviousFlags = Flags = ImPlot3DFlags_None;
548549
JustCreated = true;
550+
Initialized = false;
549551
Rotation = ImPlot3DQuat(0.0f, 0.0f, 0.0f, 1.0f);
550552
for (int i = 0; i < 3; i++)
551553
Axes[i] = ImPlot3DAxis();

0 commit comments

Comments
 (0)