diff --git a/implot.h b/implot.h index 8503e81..1565ca4 100644 --- a/implot.h +++ b/implot.h @@ -474,8 +474,8 @@ template IMPLOT_API void PlotHLines(const char* label_id, const T* // Plots a pie chart. If the sum of values > 1 or normalize is true, each value will be normalized. Center and radius are in plot units. #label_fmt can be set to NULL for no labels. template IMPLOT_API void PlotPieChart(const char* const label_ids[], const T* values, int count, double x, double y, double radius, bool normalize=false, const char* label_fmt="%.1f", double angle0=90); -// Plots a 2D heatmap chart. Values are expected to be in row-major order. #label_fmt can be set to NULL for no labels. -template IMPLOT_API void PlotHeatmap(const char* label_id, const T* values, int rows, int cols, double scale_min, double scale_max, const char* label_fmt="%.1f", const ImPlotPoint& bounds_min=ImPlotPoint(0,0), const ImPlotPoint& bounds_max=ImPlotPoint(1,1)); +// Plots a 2D heatmap chart. Values are expected to be in row-major order. Leave #scale_min and scale_max both at 0 for automatic color scaling, or set them to a predefined range. #label_fmt can be set to NULL for no labels. +template IMPLOT_API void PlotHeatmap(const char* label_id, const T* values, int rows, int cols, double scale_min=0, double scale_max=0, const char* label_fmt="%.1f", const ImPlotPoint& bounds_min=ImPlotPoint(0,0), const ImPlotPoint& bounds_max=ImPlotPoint(1,1)); // Plots a horizontal histogram. #bins can be a positive integer or an ImPlotBin_ method. If #cumulative is true, each bin contains its count plus the counts of all previous bins. // If #density is true, the PDF is visualized. If both are true, the CDF is visualized. If #range is left unspecified, the min/max of #values will be used as the range. diff --git a/implot_items.cpp b/implot_items.cpp index 99cd6b0..9ef8507 100644 --- a/implot_items.cpp +++ b/implot_items.cpp @@ -1847,6 +1847,12 @@ struct GetterHeatmap { template void RenderHeatmap(Transformer transformer, ImDrawList& DrawList, const T* values, int rows, int cols, double scale_min, double scale_max, const char* fmt, const ImPlotPoint& bounds_min, const ImPlotPoint& bounds_max, bool reverse_y) { ImPlotContext& gp = *GImPlot; + if (scale_min == 0 && scale_max == 0) { + T temp_min, temp_max; + ImMinMaxArray(values,rows*cols,&temp_min,&temp_max); + scale_min = (double)temp_min; + scale_max = (double)temp_max; + } if (scale_min == scale_max) { ImVec2 a = transformer(bounds_min); ImVec2 b = transformer(bounds_max);