Skip to content

Commit 9478e2f

Browse files
committed
Rename IsPlotChanging to IsAxisRangeChanging and define PreviousRange in SetupFinish
1 parent 9c44711 commit 9478e2f

File tree

4 files changed

+16
-13
lines changed

4 files changed

+16
-13
lines changed

TODO.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,8 @@ Ideally every `PlotX` function should use our faster rendering pipeline when it
7979
|PlotDummy|-|-|-|-|
8080

8181
## Completed
82-
- add `IsPlotChanging` to detect change in limits
82+
- add `IsAxisRangeChanging` to detect change in limits
83+
- add exploding to `PlotPieChart` (on legend hover)
8384
- make BeginPlot take fewer args:
8485
- make query a tool -> `DragRect`
8586
- rework DragLine/Point to use ButtonBehavior

implot.cpp

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2135,8 +2135,6 @@ void SetupAxis(ImAxis idx, const char* label, ImPlotAxisFlags flags) {
21352135
if (plot.JustCreated || flags != axis.PreviousFlags)
21362136
axis.Flags = flags;
21372137
axis.PreviousFlags = flags;
2138-
// cache previous range
2139-
axis.PreviousRange = ImPlotRange(axis.Range.Min, axis.Range.Max);
21402138
// enable axis
21412139
axis.Enabled = true;
21422140
// set label
@@ -2632,6 +2630,11 @@ void SetupFinish() {
26322630
}
26332631
}
26342632

2633+
// cache previous ranges
2634+
for(int i = 0; i < ImAxis_COUNT; i++) {
2635+
plot.Axes[i].PreviousRange = ImPlotRange(plot.Axes[i].Range.Min, plot.Axes[i].Range.Max);
2636+
}
2637+
26352638
// INPUT ------------------------------------------------------------------
26362639
if (!ImHasFlag(plot.Flags, ImPlotFlags_NoInputs))
26372640
UpdateInput(plot);
@@ -3741,14 +3744,14 @@ bool IsPlotHovered() {
37413744
return gp.CurrentPlot->Hovered;
37423745
}
37433746

3744-
bool IsPlotChanging() {
3747+
bool IsAxisRangeChanging(ImAxis axis) {
37453748
ImPlotContext& gp = *GImPlot;
3746-
IM_ASSERT_USER_ERROR(gp.CurrentPlot != nullptr, "IsPlotChanging() needs to be called between BeginPlot() and EndPlot()!");
3749+
IM_ASSERT_USER_ERROR(gp.CurrentPlot != nullptr, "IsAxisRangeChanging() needs to be called between BeginPlot() and EndPlot()!");
37473750
SetupLock();
37483751
ImPlotPlot& plot = *gp.CurrentPlot;
3749-
bool differentX = plot.Axes[plot.CurrentX].Range.Min != plot.Axes[plot.CurrentX].PreviousRange.Min || plot.Axes[plot.CurrentX].Range.Max != plot.Axes[plot.CurrentX].PreviousRange.Max;
3750-
bool differentY = plot.Axes[plot.CurrentY].Range.Min != plot.Axes[plot.CurrentY].PreviousRange.Min || plot.Axes[plot.CurrentY].Range.Max != plot.Axes[plot.CurrentY].PreviousRange.Max;
3751-
return differentX || differentY;
3752+
bool isMinDifferent = plot.Axes[axis].Range.Min != plot.Axes[axis].PreviousRange.Min;
3753+
bool isMaxDifferent = plot.Axes[axis].Range.Max != plot.Axes[axis].PreviousRange.Max;
3754+
return isMinDifferent || isMaxDifferent;
37523755
}
37533756

37543757
bool IsAxisHovered(ImAxis axis) {

implot.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -982,8 +982,8 @@ IMPLOT_API ImPlotRect GetPlotLimits(ImAxis x_axis = IMPLOT_AUTO, ImAxis y_axis =
982982

983983
// Returns true if the plot area in the current plot is hovered.
984984
IMPLOT_API bool IsPlotHovered();
985-
// Returns true if the limits of the current plot are changing.
986-
IMPLOT_API bool IsPlotChanging();
985+
// Returns true if the limits of the selected axis are changing.
986+
IMPLOT_API bool IsAxisRangeChanging(ImAxis axis);
987987
// Returns true if the axis label area in the current plot is hovered.
988988
IMPLOT_API bool IsAxisHovered(ImAxis axis);
989989
// Returns true if the bounding frame of a subplot is hovered.

implot_demo.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2131,15 +2131,14 @@ void Demo_ColormapWidgets() {
21312131
void Demo_PlotLimitsChanging() {
21322132
unsigned int lin[10] = {8,8,9,7,8,8,8,9,7,8};
21332133
unsigned int bar[10] = {1,2,5,3,4,1,2,5,3,4};
2134-
unsigned int dot[10] = {7,6,6,7,8,5,6,5,8,7};
21352134

21362135
if (ImPlot::BeginPlot("##LimitsChanging")) {
21372136
ImPlot::SetupAxes( "x-axis", "y-axis");
21382137
ImPlot::SetupAxesLimits(-0.5f, 9.5f, 0, 10);
21392138
ImPlot::PlotBars("Bars", bar, 10, 0.5f);
21402139
ImPlot::PlotLine("Line", lin, 10);
2141-
bool is_changing = ImPlot::IsPlotChanging();
2142-
ImGui::Text("Axes are changing: %s", (is_changing ? "true" : "false"));
2140+
bool is_changing = ImPlot::IsAxisRangeChanging(ImAxis_X1);
2141+
ImGui::Text("Axis X1 is changing: %s", (is_changing ? "true" : "false"));
21432142
ImPlot::EndPlot();
21442143
}
21452144
}

0 commit comments

Comments
 (0)