| 916 | //----------------------------------------------------------------------------- |
| 917 | |
| 918 | void Demo_DigitalPlots() { |
| 919 | IMGUI_DEMO_MARKER("Plots/Digital Plots"); |
| 920 | ImGui::BulletText("Digital plots do not respond to Y drag and zoom, so that"); |
| 921 | ImGui::Indent(); |
| 922 | ImGui::Text("you can drag analog plots over the rising/falling digital edge."); |
| 923 | ImGui::Unindent(); |
| 924 | |
| 925 | static bool paused = false; |
| 926 | static ScrollingBuffer dataDigital[3]; |
| 927 | static ScrollingBuffer dataAnalog[2]; |
| 928 | static bool showDigital[3] = {true, false, false}; |
| 929 | static bool showAnalog[2] = {true, false}; |
| 930 | |
| 931 | char label[32]; |
| 932 | ImGui::Checkbox("Pause", &paused); |
| 933 | ImGui::Checkbox("digital_0", &showDigital[0]); ImGui::SameLine(); |
| 934 | ImGui::Checkbox("digital_1", &showDigital[1]); ImGui::SameLine(); |
| 935 | ImGui::Checkbox("digital_2", &showDigital[2]); ImGui::SameLine(); |
| 936 | ImGui::Checkbox("analog_0", &showAnalog[0]); ImGui::SameLine(); |
| 937 | ImGui::Checkbox("analog_1", &showAnalog[1]); |
| 938 | |
| 939 | static float t = 0, last_t = 0; |
| 940 | if (!paused) { |
| 941 | t += ImGui::GetIO().DeltaTime; |
| 942 | if (t - last_t >= 0.01f) { |
| 943 | last_t = t; |
| 944 | // Digital signal values |
| 945 | if (showDigital[0]) |
| 946 | dataDigital[0].AddPoint(t, sinf(2*t) > 0.45); |
| 947 | if (showDigital[1]) |
| 948 | dataDigital[1].AddPoint(t, sinf(2*t) < 0.45); |
| 949 | if (showDigital[2]) |
| 950 | dataDigital[2].AddPoint(t, sinf(50*t) > 0.5); |
| 951 | // Analog signal values |
| 952 | if (showAnalog[0]) |
| 953 | dataAnalog[0].AddPoint(t, sinf(2*t)); |
| 954 | if (showAnalog[1]) |
| 955 | dataAnalog[1].AddPoint(t, cosf(2*t)); |
| 956 | } |
| 957 | } |
| 958 | if (ImPlot::BeginPlot("##Digital")) { |
| 959 | ImPlot::SetupAxisLimits(ImAxis_X1, t - 10.0, t, paused ? ImGuiCond_Once : ImGuiCond_Always); |
| 960 | ImPlot::SetupAxisLimits(ImAxis_Y1, -1, 1); |
| 961 | for (int i = 0; i < 3; ++i) { |
| 962 | if (showDigital[i] && dataDigital[i].Data.size() > 0) { |
| 963 | snprintf(label, sizeof(label), "digital_%d", i); |
| 964 | ImPlot::PlotDigital(label, &dataDigital[i].Data[0].x, &dataDigital[i].Data[0].y, dataDigital[i].Data.size(), { |
| 965 | ImPlotProp_Offset, dataDigital[i].Offset, |
| 966 | ImPlotProp_Stride, 2 * sizeof(float), |
| 967 | ImPlotProp_Size, (i+1) * 4 |
| 968 | }); |
| 969 | } |
| 970 | } |
| 971 | for (int i = 0; i < 2; ++i) { |
| 972 | if (showAnalog[i]) { |
| 973 | snprintf(label, sizeof(label), "analog_%d", i); |
| 974 | if (dataAnalog[i].Data.size() > 0) { |
| 975 | ImPlot::PlotLine(label, &dataAnalog[i].Data[0].x, &dataAnalog[i].Data[0].y, dataAnalog[i].Data.size(), { |
nothing calls this directly
no test coverage detected