1
0
Fork 0
mirror of https://github.com/gwm17/implot.git synced 2024-11-26 12:18:52 -05:00

Fix vertically-flipped 2D histograms

This commit is contained in:
marcizhu 2021-06-25 11:52:38 +02:00
parent 5f11a7875d
commit bef982f0b6
No known key found for this signature in database
GPG Key ID: 2D8FA5B173E88095
3 changed files with 10 additions and 11 deletions

View File

@ -53,8 +53,8 @@ struct HeatmapData
HeatmapShader* ShaderProgram; ///< Shader to be used by this heatmap (either ShaderInt or ShaderFloat) HeatmapShader* ShaderProgram; ///< Shader to be used by this heatmap (either ShaderInt or ShaderFloat)
GLuint HeatmapTexID; ///< Texture ID of the heatmap 2D texture GLuint HeatmapTexID; ///< Texture ID of the heatmap 2D texture
GLuint ColormapTexID; ///< Texture ID of the colormap 1D texture GLuint ColormapTexID; ///< Texture ID of the colormap 1D texture
ImVec2 MinBounds; ///< Minimum bounds of the heatmap ImPlotPoint MinBounds; ///< Minimum bounds of the heatmap
ImVec2 MaxBounds; ///< Maximum bounds of the heatmap ImPlotPoint MaxBounds; ///< Maximum bounds of the heatmap
float MinValue; ///< Minimum value of the colormap float MinValue; ///< Minimum value of the colormap
float MaxValue; ///< Maximum value of the colormap float MaxValue; ///< Maximum value of the colormap
bool AxisLogX; ///< Whether the X axis is logarithmic or not bool AxisLogX; ///< Whether the X axis is logarithmic or not
@ -332,19 +332,19 @@ void SetHeatmapData(int itemID, const ImU64* values, int rows, int cols)
SetTextureData(itemID, Context.temp3.Data, rows, cols, GL_R32UI, GL_RED_INTEGER, GL_UNSIGNED_INT); SetTextureData(itemID, Context.temp3.Data, rows, cols, GL_R32UI, GL_RED_INTEGER, GL_UNSIGNED_INT);
} }
void SetAxisLog(int itemID, bool x_is_log, bool y_is_log, const ImVec2& bounds_min, const ImVec2& bounds_max) void SetAxisLog(int itemID, bool x_is_log, bool y_is_log, const ImPlotPoint& bounds_min, const ImPlotPoint& bounds_max)
{ {
ContextData& Context = *((ContextData*)GImPlot->backendCtx); ContextData& Context = *((ContextData*)GImPlot->backendCtx);
int idx = Context.ItemIDs.GetInt(itemID, -1); int idx = Context.ItemIDs.GetInt(itemID, -1);
HeatmapData& data = Context.HeatmapDataList[idx]; HeatmapData& data = Context.HeatmapDataList[idx];
data.AxisLogX = x_is_log; data.AxisLogX = x_is_log;
data.AxisLogY =y_is_log; data.AxisLogY = y_is_log;
data.MinBounds = bounds_min; data.MinBounds = bounds_min;
data.MaxBounds = bounds_max; data.MaxBounds = bounds_max;
} }
void RenderHeatmap(int itemID, ImDrawList& DrawList, const ImVec2& bounds_min, const ImVec2& bounds_max, float scale_min, float scale_max, ImPlotColormap colormap) void RenderHeatmap(int itemID, ImDrawList& DrawList, const ImVec2& bounds_min, const ImVec2& bounds_max, float scale_min, float scale_max, ImPlotColormap colormap, bool reverse_y)
{ {
ContextData& Context = *((ContextData*)GImPlot->backendCtx); ContextData& Context = *((ContextData*)GImPlot->backendCtx);
int idx = Context.ItemIDs.GetInt(itemID, Context.HeatmapDataList.Size); int idx = Context.ItemIDs.GetInt(itemID, Context.HeatmapDataList.Size);
@ -367,7 +367,7 @@ void RenderHeatmap(int itemID, ImDrawList& DrawList, const ImVec2& bounds_min, c
DrawList.AddCallback(RenderCallback, (void*)(intptr_t)itemID); DrawList.AddCallback(RenderCallback, (void*)(intptr_t)itemID);
DrawList.PrimReserve(6, 4); DrawList.PrimReserve(6, 4);
DrawList.PrimRectUV(bounds_min, bounds_max, ImVec2(0.0f, 1.0f), ImVec2(1.0f, 0.0f), 0); DrawList.PrimRectUV(bounds_min, bounds_max, ImVec2(0.0f, reverse_y ? 1.0f : 0.0f), ImVec2(1.0f, reverse_y ? 0.0f : 1.0f), 0);
DrawList.AddCallback(ResetState, nullptr); DrawList.AddCallback(ResetState, nullptr);
} }

View File

@ -188,7 +188,7 @@ IMPLOT_API void SetHeatmapData(int itemID, const ImU64* values, int rows, int c
*/ */
IMPLOT_API void RenderHeatmap( IMPLOT_API void RenderHeatmap(
int itemID, ImDrawList& DrawList, const ImVec2& bounds_min, const ImVec2& bounds_max, int itemID, ImDrawList& DrawList, const ImVec2& bounds_min, const ImVec2& bounds_max,
float scale_min, float scale_max, ImPlotColormap colormap); float scale_min, float scale_max, ImPlotColormap colormap, bool reverse_y);
/** /**
* @brief Set logarithmic axis * @brief Set logarithmic axis
@ -202,7 +202,7 @@ IMPLOT_API void RenderHeatmap(
* @param bounds_min Minimum bounds (for X & Y) of the heatmap * @param bounds_min Minimum bounds (for X & Y) of the heatmap
* @param bounds_min Maximum bounds (for X & Y) of the heatmap * @param bounds_min Maximum bounds (for X & Y) of the heatmap
*/ */
void SetAxisLog(int itemID, bool x_is_log, bool y_is_log, const ImVec2& bounds_min, const ImVec2& bounds_max); void SetAxisLog(int itemID, bool x_is_log, bool y_is_log, const ImPlotPoint& bounds_min, const ImPlotPoint& bounds_max);
} }
} }

