MCPcopy Create free account
hub / github.com/SatDump/SatDump / PlotHistogram

Function PlotHistogram

src-core/imgui/implot/implot_items.cpp:2505–2581  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2503
2504template <typename T>
2505double PlotHistogram(const char* label_id, const T* values, int count, int bins, double bar_scale, ImPlotRange range, ImPlotHistogramFlags flags) {
2506
2507 const bool cumulative = ImHasFlag(flags, ImPlotHistogramFlags_Cumulative);
2508 const bool density = ImHasFlag(flags, ImPlotHistogramFlags_Density);
2509 const bool outliers = !ImHasFlag(flags, ImPlotHistogramFlags_NoOutliers);
2510
2511 if (count <= 0 || bins == 0)
2512 return 0;
2513
2514 if (range.Min == 0 && range.Max == 0) {
2515 T Min, Max;
2516 ImMinMaxArray(values, count, &Min, &Max);
2517 range.Min = (double)Min;
2518 range.Max = (double)Max;
2519 }
2520
2521 double width;
2522 if (bins < 0)
2523 CalculateBins(values, count, bins, range, bins, width);
2524 else
2525 width = range.Size() / bins;
2526
2527 ImPlotContext& gp = *GImPlot;
2528 ImVector<double>& bin_centers = gp.TempDouble1;
2529 ImVector<double>& bin_counts = gp.TempDouble2;
2530 bin_centers.resize(bins);
2531 bin_counts.resize(bins);
2532 int below = 0;
2533
2534 for (int b = 0; b < bins; ++b) {
2535 bin_centers[b] = range.Min + b * width + width * 0.5;
2536 bin_counts[b] = 0;
2537 }
2538 int counted = 0;
2539 double max_count = 0;
2540 for (int i = 0; i < count; ++i) {
2541 double val = (double)values[i];
2542 if (range.Contains(val)) {
2543 const int b = ImClamp((int)((val - range.Min) / width), 0, bins - 1);
2544 bin_counts[b] += 1.0;
2545 if (bin_counts[b] > max_count)
2546 max_count = bin_counts[b];
2547 counted++;
2548 }
2549 else if (val < range.Min) {
2550 below++;
2551 }
2552 }
2553 if (cumulative && density) {
2554 if (outliers)
2555 bin_counts[0] += below;
2556 for (int b = 1; b < bins; ++b)
2557 bin_counts[b] += bin_counts[b-1];
2558 double scale = 1.0 / (outliers ? count : counted);
2559 for (int b = 0; b < bins; ++b)
2560 bin_counts[b] *= scale;
2561 max_count = bin_counts[bins-1];
2562 }

Callers 3

ShowDemoWindowWidgetsFunction · 0.85
ShowDemoWindowLayoutFunction · 0.85
Demo_HistogramFunction · 0.85

Calls 8

ImHasFlagFunction · 0.85
ImMinMaxArrayFunction · 0.85
CalculateBinsFunction · 0.85
ImClampFunction · 0.85
PlotBarsFunction · 0.85
SizeMethod · 0.45
resizeMethod · 0.45
ContainsMethod · 0.45

Tested by

no test coverage detected