MCPcopy Create free account
hub / github.com/chrxh/alien / processHistogramsTab

Method processHistogramsTab

source/Gui/StatisticsWindow.cpp:149–221  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

147}
148
149void StatisticsWindow::processHistogramsTab()
150{
151 if (!_histogramLiveStatistics.isDataAvailable()) {
152 return;
153 }
154 ImPlot::PushStyleColor(ImPlotCol_FrameBg, (ImU32)ImColor(0.0f, 0.0f, 0.0f, ImGui::GetStyle().Alpha * 0.5 * Const::WindowAlpha));
155 ImPlot::PushStyleColor(ImPlotCol_PlotBg, (ImU32)ImColor(0.0f, 0.0f, 0.0f, ImGui::GetStyle().Alpha * 0.5 * Const::WindowAlpha));
156 auto const& histogramData = _histogramLiveStatistics.getData();
157 auto maxNumObjects = 0;
158 for (int i = 0; i < MAX_COLORS; ++i) {
159 for (int j = 0; j < MAX_HISTOGRAM_SLOTS; ++j) {
160 auto value = histogramData->numCellsByColorBySlot[i][j];
161 maxNumObjects = std::max(maxNumObjects, value);
162 }
163 }
164
165 //round maxNumObjects
166 if (!_histogramUpperBound || toFloat(maxNumObjects) > *_histogramUpperBound * 0.9f || toFloat(maxNumObjects) < *_histogramUpperBound * 0.5f) {
167 _histogramUpperBound = toFloat(maxNumObjects) * 1.3f;
168 }
169
170 ImPlot::SetNextAxesLimits(0, toFloat(MAX_HISTOGRAM_SLOTS), 0, *_histogramUpperBound, ImGuiCond_Always);
171
172 auto getLabelString = [](int value) {
173 if (value >= 1000) {
174 return std::to_string(value / 1000) + "K";
175 } else {
176 return std::to_string(value);
177 }
178 };
179
180 //y-ticks
181 char const* labelsY[6];
182 double positionsY[6];
183 for (int i = 0; i < 5; ++i) {
184 labelsY[i] = "";
185 positionsY[i] = *_histogramUpperBound / 5 * i;
186 }
187 auto temp = getLabelString(maxNumObjects);
188 labelsY[5] = temp.c_str();
189 positionsY[5] = toFloat(maxNumObjects);
190
191 //x-ticks
192 char const* labelsX[5];
193 std::string labelsX_temp[5];
194 double positionsX[5];
195
196 auto slotAge = histogramData->maxValue / MAX_HISTOGRAM_SLOTS;
197 for (int i = 0; i < 5; ++i) {
198 labelsX_temp[i] = getLabelString(slotAge * ((MAX_HISTOGRAM_SLOTS - 1) / 4) * i);
199 labelsX[i] = labelsX_temp[i].c_str();
200 positionsX[i] = toFloat(((MAX_HISTOGRAM_SLOTS - 1) / 4) * i);
201 }
202
203
204 //plot histogram
205 if (ImPlot::BeginPlot("##Histograms", ImVec2(-1, -1))) {
206 ImPlot::SetupAxisTicks(ImAxis_Y1, positionsY, 5, labelsY);

Callers

nothing calls this directly

Calls 4

toFloatFunction · 0.85
to_stringFunction · 0.85
ImVec2Class · 0.85
isDataAvailableMethod · 0.45

Tested by

no test coverage detected