MCPcopy Create free account
hub / github.com/KebsCS/KBotExt / PlotEx

Method PlotEx

KBotExt/imgui/imgui_widgets.cpp:6721–6834  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

6719//-------------------------------------------------------------------------
6720
6721int 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, const ImVec2& size_arg)
6722{
6723 ImGuiContext& g = *GImGui;
6724 ImGuiWindow* window = GetCurrentWindow();
6725 if (window->SkipItems)
6726 return -1;
6727
6728 const ImGuiStyle& style = g.Style;
6729 const ImGuiID id = window->GetID(label);
6730
6731 const ImVec2 label_size = CalcTextSize(label, NULL, true);
6732 const ImVec2 frame_size = CalcItemSize(size_arg, CalcItemWidth(), label_size.y + style.FramePadding.y * 2.0f);
6733
6734 const ImRect frame_bb(window->DC.CursorPos, window->DC.CursorPos + frame_size);
6735 const ImRect inner_bb(frame_bb.Min + style.FramePadding, frame_bb.Max - style.FramePadding);
6736 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));
6737 ItemSize(total_bb, style.FramePadding.y);
6738 if (!ItemAdd(total_bb, 0, &frame_bb))
6739 return -1;
6740 const bool hovered = ItemHoverable(frame_bb, id, g.LastItemData.InFlags);
6741
6742 // Determine scale from values if not specified
6743 if (scale_min == FLT_MAX || scale_max == FLT_MAX)
6744 {
6745 float v_min = FLT_MAX;
6746 float v_max = -FLT_MAX;
6747 for (int i = 0; i < values_count; i++)
6748 {
6749 const float v = values_getter(data, i);
6750 if (v != v) // Ignore NaN values
6751 continue;
6752 v_min = ImMin(v_min, v);
6753 v_max = ImMax(v_max, v);
6754 }
6755 if (scale_min == FLT_MAX)
6756 scale_min = v_min;
6757 if (scale_max == FLT_MAX)
6758 scale_max = v_max;
6759 }
6760
6761 RenderFrame(frame_bb.Min, frame_bb.Max, GetColorU32(ImGuiCol_FrameBg), true, style.FrameRounding);
6762
6763 const int values_count_min = (plot_type == ImGuiPlotType_Lines) ? 2 : 1;
6764 int idx_hovered = -1;
6765 if (values_count >= values_count_min)
6766 {
6767 int res_w = ImMin((int)frame_size.x, values_count) + ((plot_type == ImGuiPlotType_Lines) ? -1 : 0);
6768 int item_count = values_count + ((plot_type == ImGuiPlotType_Lines) ? -1 : 0);
6769
6770 // Tooltip on hover
6771 if (hovered && inner_bb.Contains(g.IO.MousePos))
6772 {
6773 const float t = ImClamp((g.IO.MousePos.x - inner_bb.Min.x) / (inner_bb.Max.x - inner_bb.Min.x), 0.0f, 0.9999f);
6774 const int v_idx = (int)(t * item_count);
6775 IM_ASSERT(v_idx >= 0 && v_idx < values_count);
6776
6777 const float v0 = values_getter(data, (v_idx + values_offset) % values_count);
6778 const float v1 = values_getter(data, (v_idx + 1 + values_offset) % values_count);

Callers

nothing calls this directly

Calls 12

GetCurrentWindowFunction · 0.85
ImVec2Function · 0.85
ItemSizeFunction · 0.85
ImMinFunction · 0.85
ImMaxFunction · 0.85
ImClampFunction · 0.85
ImSaturateFunction · 0.85
ImLerpFunction · 0.85
GetIDMethod · 0.80
ContainsMethod · 0.80
AddLineMethod · 0.80
AddRectFilledMethod · 0.80

Tested by

no test coverage detected