| 291 | } |
| 292 | |
| 293 | void ProfilerUI::renderGraph(const ImVec2& size, size_t highlightIndex, size_t& newHighlightIndex) |
| 294 | { |
| 295 | ImVec2 mousePos = ImGui::GetMousePos(); |
| 296 | ImVec2 screenPos = ImGui::GetCursorScreenPos(); |
| 297 | mousePos.x -= screenPos.x; |
| 298 | mousePos.y -= screenPos.y; |
| 299 | |
| 300 | float totalMaxGraphValue = 0.f; |
| 301 | for (const auto& eventData : mEventData) |
| 302 | totalMaxGraphValue += eventData.level == 0 ? eventData.maxGraphValue : 0.f; |
| 303 | |
| 304 | const float scaleY = size.y / totalMaxGraphValue; |
| 305 | |
| 306 | float x = 0.f; |
| 307 | float levelY[128]; |
| 308 | std::optional<float> highlightValue; |
| 309 | |
| 310 | for (size_t k = 0; k < mHistoryLength; ++k) |
| 311 | { |
| 312 | size_t historyIndex = (mHistoryWrite + kHistoryCapacity - k - 1) % kHistoryCapacity; |
| 313 | |
| 314 | float totalValue = 0.f; |
| 315 | for (const auto& eventData : mEventData) |
| 316 | { |
| 317 | totalValue += eventData.level == 0 ? eventData.graphHistory[historyIndex] : 0.f; |
| 318 | } |
| 319 | |
| 320 | levelY[0] = size.y - totalValue * scaleY; |
| 321 | float highlightY = 0.f; |
| 322 | float highlightHeight = 0.f; |
| 323 | |
| 324 | for (size_t i = 0; i < mEventData.size(); ++i) |
| 325 | { |
| 326 | const auto& eventData = mEventData[i]; |
| 327 | float value = eventData.graphHistory[historyIndex]; |
| 328 | uint32_t level = eventData.level; |
| 329 | |
| 330 | float y = levelY[level]; |
| 331 | float height = value * scaleY; |
| 332 | drawRectFilled(ImVec2(x, y), ImVec2(kGraphBarWidth, height), eventData.color); |
| 333 | |
| 334 | // Check if mouse is over this bar for tooltip value and highlighting in next frame. |
| 335 | if (mousePos.x >= x && mousePos.x < x + kGraphBarWidth && mousePos.y >= y && mousePos.y < y + height) |
| 336 | { |
| 337 | newHighlightIndex = i; |
| 338 | highlightValue = value / totalValue; |
| 339 | } |
| 340 | |
| 341 | if (highlightIndex == i) |
| 342 | { |
| 343 | highlightY = y; |
| 344 | highlightHeight = height; |
| 345 | } |
| 346 | |
| 347 | levelY[level + 1] = levelY[level]; |
| 348 | levelY[level] += height; |
| 349 | } |
| 350 |
nothing calls this directly
no test coverage detected