1
0
Fork 0
mirror of https://github.com/gwm17/implot.git synced 2024-11-26 20:28:50 -05:00

bug fix: calculate adaptive divisions after canvas bounding box is calculated

This commit is contained in:
Evan Pezent 2020-07-25 07:59:47 -05:00
parent 0a3442f389
commit e847aa786d
2 changed files with 8 additions and 8 deletions

View File

@ -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;

View File

@ -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);