From 127f44c12bc4b1e5b6d7eb90b9a934668b01e8c2 Mon Sep 17 00:00:00 2001 From: ocornut Date: Sun, 20 Sep 2015 13:29:18 +0200 Subject: [PATCH] Demo: Extra plotting examples. --- imgui_demo.cpp | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/imgui_demo.cpp b/imgui_demo.cpp index 28c5020c..7ecb0369 100644 --- a/imgui_demo.cpp +++ b/imgui_demo.cpp @@ -684,13 +684,29 @@ void ImGui::ShowTestWindow(bool* opened) phase += 0.10f*values_offset; } } - ImGui::PlotLines("##Graph", values.Data, values.Size, values_offset, "avg 0.0", -1.0f, 1.0f, ImVec2(0,80)); + ImGui::PlotLines("##Lines", values.Data, values.Size, values_offset, "avg 0.0", -1.0f, 1.0f, ImVec2(0,80)); ImGui::SameLine(0, ImGui::GetStyle().ItemInnerSpacing.x); ImGui::BeginGroup(); - ImGui::Text("Graph"); + ImGui::Text("Lines"); ImGui::Checkbox("pause", &pause); ImGui::EndGroup(); ImGui::PlotHistogram("Histogram", arr, IM_ARRAYSIZE(arr), 0, NULL, 0.0f, 1.0f, ImVec2(0,80)); + + // Use functions to generate output + // FIXME: This is rather awkward because current plot API only pass in indices. We probably want an API passing floats and user provide sample rate/count. + struct Funcs + { + static float Sin(void*, int i) { return sinf(i * 0.1f); } + static float Saw(void*, int i) { return (i & 1) ? 1.0f : 0.0f; } + }; + static int func_type = 0, display_count = 70; + ImGui::Separator(); + ImGui::PushItemWidth(100); ImGui::Combo("func", &func_type, "Sin\0Saw\0"); ImGui::PopItemWidth(); + ImGui::SameLine(); + ImGui::SliderInt("Sample count", &display_count, 1, 500); + float (*func)(void*, int) = (func_type == 0) ? Funcs::Sin : Funcs::Saw; + ImGui::PlotLines("Lines", func, NULL, display_count, 0, NULL, -1.0f, 1.0f, ImVec2(0,80)); + ImGui::PlotHistogram("Histogram", func, NULL, display_count, 0, NULL, -1.0f, 1.0f, ImVec2(0,80)); } if (ImGui::CollapsingHeader("Layout"))