| 6545 | //------------------------------------------------------------------------- |
| 6546 | |
| 6547 | int ImGui::PlotEx(ImGuiPlotType plot_type, const char* label, float (*values_getter)(void* data, int idx), void* data, int values_count, int values_offset, const char* overlay_text, float scale_min, float scale_max, ImVec2 frame_size) |
| 6548 | { |
| 6549 | ImGuiContext& g = *GImGui; |
| 6550 | ImGuiWindow* window = GetCurrentWindow(); |
| 6551 | if (window->SkipItems) |
| 6552 | return -1; |
| 6553 | |
| 6554 | const ImGuiStyle& style = g.Style; |
| 6555 | const ImGuiID id = window->GetID(label); |
| 6556 | |
| 6557 | const ImVec2 label_size = CalcTextSize(label, NULL, true); |
| 6558 | if (frame_size.x == 0.0f) |
| 6559 | frame_size.x = CalcItemWidth(); |
| 6560 | if (frame_size.y == 0.0f) |
| 6561 | frame_size.y = label_size.y + (style.FramePadding.y * 2); |
| 6562 | |
| 6563 | const ImRect frame_bb(window->DC.CursorPos, window->DC.CursorPos + frame_size); |
| 6564 | const ImRect inner_bb(frame_bb.Min + style.FramePadding, frame_bb.Max - style.FramePadding); |
| 6565 | const ImRect total_bb(frame_bb.Min, frame_bb.Max + ImVec2(label_size.x > 0.0f ? style.ItemInnerSpacing.x + label_size.x : 0.0f, 0)); |
| 6566 | ItemSize(total_bb, style.FramePadding.y); |
| 6567 | if (!ItemAdd(total_bb, 0, &frame_bb)) |
| 6568 | return -1; |
| 6569 | const bool hovered = ItemHoverable(frame_bb, id); |
| 6570 | |
| 6571 | // Determine scale from values if not specified |
| 6572 | if (scale_min == FLT_MAX || scale_max == FLT_MAX) |
| 6573 | { |
| 6574 | float v_min = FLT_MAX; |
| 6575 | float v_max = -FLT_MAX; |
| 6576 | for (int i = 0; i < values_count; i++) |
| 6577 | { |
| 6578 | const float v = values_getter(data, i); |
| 6579 | if (v != v) // Ignore NaN values |
| 6580 | continue; |
| 6581 | v_min = ImMin(v_min, v); |
| 6582 | v_max = ImMax(v_max, v); |
| 6583 | } |
| 6584 | if (scale_min == FLT_MAX) |
| 6585 | scale_min = v_min; |
| 6586 | if (scale_max == FLT_MAX) |
| 6587 | scale_max = v_max; |
| 6588 | } |
| 6589 | |
| 6590 | RenderFrame(frame_bb.Min, frame_bb.Max, GetColorU32(ImGuiCol_FrameBg), true, style.FrameRounding); |
| 6591 | |
| 6592 | const int values_count_min = (plot_type == ImGuiPlotType_Lines) ? 2 : 1; |
| 6593 | int idx_hovered = -1; |
| 6594 | if (values_count >= values_count_min) |
| 6595 | { |
| 6596 | int res_w = ImMin((int)frame_size.x, values_count) + ((plot_type == ImGuiPlotType_Lines) ? -1 : 0); |
| 6597 | int item_count = values_count + ((plot_type == ImGuiPlotType_Lines) ? -1 : 0); |
| 6598 | |
| 6599 | // Tooltip on hover |
| 6600 | if (hovered && inner_bb.Contains(g.IO.MousePos)) |
| 6601 | { |
| 6602 | const float t = ImClamp((g.IO.MousePos.x - inner_bb.Min.x) / (inner_bb.Max.x - inner_bb.Min.x), 0.0f, 0.9999f); |
| 6603 | const int v_idx = (int)(t * item_count); |
| 6604 | IM_ASSERT(v_idx >= 0 && v_idx < values_count); |
nothing calls this directly
no test coverage detected