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

Function PlotHistogram

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

Source from the content-addressed store, hash-verified

3189
3190template <typename T>
3191double PlotHistogram(const char* label_id, const T* values, int count, int bins, double bar_scale, ImPlotRange range, const ImPlotSpec& spec) {
3192
3193 const bool cumulative = ImHasFlag(spec.Flags, ImPlotHistogramFlags_Cumulative);
3194 const bool density = ImHasFlag(spec.Flags, ImPlotHistogramFlags_Density);
3195 const bool outliers = !ImHasFlag(spec.Flags, ImPlotHistogramFlags_NoOutliers);
3196
3197 IndexerIdx<T> indexer(values,count,spec.Offset,Stride<T>(spec));
3198
3199 if (count <= 0 || bins == 0)
3200 return 0;
3201
3202 if (range.Min == 0 && range.Max == 0) {
3203 ImMinMaxIndexer(indexer, count, &range.Min, &range.Max);
3204 }
3205
3206 double width;
3207 if (bins < 0)
3208 CalculateBins(indexer, count, bins, range, bins, width);
3209 else
3210 width = range.Size() / bins;
3211
3212 ImPlotContext& gp = *GImPlot;
3213 ImVector<double>& bin_centers = gp.TempDouble1;
3214 ImVector<double>& bin_counts = gp.TempDouble2;
3215 bin_centers.resize(bins);
3216 bin_counts.resize(bins);
3217 int below = 0;
3218
3219 for (int b = 0; b < bins; ++b) {
3220 bin_centers[b] = range.Min + b * width + width * 0.5;
3221 bin_counts[b] = 0;
3222 }
3223 int counted = 0;
3224 double max_count = 0;
3225 for (int i = 0; i < count; ++i) {
3226 double val = indexer[i];
3227 if (range.Contains(val)) {
3228 const int b = ImClamp((int)((val - range.Min) / width), 0, bins - 1);
3229 bin_counts[b] += 1.0;
3230 if (bin_counts[b] > max_count)
3231 max_count = bin_counts[b];
3232 counted++;
3233 }
3234 else if (val < range.Min) {
3235 below++;
3236 }
3237 }
3238 if (cumulative && density) {
3239 if (outliers)
3240 bin_counts[0] += below;
3241 for (int b = 1; b < bins; ++b)
3242 bin_counts[b] += bin_counts[b-1];
3243 double scale = 1.0 / (outliers ? count : counted);
3244 for (int b = 0; b < bins; ++b)
3245 bin_counts[b] *= scale;
3246 max_count = bin_counts[bins-1];
3247 }
3248 else if (cumulative) {

Callers 3

Demo_HistogramFunction · 0.70
DemoWindowLayoutFunction · 0.50

Calls 8

ImHasFlagFunction · 0.85
ImMinMaxIndexerFunction · 0.85
CalculateBinsFunction · 0.85
ImClampFunction · 0.85
PlotBarsFunction · 0.85
SizeMethod · 0.65
resizeMethod · 0.45
ContainsMethod · 0.45

Tested by

no test coverage detected