SetNextPlotLimitsX differences between v0.9 and v0.10
Closed this issue · 3 comments
First I want to thank you for creating this graphing library, it has saved me tons of time. I recently updated implot code to verion
0.10 and instantly noticed that the xmin and xmax in SetNextPlotLimitsX not longer limit my sliding window charts. My guess is that I'm doing something wrong in my approach. When you have a chance please take a look.
Here is my full code:
int bar_data[11] = { 0,1,2,3,4,5,6,7,8,9,10 };
float x_data[1000];
float y_data[1000];
for (int x = 0; x < 1000; x++)
{
x_data[x] = x;
y_data[x] = sin(2 * 3.14 * 6000 * x) * 10.0;
}
/////////////////////////////////////////////////////////////////////////////////
// Chart 1
/////////////////////////////////////////////////////////////////////////////////
static double xmin = 0, xmax = 0;
const ImVec2 winSize = ImGui::GetContentRegionAvail();
ImPlot::GetStyle().AntiAliasedLines = true;
ImPlot::PushStyleVar(ImPlotStyleVar_PlotPadding, ImVec2(5.0f, 10.0f));
ImPlot::SetNextPlotLimitsX(0.0, 25.0, ImGuiCond_Appearing); // <----------- Not working
ImPlot::SetNextPlotLimitsY(-15.0, 15.0, ImGuiCond_Always, ImPlotYAxis_2);
ImPlot::LinkNextPlotLimits(&xmin, &xmax, NULL, NULL);
if (ImPlot::BeginPlot
(
"##StockPlot", // Title
NULL, // x_label
NULL, // y1_label
ImVec2(-1, winSize.y * 0.78f), // size
ImPlotFlags_YAxis2 | ImPlotFlags_NoMenus, // flags
ImPlotAxisFlags_NoDecorations | ImPlotAxisFlags_Invert, // ImPlotAxisFlags x_flags
ImPlotAxisFlags_NoDecorations, // ImPlotAxisFlags y1_flags
ImPlotAxisFlags_LockMin | ImPlotAxisFlags_LockMax // ImPlotAxisFlags y2_flags
))
{
ImPlot::SetLegendLocation(ImPlotLocation_SouthWest, ImPlotOrientation_Vertical);
ImPlot::SetPlotYAxis(ImPlotYAxis_2);
ImPlot::PlotLine("Charts", x_data, y_data, 1000);
ImPlot::PushStyleVar(ImPlotStyleVar_FillAlpha, 0.25f);
ImPlot::PlotShaded("Charts", x_data, y_data, 1000, -15.0);
ImPlot::PopStyleVar();
ImPlot::EndPlot();
}
/////////////////////////////////////////////////////////////////////////////////
// Chart mini
/////////////////////////////////////////////////////////////////////////////////
ImPlot::SetNextPlotLimitsY(0.0, 12.0, ImGuiCond_Always, ImPlotYAxis_2);
ImPlot::LinkNextPlotLimits(&xmin, &xmax, NULL, NULL);
if (ImPlot::BeginPlot
(
"##Indicators", // Title
NULL, // x_label
NULL, // y1_label
ImVec2(-1, winSize.y * 0.2f), // size
ImPlotFlags_YAxis2 | ImPlotFlags_NoMenus, // flags
ImPlotAxisFlags_Invert, // ImPlotAxisFlags x_flags
ImPlotAxisFlags_NoDecorations, // ImPlotAxisFlags y1_flags
ImPlotAxisFlags_LockMin | ImPlotAxisFlags_LockMax // ImPlotAxisFlags y2_flags
))
{
ImPlot::SetLegendLocation(ImPlotLocation_SouthWest, ImPlotOrientation_Vertical);
ImPlot::SetPlotYAxis(ImPlotYAxis_2);
ImPlot::PlotBars("mini", bar_data, 11);
ImPlot::EndPlot();
}
ImPlot::PopStyleVar();
Output:
@Davido71, thanks for bringing this to my attention. We introduced a feature where plots automatically fit to the data on initialization unless SetNextPlotLimits
is explicitly called. You do call this function before the first plot, but you also link the x-limits to the second plot where you do not call it. So the second plot is fit to ~[0,10] on initialization and this propagates to the first plot. The simple fix for you right now is to add ImPlotAxisFlags_NoInitialFit
to the x-axis of both plots. However, this is an obvious oversight on my part. I need to disable auto-fit on initialization if LinkNextPlotLimits
is called. Give me a few hours and it should be fixed.
Should have said a few minutes. It should be fixed by 27bc59e
Close out the issue if it's working for you again. Thanks!
Thank you for quick response and fixing the issue. Works perfectly now!