From e847aa786df07ffcc67d88b779b8690f62f300f2 Mon Sep 17 00:00:00 2001 From: Evan Pezent Date: Sat, 25 Jul 2020 07:59:47 -0500 Subject: [PATCH] bug fix: calculate adaptive divisions after canvas bounding box is calculated --- implot.cpp | 14 +++++++------- implot_demo.cpp | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/implot.cpp b/implot.cpp index 2ddefe3..72afd9f 100644 --- a/implot.cpp +++ b/implot.cpp @@ -933,13 +933,6 @@ bool BeginPlot(const char* title, const char* x_label, const char* y_label, cons plot.YAxis[i].Range.Max = plot.YAxis[i].Range.Min + DBL_EPSILON; } - // adaptive divisions - int x_divisions = ImMax(2, (int)IM_ROUND(0.003 * gp.BB_Canvas.GetWidth())); - int y_divisions[MAX_Y_AXES]; - for (int i = 0; i < MAX_Y_AXES; i++) { - y_divisions[i] = ImMax(2, (int)IM_ROUND(0.003 * gp.BB_Canvas.GetHeight())); - } - // COLORS ----------------------------------------------------------------- gp.Col_Frame = gp.Style.Colors[ImPlotCol_FrameBg].w == -1 ? ImGui::GetColorU32(ImGuiCol_FrameBg) : ImGui::GetColorU32(gp.Style.Colors[ImPlotCol_FrameBg]); @@ -974,6 +967,13 @@ bool BeginPlot(const char* title, const char* x_label, const char* y_label, cons // canvas bb gp.BB_Canvas = ImRect(gp.BB_Frame.Min + Style.WindowPadding, gp.BB_Frame.Max - Style.WindowPadding); + // adaptive divisions + int x_divisions = ImMax(2, (int)IM_ROUND(0.003 * gp.BB_Canvas.GetWidth())); + int y_divisions[MAX_Y_AXES]; + for (int i = 0; i < MAX_Y_AXES; i++) { + y_divisions[i] = ImMax(2, (int)IM_ROUND(0.003 * gp.BB_Canvas.GetHeight())); + } + gp.RenderX = (HasFlag(plot.XAxis.Flags, ImPlotAxisFlags_GridLines) || HasFlag(plot.XAxis.Flags, ImPlotAxisFlags_TickMarks) || HasFlag(plot.XAxis.Flags, ImPlotAxisFlags_TickLabels)) && x_divisions > 1; diff --git a/implot_demo.cpp b/implot_demo.cpp index c5aefb9..392b41e 100644 --- a/implot_demo.cpp +++ b/implot_demo.cpp @@ -415,7 +415,7 @@ void ShowDemoWindow(bool* p_open) { ImPlot::SetNextPlotLimits(-1,1,-1,1); if (ImPlot::BeginPlot("##Heatmap2",NULL,NULL,ImVec2(225,225),ImPlotFlags_ContextMenu,0,0)) { ImPlot::PlotHeatmap("heat1",values2,100,100,0,1,NULL); - ImPlot::PlotHeatmap("heat1",values2,100,100,0,1,NULL, ImPlotPoint(-1,-1), ImPlotPoint(0,0)); + ImPlot::PlotHeatmap("heat2",values2,100,100,0,1,NULL, ImPlotPoint(-1,-1), ImPlotPoint(0,0)); ImPlot::EndPlot(); } ImPlot::SetColormap(ImPlotColormap_Default);