View File

@ -1895,15 +1895,14 @@ void RenderHeatmap(Transformer transformer, ImDrawList& DrawList, const T* value
#ifdef IMPLOT_BACKEND_HAS_HEATMAP #ifdef IMPLOT_BACKEND_HAS_HEATMAP
ImVec2 bmin = transformer(bounds_min); ImVec2 bmin = transformer(bounds_min);
ImVec2 bmax = transformer(bounds_max); ImVec2 bmax = transformer(bounds_max);
ImPlotScale scale = GetCurrentScale(); ImPlotScale scale = GetCurrentScale();
// NOTE: Order is important! // NOTE: Order is important!
Backend::RenderHeatmap(gp.CurrentItem->ID, DrawList, bmin, bmax, scale_min, scale_max, gp.Style.Colormap); Backend::RenderHeatmap(gp.CurrentItem->ID, DrawList, bmin, bmax, scale_min, scale_max, gp.Style.Colormap, reverse_y);
Backend::SetAxisLog(gp.CurrentItem->ID, Backend::SetAxisLog(gp.CurrentItem->ID,
scale == ImPlotScale_LogLin || scale == ImPlotScale_LogLog, scale == ImPlotScale_LogLin || scale == ImPlotScale_LogLog,
scale == ImPlotScale_LinLog || scale == ImPlotScale_LogLog, scale == ImPlotScale_LinLog || scale == ImPlotScale_LogLog,
ImVec2(bounds_min.x, bounds_min.y), ImVec2(bounds_max.x, bounds_max.y)); bounds_min, bounds_max);
Backend::SetHeatmapData(gp.CurrentItem->ID, values, rows, cols); Backend::SetHeatmapData(gp.CurrentItem->ID, values, rows, cols);
#else #else
GetterHeatmap<T> getter(values, rows, cols, scale_min, scale_max, (bounds_max.x - bounds_min.x) / cols, (bounds_max.y - bounds_min.y) / rows, bounds_min.x, yref, ydir); GetterHeatmap<T> getter(values, rows, cols, scale_min, scale_max, (bounds_max.x - bounds_min.x) / cols, (bounds_max.y - bounds_min.y) / rows, bounds_min.x, yref, ydir);