Skip to content

Adding extra flag to allow relative Histograms #622

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions implot.h
Original file line number Diff line number Diff line change
Expand Up @@ -304,9 +304,10 @@ enum ImPlotHistogramFlags_ {
ImPlotHistogramFlags_None = 0, // default
ImPlotHistogramFlags_Horizontal = 1 << 10, // histogram bars will be rendered horizontally (not supported by PlotHistogram2D)
ImPlotHistogramFlags_Cumulative = 1 << 11, // each bin will contain its count plus the counts of all previous bins (not supported by PlotHistogram2D)
ImPlotHistogramFlags_Density = 1 << 12, // counts will be normalized, i.e. the PDF will be visualized, or the CDF will be visualized if Cumulative is also set
ImPlotHistogramFlags_Density = 1 << 12, // counts will be normalized, i.e. the PDF will be visualized, or the CDF will be visualized if Cumulative is also set, or if ImPlotHistogramFlags_NormalizeIgnoreWidth is set the bin counts add up to 1
ImPlotHistogramFlags_NoOutliers = 1 << 13, // exclude values outside the specifed histogram range from the count toward normalizing and cumulative counts
ImPlotHistogramFlags_ColMajor = 1 << 14 // data will be read in column major order (not supported by PlotHistogram)
ImPlotHistogramFlags_ColMajor = 1 << 14, // data will be read in column major order (not supported by PlotHistogram)
ImPlotHistogramFlags_NormalizeIgnoreWidth = 1 << 15 // Ignore bin width for ImPlotHistogramFlags_Density, if both set, a relative histogram is plotted
};

// Flags for PlotDigital (placeholder)
Expand Down
4 changes: 3 additions & 1 deletion implot_items.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2545,6 +2545,7 @@ double PlotHistogram(const char* label_id, const T* values, int count, int bins,
const bool cumulative = ImHasFlag(flags, ImPlotHistogramFlags_Cumulative);
const bool density = ImHasFlag(flags, ImPlotHistogramFlags_Density);
const bool outliers = !ImHasFlag(flags, ImPlotHistogramFlags_NoOutliers);
const bool ignoreWidth = ImHasFlag(flags, ImPlotHistogramFlags_NormalizeIgnoreWidth);

if (count <= 0 || bins == 0)
return 0;
Expand Down Expand Up @@ -2606,7 +2607,8 @@ double PlotHistogram(const char* label_id, const T* values, int count, int bins,
max_count = bin_counts[bins-1];
}
else if (density) {
double scale = 1.0 / ((outliers ? count : counted) * width);
double selectedWidth = ignoreWidth ? 1.0 : width;
double scale = 1.0 / ((outliers ? count : counted) * selectedWidth);
for (int b = 0; b < bins; ++b)
bin_counts[b] *= scale;
max_count *= scale;
Expand Down