mirror of
https://github.com/gwm17/implot.git
synced 2025-01-30 10:58:51 -05:00
add FitNextPlotAxes
This commit is contained in:
parent
ff29f1ebcc
commit
7da6ed69f3
32
implot.cpp
32
implot.cpp
|
@ -227,7 +227,8 @@ void Reset(ImPlotContext* ctx) {
|
|||
ctx->YTicks[i].shrink(0);
|
||||
ctx->YTickLabels[i].Buf.shrink(0);
|
||||
}
|
||||
// reset extents
|
||||
// reset extents/fit
|
||||
ctx->FitThisFrame = false;
|
||||
ctx->FitX = false;
|
||||
ctx->ExtentsX.Min = HUGE_VAL;
|
||||
ctx->ExtentsX.Max = -HUGE_VAL;
|
||||
|
@ -971,19 +972,25 @@ bool BeginPlot(const char* title, const char* x_label, const char* y_label, cons
|
|||
plot.QueryRect = ImRect(0,0,0,0);
|
||||
}
|
||||
|
||||
// DOUBLE CLICK -----------------------------------------------------------
|
||||
// FIT -----------------------------------------------------------
|
||||
|
||||
if ( IO.MouseDoubleClicked[gp.InputMap.FitButton] && gp.Hov_Frame && (plot.XAxis.HoveredTot || any_hov_y_axis_region) && !hov_legend && !hov_query) {
|
||||
// fit from double click
|
||||
if ( IO.MouseDoubleClicked[gp.InputMap.FitButton] && gp.Hov_Frame && (plot.XAxis.HoveredTot || any_hov_y_axis_region) && !hov_legend && !hov_query ) {
|
||||
gp.FitThisFrame = true;
|
||||
gp.FitX = plot.XAxis.HoveredTot;
|
||||
for (int i = 0; i < IMPLOT_Y_AXES; i++)
|
||||
gp.FitY[i] = plot.YAxis[i].HoveredTot;
|
||||
}
|
||||
else {
|
||||
gp.FitThisFrame = false;
|
||||
gp.FitX = false;
|
||||
for (int i = 0; i < IMPLOT_Y_AXES; i++)
|
||||
gp.FitY[i] = false;
|
||||
// fit from FitNextPlotAxes
|
||||
if (gp.NextPlotData.FitX) {
|
||||
gp.FitThisFrame = true;
|
||||
gp.FitX = true;
|
||||
}
|
||||
for (int i = 0; i < IMPLOT_Y_AXES; ++i) {
|
||||
if (gp.NextPlotData.FitY[i]) {
|
||||
gp.FitThisFrame = true;
|
||||
gp.FitY[i] = true;
|
||||
}
|
||||
}
|
||||
|
||||
// FOCUS ------------------------------------------------------------------
|
||||
|
@ -1554,6 +1561,15 @@ void SetNextPlotLimitsY(double y_min, double y_max, ImGuiCond cond, int y_axis)
|
|||
gp.NextPlotData.Y[y_axis].Max = y_max;
|
||||
}
|
||||
|
||||
void FitNextPlotAxes(bool x, bool y, bool y2, bool y3) {
|
||||
ImPlotContext& gp = *GImPlot;
|
||||
IM_ASSERT_USER_ERROR(gp.CurrentPlot == NULL, "FitNextPlotAxes() needs to be called before BeginPlot()!");
|
||||
gp.NextPlotData.FitX = x;
|
||||
gp.NextPlotData.FitY[0] = y;
|
||||
gp.NextPlotData.FitY[1] = y2;
|
||||
gp.NextPlotData.FitY[2] = y3;
|
||||
}
|
||||
|
||||
void SetNextPlotTicksX(const double* values, int n_ticks, const char** labels, bool show_default) {
|
||||
ImPlotContext& gp = *GImPlot;
|
||||
IM_ASSERT_USER_ERROR(gp.CurrentPlot == NULL, "SetNextPlotTicksX() needs to be called before BeginPlot()!");
|
||||
|
|
2
implot.h
2
implot.h
|
@ -382,6 +382,8 @@ void SetNextPlotLimits(double x_min, double x_max, double y_min, double y_max, I
|
|||
void SetNextPlotLimitsX(double x_min, double x_max, ImGuiCond cond = ImGuiCond_Once);
|
||||
// Set the Y axis range limits of the next plot. Call right before BeginPlot(). If ImGuiCond_Always is used, the Y axis limits will be locked.
|
||||
void SetNextPlotLimitsY(double y_min, double y_max, ImGuiCond cond = ImGuiCond_Once, int y_axis = 0);
|
||||
// Fits the next plot axes if they are unlocked.
|
||||
void FitNextPlotAxes(bool x = true, bool y = true, bool y2 = true, bool y3 = true);
|
||||
|
||||
// Set the X axis ticks and optionally the labels for the next plot.
|
||||
void SetNextPlotTicksX(const double* values, int n_ticks, const char** labels = NULL, bool show_default = false);
|
||||
|
|
|
@ -600,6 +600,11 @@ void ShowDemoWindow(bool* p_open) {
|
|||
ImGui::ColorEdit4("##Col2", &y2_col.x, ImGuiColorEditFlags_NoInputs);
|
||||
ImGui::SameLine();
|
||||
ImGui::ColorEdit4("##Col3", &y3_col.x, ImGuiColorEditFlags_NoInputs);
|
||||
// you can fit axes programatically
|
||||
ImGui::SameLine(); if (ImGui::Button("Fit X")) ImPlot::FitNextPlotAxes(true, false, false, false);
|
||||
ImGui::SameLine(); if (ImGui::Button("Fit Y")) ImPlot::FitNextPlotAxes(false, true, false, false);
|
||||
ImGui::SameLine(); if (ImGui::Button("Fit Y2")) ImPlot::FitNextPlotAxes(false, false, true, false);
|
||||
ImGui::SameLine(); if (ImGui::Button("Fit Y3")) ImPlot::FitNextPlotAxes(false, false, false, true);
|
||||
for (int i = 0; i < 1001; ++i) {
|
||||
xs[i] = (i*0.1f);
|
||||
ys1[i] = Sin(xs[i]) * 3 + 1;
|
||||
|
|
|
@ -299,13 +299,17 @@ struct ImPlotNextPlotData
|
|||
bool HasYRange[IMPLOT_Y_AXES];
|
||||
bool ShowDefaultTicksX;
|
||||
bool ShowDefaultTicksY[IMPLOT_Y_AXES];
|
||||
bool FitX;
|
||||
bool FitY[IMPLOT_Y_AXES];
|
||||
|
||||
ImPlotNextPlotData() {
|
||||
HasXRange = false;
|
||||
ShowDefaultTicksX = true;
|
||||
FitX = false;
|
||||
for (int i = 0; i < IMPLOT_Y_AXES; ++i) {
|
||||
HasYRange[i] = false;
|
||||
ShowDefaultTicksY[i] = true;
|
||||
FitY[i] = false;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue
Block a user