MCPcopy Create free account
hub / github.com/IppClub/Dora-SSR / RenderHeatmap

Function RenderHeatmap

Source/3rdParty/implot/implot_items.cpp:3100–3166  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3098
3099template <typename T>
3100void RenderHeatmap(ImDrawList& draw_list, IndexerIdx<T> indexer, int rows, int cols, double scale_min, double scale_max, const char* fmt, const ImPlotPoint& bounds_min, const ImPlotPoint& bounds_max, bool reverse_y, bool col_maj) {
3101 ImPlotContext& gp = *GImPlot;
3102 Transformer2 transformer;
3103 if (scale_min == 0 && scale_max == 0) {
3104 ImMinMaxIndexer(indexer,rows*cols,&scale_min,&scale_max);
3105 }
3106 if (scale_min == scale_max) {
3107 ImVec2 a = transformer(bounds_min);
3108 ImVec2 b = transformer(bounds_max);
3109 ImU32 col = GetColormapColorU32(0,gp.Style.Colormap);
3110 draw_list.AddRectFilled(a, b, col);
3111 return;
3112 }
3113 const double yref = reverse_y ? bounds_max.y : bounds_min.y;
3114 const double ydir = reverse_y ? -1 : 1;
3115 if (col_maj) {
3116 GetterHeatmapColMaj<IndexerIdx<T>> getter(indexer, 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);
3117 RenderPrimitives1<RendererRectC>(getter);
3118 }
3119 else {
3120 GetterHeatmapRowMaj<IndexerIdx<T>> getter(indexer, 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);
3121 RenderPrimitives1<RendererRectC>(getter);
3122 }
3123 // labels
3124 if (fmt != nullptr) {
3125 const double w = (bounds_max.x - bounds_min.x) / cols;
3126 const double h = (bounds_max.y - bounds_min.y) / rows;
3127 const ImPlotPoint half_size(w*0.5,h*0.5);
3128 int i = 0;
3129 if (col_maj) {
3130 for (int c = 0; c < cols; ++c) {
3131 for (int r = 0; r < rows; ++r) {
3132 ImPlotPoint p;
3133 p.x = bounds_min.x + 0.5*w + c*w;
3134 p.y = yref + ydir * (0.5*h + r*h);
3135 ImVec2 px = transformer(p);
3136 char buff[32];
3137 ImFormatString(buff, 32, fmt, indexer[i]);
3138 ImVec2 size = ImGui::CalcTextSize(buff);
3139 double t = ImClamp(ImRemap01((double)indexer[i], scale_min, scale_max),0.0,1.0);
3140 ImVec4 color = SampleColormap((float)t);
3141 ImU32 col = CalcTextColor(color);
3142 draw_list.AddText(px - size * 0.5f, col, buff);
3143 i++;
3144 }
3145 }
3146 }
3147 else {
3148 for (int r = 0; r < rows; ++r) {
3149 for (int c = 0; c < cols; ++c) {
3150 ImPlotPoint p;
3151 p.x = bounds_min.x + 0.5*w + c*w;
3152 p.y = yref + ydir * (0.5*h + r*h);
3153 ImVec2 px = transformer(p);
3154 char buff[32];
3155 ImFormatString(buff, 32, fmt, indexer[i]);
3156 ImVec2 size = ImGui::CalcTextSize(buff);
3157 double t = ImClamp(ImRemap01((double)indexer[i], scale_min, scale_max),0.0,1.0);

Callers 2

PlotHeatmapFunction · 0.85
PlotHistogram2DFunction · 0.85

Calls 9

ImMinMaxIndexerFunction · 0.85
GetColormapColorU32Function · 0.85
ImFormatStringFunction · 0.85
ImClampFunction · 0.85
ImRemap01Function · 0.85
SampleColormapFunction · 0.85
CalcTextColorFunction · 0.85
AddRectFilledMethod · 0.80
AddTextMethod · 0.80

Tested by

no test coverage detected