1
0
Fork 0
mirror of https://github.com/gwm17/implot.git synced 2024-10-09 15:47:26 -04:00
implot/implot_demo.cpp

1109 lines
53 KiB
C++
Raw Normal View History

2020-04-27 11:27:59 -04:00
// MIT License
// Copyright (c) 2020 Evan Pezent
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
2020-08-07 14:04:31 -04:00
// ImPlot v0.5 WIP
2020-05-11 07:13:43 -04:00
#include "implot.h"
#include <math.h>
2020-04-30 10:02:02 -04:00
#include <stdio.h>
2020-05-11 07:13:43 -04:00
#include <stdlib.h>
2020-04-27 11:27:59 -04:00
#ifdef _MSC_VER
#define sprintf sprintf_s
#endif
2020-04-27 11:27:59 -04:00
2020-08-17 21:20:15 -04:00
namespace MyImPlot {
// Example for Custom Plotters section. Plots a candlestick chart for financial data. See implementatoin at bottom.
void PlotCandlestick(const char* label_id, const double* xs, const double* opens, const double* closes, const double* lows, const double* highs, int count,
float tail_width = 1, float real_width = 5, ImVec4 bullCol = ImVec4(0,1,0,1), ImVec4 bearCol = ImVec4(1,0,0,1));
}
2020-06-14 09:31:09 -04:00
namespace ImPlot {
2020-05-29 13:39:30 -04:00
/// Choose whether the demo uses double or float versions of the ImPlot API.
/// NB: You don't ever need to typdef of define values for ImPlot. This
/// is only being done here for the sake of demoing both precision types.
2020-06-14 09:31:09 -04:00
// #define IMPLOT_DEMO_USE_DOUBLE
2020-05-29 13:39:30 -04:00
#ifdef IMPLOT_DEMO_USE_DOUBLE
typedef double t_float;
typedef ImPlotPoint t_float2;
#define Sin sin
#define Cos cos
#define Pow pow
#define Log log
#define Fmod fmod
#else
typedef float t_float;
typedef ImVec2 t_float2;
#define Sin sinf
#define Cos cosf
#define Pow powf
#define Log logf
#define Fmod fmodf
#endif
t_float RandomRange(t_float min, t_float max) {
t_float scale = rand() / (t_float) RAND_MAX;
return min + scale * ( max - min );
}
2020-05-29 13:39:30 -04:00
// utility structure for realtime plot
2020-04-27 11:27:59 -04:00
struct ScrollingData {
int MaxSize;
int Offset;
2020-05-29 13:39:30 -04:00
ImVector<t_float2> Data;
ScrollingData() {
MaxSize = 2000;
Offset = 0;
Data.reserve(MaxSize);
}
2020-05-29 13:39:30 -04:00
void AddPoint(t_float x, t_float y) {
2020-04-30 09:47:14 -04:00
if (Data.size() < MaxSize)
2020-05-29 13:39:30 -04:00
Data.push_back(t_float2(x,y));
2020-04-30 09:47:14 -04:00
else {
2020-05-29 13:39:30 -04:00
Data[Offset] = t_float2(x,y);
2020-04-30 09:47:14 -04:00
Offset = (Offset + 1) % MaxSize;
}
}
void Erase() {
if (Data.size() > 0) {
Data.shrink(0);
2020-04-30 09:47:14 -04:00
Offset = 0;
}
}
2020-04-27 11:27:59 -04:00
};
2020-05-29 13:39:30 -04:00
// utility structure for realtime plot
2020-04-27 11:27:59 -04:00
struct RollingData {
2020-05-29 13:39:30 -04:00
t_float Span;
ImVector<t_float2> Data;
RollingData() {
Span = 10.0f;
Data.reserve(2000);
}
2020-05-29 13:39:30 -04:00
void AddPoint(t_float x, t_float y) {
t_float xmod = Fmod(x, Span);
2020-04-30 09:47:14 -04:00
if (!Data.empty() && xmod < Data.back().x)
Data.shrink(0);
2020-05-29 13:39:30 -04:00
Data.push_back(t_float2(xmod, y));
2020-04-30 09:47:14 -04:00
}
2020-04-30 09:00:08 -04:00
};
2020-05-29 13:39:30 -04:00
// utility structure for benchmark data
struct BenchmarkItem {
BenchmarkItem() {
2020-05-29 13:39:30 -04:00
t_float y = RandomRange(0,1);
Data = new t_float2[1000];
for (int i = 0; i < 1000; ++i) {
2020-05-03 01:24:10 -04:00
Data[i].x = i*0.001f;
Data[i].y = y + RandomRange(-0.01f,0.01f);
}
2020-05-29 13:39:30 -04:00
Col = ImVec4((float)RandomRange(0,1),(float)RandomRange(0,1),(float)RandomRange(0,1),1);
}
2020-06-12 08:59:17 -04:00
~BenchmarkItem() { delete[] Data; }
2020-05-29 13:39:30 -04:00
t_float2* Data;
ImVec4 Col;
2020-04-27 11:27:59 -04:00
};
2020-05-12 05:20:23 -04:00
void ShowDemoWindow(bool* p_open) {
2020-06-02 13:34:14 -04:00
static const char* cmap_names[] = {"Default","Dark","Pastel","Paired","Viridis","Plasma","Hot","Cool","Pink","Jet"};
2020-05-12 05:20:23 -04:00
static bool show_app_metrics = false;
static bool show_app_style_editor = false;
if (show_app_metrics) { ImGui::ShowMetricsWindow(&show_app_metrics); }
if (show_app_style_editor) { ImGui::Begin("Style Editor", &show_app_style_editor); ImGui::ShowStyleEditor(); ImGui::End(); }
2020-05-03 01:24:10 -04:00
ImGui::SetNextWindowPos(ImVec2(50, 50), ImGuiCond_FirstUseEver);
2020-06-01 23:14:22 -04:00
ImGui::SetNextWindowSize(ImVec2(530, 750), ImGuiCond_FirstUseEver);
2020-05-12 05:20:23 -04:00
ImGui::Begin("ImPlot Demo", p_open, ImGuiWindowFlags_MenuBar);
if (ImGui::BeginMenuBar()) {
if (ImGui::BeginMenu("Tools")) {
ImGui::MenuItem("Metrics", NULL, &show_app_metrics);
ImGui::MenuItem("Style Editor (ImGui)", NULL, &show_app_style_editor);
ImGui::EndMenu();
}
ImGui::EndMenuBar();
}
//-------------------------------------------------------------------------
2020-08-07 14:04:31 -04:00
ImGui::Text("ImPlot says hello. (0.5 WIP)");
2020-04-30 09:47:14 -04:00
if (ImGui::CollapsingHeader("Help")) {
ImGui::Text("USER GUIDE:");
ImGui::BulletText("Left click and drag within the plot area to pan X and Y axes.");
ImGui::Indent();
ImGui::BulletText("Left click and drag on an axis to pan an individual axis.");
ImGui::Unindent();
2020-04-30 09:47:14 -04:00
ImGui::BulletText("Scroll in the plot area to zoom both X any Y axes.");
ImGui::Indent();
ImGui::BulletText("Scroll on an axis to zoom an individual axis.");
ImGui::Unindent();
2020-04-30 09:47:14 -04:00
ImGui::BulletText("Right click and drag to box select data.");
ImGui::Indent();
ImGui::BulletText("Hold Alt to expand box selection horizontally.");
ImGui::BulletText("Hold Shift to expand box selection vertically.");
ImGui::BulletText("Left click while box selecting to cancel the selection.");
ImGui::Unindent();
ImGui::BulletText("Double left click to fit all visible data.");
ImGui::Indent();
ImGui::BulletText("Double left click on an axis to fit the individual axis.");
ImGui::Unindent();
2020-04-30 09:47:14 -04:00
ImGui::BulletText("Double right click to open the plot context menu.");
ImGui::BulletText("Click legend label icons to show/hide plot items.");
ImGui::BulletText("IMPORTANT: By default, anti-aliased lines are turned OFF.");
ImGui::Indent();
ImGui::BulletText("Software AA can be enabled per plot with ImPlotFlags_AntiAliased.");
ImGui::BulletText("AA for demo plots can be enabled from the plot's context menu.");
ImGui::BulletText("If permitable, you are better off using hardware AA (e.g. MSAA).");
ImGui::Unindent();
2020-05-29 13:39:30 -04:00
#ifdef IMPLOT_DEMO_USE_DOUBLE
ImGui::BulletText("The demo data precision is: double");
#else
ImGui::BulletText("The demo data precision is: float");
2020-05-31 10:17:07 -04:00
#endif
2020-04-30 09:47:14 -04:00
}
//-------------------------------------------------------------------------
if (ImGui::CollapsingHeader("Line Plots")) {
2020-05-29 13:39:30 -04:00
static t_float xs1[1001], ys1[1001];
2020-04-30 09:47:14 -04:00
for (int i = 0; i < 1001; ++i) {
xs1[i] = i * 0.001f;
2020-05-29 13:39:30 -04:00
ys1[i] = 0.5f + 0.5f * Sin(50 * xs1[i]);
2020-04-30 09:47:14 -04:00
}
2020-05-29 13:39:30 -04:00
static t_float xs2[11], ys2[11];
2020-04-30 09:47:14 -04:00
for (int i = 0; i < 11; ++i) {
xs2[i] = i * 0.1f;
ys2[i] = xs2[i] * xs2[i];
}
static float weight = ImPlot::GetStyle().LineWeight;
ImGui::BulletText("Anti-aliasing can be enabled from the plot's context menu (see Help).");
ImGui::DragFloat("Line Weight", &weight, 0.05f, 1.0f, 5.0f, "%.2f px");
2020-05-16 10:11:29 -04:00
if (ImPlot::BeginPlot("Line Plot", "x", "f(x)")) {
ImPlot::PushStyleVar(ImPlotStyleVar_LineWeight, weight);
2020-05-31 17:32:32 -04:00
ImPlot::PlotLine("0.5 + 0.5*sin(50*x)", xs1, ys1, 1001);
ImPlot::PushStyleVar(ImPlotStyleVar_Marker, ImPlotMarker_Circle);
ImPlot::PlotLine("x^2", xs2, ys2, 11);
ImPlot::PopStyleVar(2);
2020-05-12 05:20:23 -04:00
ImPlot::EndPlot();
2020-04-30 09:47:14 -04:00
}
}
//-------------------------------------------------------------------------
if (ImGui::CollapsingHeader("Filled Line Plots")) {
2020-06-13 13:42:47 -04:00
static t_float xs1[101], ys1[101], ys2[101], ys3[101];
srand(0);
for (int i = 0; i < 101; ++i) {
xs1[i] = (float)i;
ys1[i] = RandomRange(400,450);
ys2[i] = RandomRange(275,350);
ys3[i] = RandomRange(150,225);
}
static bool show_lines = true;
static bool show_fills = true;
static float fill_ref = 0;
ImGui::Checkbox("Lines",&show_lines); ImGui::SameLine();
ImGui::Checkbox("Fills",&show_fills);
ImGui::DragFloat("Reference",&fill_ref, 1, -100, 500);
ImPlot::SetNextPlotLimits(0,100,0,500);
if (ImPlot::BeginPlot("Stock Prices", "Days", "Price")) {
if (show_fills) {
ImPlot::PushStyleVar(ImPlotStyleVar_FillAlpha, 0.25f);
ImPlot::PlotShaded("Stock 1", xs1, ys1, 101, fill_ref);
ImPlot::PlotShaded("Stock 2", xs1, ys2, 101, fill_ref);
ImPlot::PlotShaded("Stock 3", xs1, ys3, 101, fill_ref);
ImPlot::PopStyleVar();
}
if (show_lines) {
ImPlot::PlotLine("Stock 1", xs1, ys1, 101);
ImPlot::PlotLine("Stock 2", xs1, ys2, 101);
ImPlot::PlotLine("Stock 3", xs1, ys3, 101);
}
ImPlot::EndPlot();
}
}
2020-05-31 17:32:32 -04:00
//-------------------------------------------------------------------------
2020-06-13 13:59:48 -04:00
if (ImGui::CollapsingHeader("Shaded Plots")) {
static t_float xs[1001], ys[1001], ys1[1001], ys2[1001], ys3[1001], ys4[1001];
srand(0);
for (int i = 0; i < 1001; ++i) {
xs[i] = i * 0.001f;
ys[i] = 0.25f + 0.25f * Sin(25 * xs[i]) * Sin(5 * xs[i]) + RandomRange(-0.01f, 0.01f);
ys1[i] = ys[i] + RandomRange(0.1f, 0.12f);
ys2[i] = ys[i] - RandomRange(0.1f, 0.12f);
ys3[i] = 0.75f + 0.2f * Sin(25 * xs[i]);
ys4[i] = 0.75f + 0.1f * Cos(25 * xs[i]);
2020-06-13 13:59:48 -04:00
}
static float alpha = 0.25f;
ImGui::DragFloat("Alpha",&alpha,0.01f,0,1);
if (ImPlot::BeginPlot("Shaded Plots")) {
ImPlot::PushStyleVar(ImPlotStyleVar_FillAlpha, alpha);
ImPlot::PlotShaded("Uncertain Data",xs,ys1,ys2,1001);
ImPlot::PlotLine("Uncertain Data", xs, ys, 1001);
ImPlot::PlotShaded("Overlapping",xs,ys3,ys4,1001);
ImPlot::PlotLine("Overlapping",xs,ys3,1001);
ImPlot::PlotLine("Overlapping",xs,ys4,1001);
ImPlot::PopStyleVar();
ImPlot::EndPlot();
}
}
//-------------------------------------------------------------------------
2020-04-30 09:47:14 -04:00
if (ImGui::CollapsingHeader("Scatter Plots")) {
srand(0);
2020-05-29 13:39:30 -04:00
static t_float xs1[100], ys1[100];
2020-04-30 09:47:14 -04:00
for (int i = 0; i < 100; ++i) {
xs1[i] = i * 0.01f;
2020-05-29 13:39:30 -04:00
ys1[i] = xs1[i] + 0.1f * ((t_float)rand() / (t_float)RAND_MAX);
2020-04-30 09:47:14 -04:00
}
2020-05-29 13:39:30 -04:00
static t_float xs2[50], ys2[50];
2020-04-30 09:47:14 -04:00
for (int i = 0; i < 50; i++) {
2020-05-29 13:39:30 -04:00
xs2[i] = 0.25f + 0.2f * ((t_float)rand() / (t_float)RAND_MAX);
ys2[i] = 0.75f + 0.2f * ((t_float)rand() / (t_float)RAND_MAX);
2020-04-30 09:47:14 -04:00
}
2020-05-16 10:11:29 -04:00
if (ImPlot::BeginPlot("Scatter Plot", NULL, NULL)) {
ImPlot::PlotScatter("Data 1", xs1, ys1, 100);
ImPlot::PushStyleVar(ImPlotStyleVar_MarkerSize, 6);
ImPlot::PushStyleVar(ImPlotStyleVar_Marker, ImPlotMarker_Square);
ImPlot::PushStyleVar(ImPlotStyleVar_FillAlpha, 0.25f);
ImPlot::PlotScatter("Data 2", xs2, ys2, 50);
ImPlot::PopStyleVar(3);
2020-05-12 05:20:23 -04:00
ImPlot::EndPlot();
2020-04-30 09:47:14 -04:00
}
}
//-------------------------------------------------------------------------
if (ImGui::CollapsingHeader("Bar Plots")) {
2020-06-03 15:37:01 -04:00
static const char* labels[] = {"S1","S2","S3","S4","S5","S6","S7","S8","S9","S10"};
static const double positions[] = {0,1,2,3,4,5,6,7,8,9};
2020-04-30 09:47:14 -04:00
static bool horz = false;
ImGui::Checkbox("Horizontal",&horz);
2020-06-03 15:37:01 -04:00
if (horz) {
2020-05-29 13:39:30 -04:00
ImPlot::SetNextPlotLimits(0, 110, -0.5, 9.5, ImGuiCond_Always);
2020-06-03 15:37:01 -04:00
ImPlot::SetNextPlotTicksY(positions, 10, labels);
}
else {
2020-05-29 13:39:30 -04:00
ImPlot::SetNextPlotLimits(-0.5, 9.5, 0, 110, ImGuiCond_Always);
2020-06-03 15:37:01 -04:00
ImPlot::SetNextPlotTicksX(positions, 10, labels);
}
2020-05-16 10:11:29 -04:00
if (ImPlot::BeginPlot("Bar Plot", horz ? "Score": "Student", horz ? "Student" : "Score")) {
2020-05-29 13:39:30 -04:00
static t_float midtm[10] = {83, 67, 23, 89, 83, 78, 91, 82, 85, 90};
static t_float final[10] = {80, 62, 56, 99, 55, 78, 88, 78, 90, 100};
static t_float grade[10] = {80, 69, 52, 92, 72, 78, 75, 76, 89, 95};
2020-04-30 09:47:14 -04:00
if (horz) {
2020-05-16 10:14:48 -04:00
ImPlot::PlotBarsH("Midterm Exam", midtm, 10, 0.2f, -0.2f);
ImPlot::PlotBarsH("Final Exam", final, 10, 0.2f, 0);
ImPlot::PlotBarsH("Course Grade", grade, 10, 0.2f, 0.2f);
2020-04-30 09:47:14 -04:00
}
else {
2020-05-16 10:14:48 -04:00
ImPlot::PlotBars("Midterm Exam", midtm, 10, 0.2f, -0.2f);
ImPlot::PlotBars("Final Exam", final, 10, 0.2f, 0);
ImPlot::PlotBars("Course Grade", grade, 10, 0.2f, 0.2f);
2020-04-30 09:47:14 -04:00
}
2020-05-12 05:20:23 -04:00
ImPlot::EndPlot();
2020-04-30 09:47:14 -04:00
}
}
//-------------------------------------------------------------------------
if (ImGui::CollapsingHeader("Error Bars")) {
2020-05-29 13:39:30 -04:00
t_float xs[5] = {1,2,3,4,5};
t_float bar[5] = {1,2,5,3,4};
t_float lin1[5] = {8,8,9,7,8};
t_float lin2[5] = {6,7,6,9,6};
2020-05-29 13:39:30 -04:00
t_float err1[5] = {0.2f, 0.4f, 0.2f, 0.6f, 0.4f};
t_float err2[5] = {0.4f, 0.2f, 0.4f, 0.8f, 0.6f};
2020-06-07 19:19:14 -04:00
t_float err3[5] = {0.09f, 0.14f, 0.09f, 0.12f, 0.16f};
t_float err4[5] = {0.02f, 0.08f, 0.15f, 0.05f, 0.2f};
static float size = ImPlot::GetStyle().ErrorBarSize;
static float weight = ImPlot::GetStyle().ErrorBarWeight;
ImGui::DragFloat("Error Bar Size", &size, 0.1f, 0, 10,"%.2f px");
ImGui::DragFloat("Error Bar Weight",&weight,0.01f,1,3,"%.2f px");
2020-05-12 05:20:23 -04:00
ImPlot::SetNextPlotLimits(0, 6, 0, 10);
2020-05-16 10:11:29 -04:00
if (ImPlot::BeginPlot("##ErrorBars",NULL,NULL)) {
ImPlot::PushStyleVar(ImPlotStyleVar_ErrorBarSize, size);
ImPlot::PushStyleVar(ImPlotStyleVar_ErrorBarWeight, weight);
2020-05-16 10:14:48 -04:00
ImPlot::PlotBars("Bar", xs, bar, 5, 0.5f);
// error bars can be grouped with the associated item by using the same label ID
ImPlot::PlotErrorBars("Bar", xs, bar, err1, 5);
ImPlot::PushStyleVar(ImPlotStyleVar_Marker, ImPlotMarker_Circle);
2020-05-12 05:20:23 -04:00
ImPlot::PushStyleVar(ImPlotStyleVar_MarkerSize, 3);
ImPlot::PushStyleColor(ImPlotCol_ErrorBar, ImPlot::GetColormapColor(1));
ImPlot::PlotErrorBars("Line1", xs, lin1, err1, err2, 5);
ImPlot::PlotLine("Line1", xs, lin1, 5);
ImPlot::PushStyleVar(ImPlotStyleVar_Marker, ImPlotMarker_Square);
ImPlot::PushStyleVar(ImPlotStyleVar_MarkerSize, 3);
ImPlot::PushStyleColor(ImPlotCol_ErrorBar, ImPlot::GetColormapColor(2));
ImPlot::PlotErrorBars("Line2", xs, lin2, err2, 5);
ImPlot::PlotErrorBarsH("Line2", xs, lin2, err3, err4, 5);
ImPlot::PlotLine("Line2", xs, lin2, 5);
ImPlot::PopStyleVar(6);
ImPlot::PopStyleColor(2);
2020-05-12 05:20:23 -04:00
ImPlot::EndPlot();
2020-04-30 09:47:14 -04:00
}
}
2020-05-03 01:24:10 -04:00
//-------------------------------------------------------------------------
if (ImGui::CollapsingHeader("Pie Charts")) {
2020-05-05 00:25:47 -04:00
static const char* labels1[] = {"Frogs","Hogs","Dogs","Logs"};
static float data1[] = {0.15f, 0.30f, 0.2f, 0.05f};
static bool normalize = false;
ImGui::SetNextItemWidth(250);
ImGui::DragFloat4("Values", data1, 0.01f, 0, 1);
if ((data1[0] + data1[1] + data1[2] + data1[3]) < 1) {
ImGui::SameLine();
ImGui::Checkbox("Normalize", &normalize);
}
2020-05-11 07:13:43 -04:00
SetNextPlotLimits(0,1,0,1,ImGuiCond_Always);
2020-05-12 05:20:23 -04:00
if (ImPlot::BeginPlot("##Pie1", NULL, NULL, ImVec2(250,250), ImPlotFlags_Legend, 0, 0)) {
ImPlot::PlotPieChart(labels1, data1, 4, 0.5f, 0.5f, 0.4f, normalize, "%.2f");
2020-05-12 05:20:23 -04:00
ImPlot::EndPlot();
2020-05-03 01:24:10 -04:00
}
ImGui::SameLine();
ImPlot::SetColormap(ImPlotColormap_Cool, 5);
2020-05-11 07:13:43 -04:00
SetNextPlotLimits(0,1,0,1,ImGuiCond_Always);
static const char* labels2[] = {"A","B","C","D","E"};
static t_float data2[] = {1,1,2,3,5};
2020-05-12 05:20:23 -04:00
if (ImPlot::BeginPlot("##Pie2", NULL, NULL, ImVec2(250,250), ImPlotFlags_Legend, 0, 0)) {
ImPlot::PlotPieChart(labels2, data2, 5, 0.5f, 0.5f, 0.4f, true, "%.0f", 180);
2020-05-12 05:20:23 -04:00
ImPlot::EndPlot();
2020-05-03 01:24:10 -04:00
}
2020-06-02 13:34:14 -04:00
ImPlot::SetColormap(ImPlotColormap_Default);
2020-06-01 23:14:22 -04:00
}
//-------------------------------------------------------------------------
if (ImGui::CollapsingHeader("Heatmaps")) {
2020-06-02 23:07:27 -04:00
static t_float values1[7][7] = {{0.8f, 2.4f, 2.5f, 3.9f, 0.0f, 4.0f, 0.0f},
{2.4f, 0.0f, 4.0f, 1.0f, 2.7f, 0.0f, 0.0f},
{1.1f, 2.4f, 0.8f, 4.3f, 1.9f, 4.4f, 0.0f},
{0.6f, 0.0f, 0.3f, 0.0f, 3.1f, 0.0f, 0.0f},
{0.7f, 1.7f, 0.6f, 2.6f, 2.2f, 6.2f, 0.0f},
{1.3f, 1.2f, 0.0f, 0.0f, 0.0f, 3.2f, 5.1f},
{0.1f, 2.0f, 0.0f, 1.4f, 0.0f, 1.9f, 6.3f}};
2020-06-02 13:34:14 -04:00
static float scale_min = 0;
static float scale_max = 6.3f;
2020-06-02 23:07:27 -04:00
static t_float values2[100*100];
2020-06-01 23:14:22 -04:00
for (int i = 0; i < 100*100; ++i) {
values2[i] = RandomRange(0,1);
}
static ImPlotColormap map = ImPlotColormap_Viridis;
2020-06-03 15:37:01 -04:00
if (ImGui::Button("Change Colormap",ImVec2(225,0)))
2020-06-01 23:14:22 -04:00
map = (map + 1) % ImPlotColormap_COUNT;
2020-06-02 23:07:27 -04:00
ImPlot::SetColormap(map);
2020-06-02 13:34:14 -04:00
ImGui::SameLine();
ImGui::LabelText("##Colormap Index", "%s", cmap_names[map]);
2020-06-02 23:07:27 -04:00
ImGui::SetNextItemWidth(225);
ImGui::DragFloat("Max",&scale_max,0.01f,0.1f,20);
2020-06-03 15:37:01 -04:00
static ImPlotAxisFlags axes_flags = ImPlotAxisFlags_LockMin | ImPlotAxisFlags_LockMax | ImPlotAxisFlags_TickLabels;
static const char* xlabels[] = {"C1","C2","C3","C4","C5","C6","C7"};
static const char* ylabels[] = {"R1","R2","R3","R4","R5","R6","R7"};
SetNextPlotTicksX(0 + 1.0/14.0, 1 - 1.0/14.0, 7, xlabels);
SetNextPlotTicksY(1- 1.0/14.0, 0 + 1.0/14.0, 7, ylabels);
if (ImPlot::BeginPlot("##Heatmap1",NULL,NULL,ImVec2(225,225),0,axes_flags,axes_flags)) {
2020-06-02 13:34:14 -04:00
ImPlot::PlotHeatmap("heat",values1[0],7,7,scale_min,scale_max);
2020-06-01 23:14:22 -04:00
ImPlot::EndPlot();
}
ImGui::SameLine();
2020-06-02 23:07:27 -04:00
ImPlot::ShowColormapScale(scale_min, scale_max, 225);
ImPlot::SetColormap(ImPlotColormap_Default);
ImGui::SameLine();
static ImVec4 gray[2] = {ImVec4(0,0,0,1), ImVec4(1,1,1,1)};
ImPlot::SetColormap(&gray[0], 2);
ImPlot::SetNextPlotLimits(-1,1,-1,1);
2020-06-02 23:07:27 -04:00
if (ImPlot::BeginPlot("##Heatmap2",NULL,NULL,ImVec2(225,225),ImPlotFlags_ContextMenu,0,0)) {
ImPlot::PlotHeatmap("heat1",values2,100,100,0,1,NULL);
ImPlot::PlotHeatmap("heat2",values2,100,100,0,1,NULL, ImPlotPoint(-1,-1), ImPlotPoint(0,0));
2020-06-01 23:14:22 -04:00
ImPlot::EndPlot();
}
2020-06-02 23:07:27 -04:00
ImPlot::SetColormap(ImPlotColormap_Default);
2020-05-03 01:24:10 -04:00
}
2020-04-30 09:47:14 -04:00
//-------------------------------------------------------------------------
if (ImGui::CollapsingHeader("Realtime Plots")) {
ImGui::BulletText("Move your mouse to change the data!");
ImGui::BulletText("This example assumes 60 FPS. Higher FPS requires larger buffer size.");
2020-04-30 09:47:14 -04:00
static bool paused = false;
static ScrollingData sdata1, sdata2;
static RollingData rdata1, rdata2;
ImVec2 mouse = ImGui::GetMousePos();
2020-05-29 13:39:30 -04:00
static t_float t = 0;
2020-04-30 09:47:14 -04:00
if (!paused) {
t += ImGui::GetIO().DeltaTime;
sdata1.AddPoint(t, mouse.x * 0.0005f);
rdata1.AddPoint(t, mouse.x * 0.0005f);
sdata2.AddPoint(t, mouse.y * 0.0005f);
rdata2.AddPoint(t, mouse.y * 0.0005f);
}
static float history = 10.0f;
ImGui::SliderFloat("History",&history,1,30,"%.1f s");
rdata1.Span = history;
rdata2.Span = history;
ImPlot::SetNextPlotLimitsX(t - history, t, paused ? ImGuiCond_Once : ImGuiCond_Always);
static int rt_axis = ImPlotAxisFlags_Default & ~ImPlotAxisFlags_TickLabels;
if (ImPlot::BeginPlot("##Scrolling", NULL, NULL, ImVec2(-1,150), ImPlotFlags_Default, rt_axis, rt_axis | ImPlotAxisFlags_LockMin)) {
2020-05-29 13:39:30 -04:00
ImPlot::PlotLine("Data 1", &sdata1.Data[0].x, &sdata1.Data[0].y, sdata1.Data.size(), sdata1.Offset, 2 * sizeof(t_float));
2020-06-13 13:59:48 -04:00
ImPlot::PushStyleVar(ImPlotStyleVar_FillAlpha, 0.25f);
ImPlot::PlotShaded("Data 2", &sdata2.Data[0].x, &sdata2.Data[0].y, sdata2.Data.size(), 0, sdata2.Offset, 2 * sizeof(t_float));
ImPlot::PopStyleVar();
2020-05-12 05:20:23 -04:00
ImPlot::EndPlot();
2020-04-30 09:47:14 -04:00
}
ImPlot::SetNextPlotLimitsX(0, history, ImGuiCond_Always);
if (ImPlot::BeginPlot("##Rolling", NULL, NULL, ImVec2(-1,150), ImPlotFlags_Default, rt_axis, rt_axis)) {
2020-05-29 13:39:30 -04:00
ImPlot::PlotLine("Data 1", &rdata1.Data[0].x, &rdata1.Data[0].y, rdata1.Data.size(), 0, 2 * sizeof(t_float));
ImPlot::PlotLine("Data 2", &rdata2.Data[0].x, &rdata2.Data[0].y, rdata2.Data.size(), 0, 2 * sizeof(t_float));
2020-05-12 05:20:23 -04:00
ImPlot::EndPlot();
2020-04-30 09:47:14 -04:00
}
}
//-------------------------------------------------------------------------
if (ImGui::CollapsingHeader("Colormaps, Markers, and Text")) {
2020-06-02 13:34:14 -04:00
static ImPlotColormap map = ImPlotColormap_Default;
2020-06-03 15:37:01 -04:00
if (ImGui::Button("Change Colormap##2"))
2020-06-02 13:34:14 -04:00
map = (map + 1) % ImPlotColormap_COUNT;
ImGui::SameLine();
ImGui::LabelText("##Colormap Index", "%s", cmap_names[map]);
static float mk_size = ImPlot::GetStyle().MarkerSize;
static float mk_weight = ImPlot::GetStyle().MarkerWeight;
ImGui::DragFloat("Marker Size",&mk_size,0.1f,2.0f,10.0f,"%.2f px");
ImGui::DragFloat("Marker Weight", &mk_weight,0.05f,0.5f,3.0f,"%.2f px");
2020-06-03 15:37:01 -04:00
ImGui::PushID(map); // NB: This is merely a workaround so that the demo can cycle color maps. You wouldn't need to do this in your own code!
2020-05-12 05:20:23 -04:00
ImPlot::SetNextPlotLimits(0, 10, 0, 12);
2020-05-16 10:11:29 -04:00
if (ImPlot::BeginPlot("##MarkerStyles", NULL, NULL, ImVec2(-1,0), 0, 0, 0)) {
ImPlot::PushStyleVar(ImPlotStyleVar_MarkerSize, mk_size);
ImPlot::PushStyleVar(ImPlotStyleVar_MarkerWeight, mk_weight);
2020-06-02 13:34:14 -04:00
ImPlot::SetColormap(map);
2020-05-29 13:39:30 -04:00
t_float xs[2] = {1,4};
t_float ys[2] = {10,11};
2020-04-30 09:47:14 -04:00
// filled
ImPlot::PushStyleVar(ImPlotStyleVar_Marker, ImPlotMarker_Circle);
2020-05-29 13:39:30 -04:00
ImPlot::PlotLine("Circle##Fill", xs, ys, 2);
ImPlot::PushStyleVar(ImPlotStyleVar_Marker, ImPlotMarker_Square); ys[0]--; ys[1]--;
2020-05-29 13:39:30 -04:00
ImPlot::PlotLine("Square##Fill", xs, ys, 2);
ImPlot::PushStyleVar(ImPlotStyleVar_Marker, ImPlotMarker_Diamond); ys[0]--; ys[1]--;
2020-05-29 13:39:30 -04:00
ImPlot::PlotLine("Diamond##Fill", xs, ys, 2);
ImPlot::PushStyleVar(ImPlotStyleVar_Marker, ImPlotMarker_Up); ys[0]--; ys[1]--;
2020-05-29 13:39:30 -04:00
ImPlot::PlotLine("Up##Fill", xs, ys, 2);
ImPlot::PushStyleVar(ImPlotStyleVar_Marker, ImPlotMarker_Down); ys[0]--; ys[1]--;
2020-05-29 13:39:30 -04:00
ImPlot::PlotLine("Down##Fill", xs, ys, 2);
ImPlot::PushStyleVar(ImPlotStyleVar_Marker, ImPlotMarker_Left); ys[0]--; ys[1]--;
2020-05-29 13:39:30 -04:00
ImPlot::PlotLine("Left##Fill", xs, ys, 2);
ImPlot::PushStyleVar(ImPlotStyleVar_Marker, ImPlotMarker_Right); ys[0]--; ys[1]--;
2020-05-29 13:39:30 -04:00
ImPlot::PlotLine("Right##Fill", xs, ys, 2);
ImPlot::PushStyleVar(ImPlotStyleVar_Marker, ImPlotMarker_Cross); ys[0]--; ys[1]--;
2020-05-29 13:39:30 -04:00
ImPlot::PlotLine("Cross##Fill", xs, ys, 2);
ImPlot::PushStyleVar(ImPlotStyleVar_Marker, ImPlotMarker_Plus); ys[0]--; ys[1]--;
2020-05-29 13:39:30 -04:00
ImPlot::PlotLine("Plus##Fill", xs, ys, 2);
ImPlot::PushStyleVar(ImPlotStyleVar_Marker, ImPlotMarker_Asterisk); ys[0]--; ys[1]--;
2020-05-29 13:39:30 -04:00
ImPlot::PlotLine("Asterisk##Fill", xs, ys, 2);
2020-05-12 05:20:23 -04:00
ImPlot::PopStyleVar(10);
2020-04-30 09:47:14 -04:00
xs[0] = 6; xs[1] = 9;
ys[0] = 10; ys[1] = 11;
2020-05-12 05:20:23 -04:00
ImPlot::PushStyleColor(ImPlotCol_MarkerFill, ImVec4(0,0,0,0));
ImPlot::PushStyleVar(ImPlotStyleVar_Marker, ImPlotMarker_Circle);
2020-05-29 13:39:30 -04:00
ImPlot::PlotLine("Circle", xs, ys, 2);
ImPlot::PushStyleVar(ImPlotStyleVar_Marker, ImPlotMarker_Square); ys[0]--; ys[1]--;
2020-05-29 13:39:30 -04:00
ImPlot::PlotLine("Square", xs, ys, 2);
ImPlot::PushStyleVar(ImPlotStyleVar_Marker, ImPlotMarker_Diamond); ys[0]--; ys[1]--;
2020-05-29 13:39:30 -04:00
ImPlot::PlotLine("Diamond", xs, ys, 2);
ImPlot::PushStyleVar(ImPlotStyleVar_Marker, ImPlotMarker_Up); ys[0]--; ys[1]--;
2020-05-29 13:39:30 -04:00
ImPlot::PlotLine("Up", xs, ys, 2);
ImPlot::PushStyleVar(ImPlotStyleVar_Marker, ImPlotMarker_Down); ys[0]--; ys[1]--;
2020-05-29 13:39:30 -04:00
ImPlot::PlotLine("Down", xs, ys, 2);
ImPlot::PushStyleVar(ImPlotStyleVar_Marker, ImPlotMarker_Left); ys[0]--; ys[1]--;
2020-05-29 13:39:30 -04:00
ImPlot::PlotLine("Left", xs, ys, 2);
ImPlot::PushStyleVar(ImPlotStyleVar_Marker, ImPlotMarker_Right); ys[0]--; ys[1]--;
2020-05-29 13:39:30 -04:00
ImPlot::PlotLine("Right", xs, ys, 2);
ImPlot::PushStyleVar(ImPlotStyleVar_Marker, ImPlotMarker_Cross); ys[0]--; ys[1]--;
2020-05-29 13:39:30 -04:00
ImPlot::PlotLine("Cross", xs, ys, 2);
ImPlot::PushStyleVar(ImPlotStyleVar_Marker, ImPlotMarker_Plus); ys[0]--; ys[1]--;
2020-05-29 13:39:30 -04:00
ImPlot::PlotLine("Plus", xs, ys, 2);
ImPlot::PushStyleVar(ImPlotStyleVar_Marker, ImPlotMarker_Asterisk); ys[0]--; ys[1]--;
2020-05-29 13:39:30 -04:00
ImPlot::PlotLine("Asterisk", xs, ys, 2);
2020-05-12 05:20:23 -04:00
ImPlot::PopStyleColor();
ImPlot::PopStyleVar(10);
2020-04-30 09:47:14 -04:00
xs[0] = 5; xs[1] = 5;
ys[0] = 1; ys[1] = 11;
2020-05-12 05:20:23 -04:00
ImPlot::PushStyleVar(ImPlotStyleVar_LineWeight, 2);
ImPlot::PushStyleVar(ImPlotStyleVar_MarkerSize, 8);
ImPlot::PushStyleVar(ImPlotStyleVar_MarkerWeight, 2);
2020-05-29 13:39:30 -04:00
ImPlot::PushStyleVar(ImPlotStyleVar_Marker, ImPlotMarker_Circle | ImPlotMarker_Cross);
2020-05-12 05:20:23 -04:00
ImPlot::PushStyleColor(ImPlotCol_MarkerOutline, ImVec4(0,0,0,1));
ImPlot::PushStyleColor(ImPlotCol_MarkerFill, ImVec4(1,1,1,1));
ImPlot::PushStyleColor(ImPlotCol_Line, ImVec4(0,0,0,1));
ImPlot::PlotLine("Circle|Cross", xs, ys, 2);
ImPlot::PopStyleVar(6);
2020-05-12 05:20:23 -04:00
ImPlot::PopStyleColor(3);
2020-04-30 09:47:14 -04:00
ImPlot::PlotText("Filled Markers", 2.5f, 6.0f);
ImPlot::PlotText("Open Markers", 7.5f, 6.0f);
2020-08-16 01:24:09 -04:00
ImGui::PushStyleColor(ImGuiCol_Text, ImVec4(0,1,0,1));
ImPlot::PlotText("Fancy Markers", 5.0f, 6.0f, true);
2020-08-16 01:24:09 -04:00
ImGui::PopStyleColor();
2020-04-30 09:47:14 -04:00
2020-06-02 13:34:14 -04:00
ImPlot::SetColormap(ImPlotColormap_Default);
2020-05-12 05:20:23 -04:00
ImPlot::EndPlot();
2020-04-30 09:47:14 -04:00
}
2020-06-02 13:34:14 -04:00
ImGui::PopID();
2020-04-30 09:47:14 -04:00
}
//-------------------------------------------------------------------------
if (ImGui::CollapsingHeader("Log Scale")) {
ImGui::BulletText("Open the plot context menu (double right click) to change scales.");
2020-05-29 13:39:30 -04:00
static t_float xs[1001], ys1[1001], ys2[1001], ys3[1001];
2020-04-30 09:47:14 -04:00
for (int i = 0; i < 1001; ++i) {
2020-05-29 13:39:30 -04:00
xs[i] = i*0.1f;
ys1[i] = Sin(xs[i]) + 1;
ys2[i] = Log(xs[i]);
ys3[i] = Pow(10.0f, xs[i]);
2020-04-30 09:47:14 -04:00
}
2020-05-29 13:39:30 -04:00
ImPlot::SetNextPlotLimits(0.1, 100, 0, 10);
2020-05-16 10:11:29 -04:00
if (ImPlot::BeginPlot("Log Plot", NULL, NULL, ImVec2(-1,0), ImPlotFlags_Default, ImPlotAxisFlags_Default | ImPlotAxisFlags_LogScale )) {
ImPlot::PlotLine("f(x) = x", xs, xs, 1001);
ImPlot::PlotLine("f(x) = sin(x)+1", xs, ys1, 1001);
ImPlot::PlotLine("f(x) = log(x)", xs, ys2, 1001);
ImPlot::PlotLine("f(x) = 10^x", xs, ys3, 21);
2020-05-12 05:20:23 -04:00
ImPlot::EndPlot();
2020-04-30 09:47:14 -04:00
}
}
//-------------------------------------------------------------------------
2020-05-11 07:13:43 -04:00
if (ImGui::CollapsingHeader("Multiple Y-Axes")) {
static ImVec4 txt_col = ImGui::GetStyle().Colors[ImGuiCol_Text];
txt_col.w = 0.25f;
static ImVec4 y1_col = txt_col;
static ImVec4 y2_col = txt_col;
static ImVec4 y3_col = txt_col;
2020-05-29 13:39:30 -04:00
static t_float xs[1001], xs2[1001], ys1[1001], ys2[1001], ys3[1001];
2020-05-11 07:13:43 -04:00
static bool y2_axis = true;
static bool y3_axis = false;
ImGui::Checkbox("Y-Axis 2", &y2_axis);
ImGui::SameLine();
ImGui::Checkbox("Y-Axis 3", &y3_axis);
ImGui::SameLine();
ImGui::ColorEdit4("##Col1", &y1_col.x, ImGuiColorEditFlags_NoInputs);
ImGui::SameLine();
ImGui::ColorEdit4("##Col2", &y2_col.x, ImGuiColorEditFlags_NoInputs);
ImGui::SameLine();
ImGui::ColorEdit4("##Col3", &y3_col.x, ImGuiColorEditFlags_NoInputs);
for (int i = 0; i < 1001; ++i) {
2020-05-29 13:39:30 -04:00
xs[i] = (i*0.1f);
ys1[i] = Sin(xs[i]) * 3 + 1;
ys2[i] = Cos(xs[i]) * 0.2f + 0.5f;
ys3[i] = Sin(xs[i]+0.5f) * 100 + 200;
2020-05-11 07:13:43 -04:00
xs2[i] = xs[i] + 10.0f;
}
2020-05-29 13:39:30 -04:00
ImPlot::SetNextPlotLimits(0.1, 100, 0, 10);
2020-05-12 05:20:23 -04:00
ImPlot::SetNextPlotLimitsY(0, 1, ImGuiCond_Once, 1);
ImPlot::SetNextPlotLimitsY(0, 300, ImGuiCond_Once, 2);
ImPlot::PushStyleColor(ImPlotCol_YAxis, y1_col);
ImPlot::PushStyleColor(ImPlotCol_YAxis2, y2_col);
ImPlot::PushStyleColor(ImPlotCol_YAxis3, y3_col);
2020-05-11 07:13:43 -04:00
2020-05-16 10:11:29 -04:00
if (ImPlot::BeginPlot("Multi-Axis Plot", NULL, NULL, ImVec2(-1,0),
2020-05-11 07:13:43 -04:00
ImPlotFlags_Default |
(y2_axis ? ImPlotFlags_YAxis2 : 0) |
(y3_axis ? ImPlotFlags_YAxis3 : 0))) {
ImPlot::PlotLine("f(x) = x", xs, xs, 1001);
ImPlot::PlotLine("f(x) = sin(x)*3+1", xs, ys1, 1001);
2020-05-11 07:13:43 -04:00
if (y2_axis) {
2020-05-12 05:20:23 -04:00
ImPlot::SetPlotYAxis(1);
ImPlot::PlotLine("f(x) = cos(x)*.2+.5 (Y2)", xs, ys2, 1001);
2020-05-11 07:13:43 -04:00
}
if (y3_axis) {
2020-05-12 05:20:23 -04:00
ImPlot::SetPlotYAxis(2);
ImPlot::PlotLine("f(x) = sin(x+.5)*100+200 (Y3)", xs2, ys3, 1001);
2020-05-11 07:13:43 -04:00
}
2020-05-12 05:20:23 -04:00
ImPlot::EndPlot();
2020-05-11 07:13:43 -04:00
}
2020-05-12 05:20:23 -04:00
ImPlot::PopStyleColor(3);
2020-05-11 07:13:43 -04:00
}
//-------------------------------------------------------------------------
2020-04-30 09:47:14 -04:00
if (ImGui::CollapsingHeader("Querying")) {
ImGui::BulletText("Ctrl + click in the plot area to draw points.");
2020-05-11 07:13:43 -04:00
ImGui::BulletText("Middle click (or Ctrl + right click) and drag to create a query rect.");
ImGui::Indent();
ImGui::BulletText("Hold Alt to expand query horizontally.");
ImGui::BulletText("Hold Shift to expand query vertically.");
ImGui::BulletText("The query rect can be dragged after it's created.");
ImGui::Unindent();
2020-05-29 13:39:30 -04:00
static ImVector<t_float2> data;
2020-05-11 07:13:43 -04:00
ImPlotLimits range, query;
2020-05-16 10:11:29 -04:00
if (ImPlot::BeginPlot("##Drawing", NULL, NULL, ImVec2(-1,0), ImPlotFlags_Default | ImPlotFlags_Query, ImPlotAxisFlags_GridLines, ImPlotAxisFlags_GridLines)) {
2020-05-16 22:09:36 -04:00
if (ImPlot::IsPlotHovered() && ImGui::IsMouseClicked(0) && ImGui::GetIO().KeyCtrl) {
ImPlotPoint pt = ImPlot::GetPlotMousePos();
2020-05-29 13:39:30 -04:00
data.push_back(t_float2((t_float)pt.x, (t_float)pt.y));
2020-05-16 22:09:36 -04:00
}
ImPlot::PushStyleVar(ImPlotStyleVar_Marker, ImPlotMarker_Diamond);
2020-04-30 09:47:14 -04:00
if (data.size() > 0)
2020-05-29 13:39:30 -04:00
ImPlot::PlotScatter("Points", &data[0].x, &data[0].y, data.size(), 0, 2 * sizeof(t_float));
2020-05-12 05:20:23 -04:00
if (ImPlot::IsPlotQueried() && data.size() > 0) {
ImPlotLimits range2 = ImPlot::GetPlotQuery();
2020-04-30 09:47:14 -04:00
int cnt = 0;
2020-05-29 13:39:30 -04:00
t_float2 avg;
2020-04-30 09:47:14 -04:00
for (int i = 0; i < data.size(); ++i) {
2020-05-29 13:39:30 -04:00
if (range2.Contains(data[i].x, data[i].y)) {
2020-04-30 09:47:14 -04:00
avg.x += data[i].x;
avg.y += data[i].y;
cnt++;
}
2020-04-30 09:47:14 -04:00
}
if (cnt > 0) {
avg.x = avg.x / cnt;
avg.y = avg.y / cnt;
ImPlot::PlotScatter("Average", &avg.x, &avg.y, 1);
2020-04-30 09:47:14 -04:00
}
}
ImPlot::PopStyleVar();
2020-05-12 05:20:23 -04:00
range = ImPlot::GetPlotLimits();
query = ImPlot::GetPlotQuery();
ImPlot::EndPlot();
2020-04-30 09:47:14 -04:00
}
2020-05-11 07:13:43 -04:00
ImGui::Text("The current plot limits are: [%g,%g,%g,%g]", range.X.Min, range.X.Max, range.Y.Min, range.Y.Max);
ImGui::Text("The current query limits are: [%g,%g,%g,%g]", query.X.Min, query.X.Max, query.Y.Min, query.Y.Max);
2020-04-30 09:47:14 -04:00
}
//-------------------------------------------------------------------------
if (ImGui::CollapsingHeader("Views")) {
// mimic's soulthread's imgui_plot demo
2020-05-29 13:39:30 -04:00
static t_float x_data[512];
static t_float y_data1[512];
static t_float y_data2[512];
static t_float y_data3[512];
static t_float sampling_freq = 44100;
static t_float freq = 500;
2020-04-30 09:47:14 -04:00
for (size_t i = 0; i < 512; ++i) {
2020-05-29 13:39:30 -04:00
const t_float t = i / sampling_freq;
2020-04-30 09:47:14 -04:00
x_data[i] = t;
2020-05-29 13:39:30 -04:00
const t_float arg = 2 * 3.14f * freq * t;
y_data1[i] = Sin(arg);
y_data2[i] = y_data1[i] * -0.6f + Sin(2 * arg) * 0.4f;
y_data3[i] = y_data2[i] * -0.6f + Sin(3 * arg) * 0.4f;
2020-04-30 09:47:14 -04:00
}
2020-05-11 07:13:43 -04:00
ImGui::BulletText("Query the first plot to render a subview in the second plot (see above for controls).");
2020-05-29 13:39:30 -04:00
ImPlot::SetNextPlotLimits(0,0.01,-1,1);
ImPlotAxisFlags flgs = ImPlotAxisFlags_Default & ~ImPlotAxisFlags_TickLabels;
2020-05-11 07:13:43 -04:00
ImPlotLimits query;
2020-05-12 05:20:23 -04:00
if (ImPlot::BeginPlot("##View1",NULL,NULL,ImVec2(-1,150), ImPlotFlags_Default | ImPlotFlags_Query, flgs, flgs)) {
ImPlot::PlotLine("Signal 1", x_data, y_data1, 512);
ImPlot::PlotLine("Signal 2", x_data, y_data2, 512);
ImPlot::PlotLine("Signal 3", x_data, y_data3, 512);
2020-05-12 05:20:23 -04:00
query = ImPlot::GetPlotQuery();
ImPlot::EndPlot();
}
ImPlot::SetNextPlotLimits(query.X.Min, query.X.Max, query.Y.Min, query.Y.Max, ImGuiCond_Always);
if (ImPlot::BeginPlot("##View2",NULL,NULL,ImVec2(-1,150), 0, 0, 0)) {
ImPlot::PlotLine("Signal 1", x_data, y_data1, 512);
ImPlot::PlotLine("Signal 2", x_data, y_data2, 512);
ImPlot::PlotLine("Signal 3", x_data, y_data3, 512);
2020-05-12 05:20:23 -04:00
ImPlot::EndPlot();
2020-04-30 09:47:14 -04:00
}
}
//-------------------------------------------------------------------------
if (ImGui::CollapsingHeader("Drag and Drop")) {
const int K_CHANNELS = 9;
2020-05-11 07:13:43 -04:00
srand((int)(10000000 * ImGui::GetTime()));
2020-04-30 09:47:14 -04:00
static bool paused = false;
static bool init = true;
static ScrollingData data[K_CHANNELS];
static bool show[K_CHANNELS];
static int yAxis[K_CHANNELS];
2020-04-30 09:47:14 -04:00
if (init) {
for (int i = 0; i < K_CHANNELS; ++i) {
2020-04-30 09:47:14 -04:00
show[i] = false;
yAxis[i] = 0;
2020-04-30 09:47:14 -04:00
}
init = false;
}
2020-07-26 22:39:17 -04:00
ImGui::BulletText("Drag data items from the left column onto the plot or onto a specific y-axis.");
2020-04-30 09:47:14 -04:00
ImGui::BeginGroup();
if (ImGui::Button("Clear", ImVec2(100, 0))) {
for (int i = 0; i < K_CHANNELS; ++i) {
2020-04-30 09:47:14 -04:00
show[i] = false;
data[i].Data.shrink(0);
data[i].Offset = 0;
}
}
if (ImGui::Button(paused ? "Resume" : "Pause", ImVec2(100,0)))
2020-04-30 09:47:14 -04:00
paused = !paused;
for (int i = 0; i < K_CHANNELS; ++i) {
char label[16];
sprintf(label, show[i] ? "data_%d (Y%d)" : "data_%d", i, yAxis[i]+1);
ImGui::Selectable(label, false, 0, ImVec2(100, 0));
2020-04-30 09:47:14 -04:00
if (ImGui::BeginDragDropSource(ImGuiDragDropFlags_None)) {
ImGui::SetDragDropPayload("DND_PLOT", &i, sizeof(int));
ImGui::TextUnformatted(label);
ImGui::EndDragDropSource();
}
}
ImGui::EndGroup();
ImGui::SameLine();
srand((unsigned int)ImGui::GetTime()*10000000);
2020-05-29 13:39:30 -04:00
static t_float t = 0;
2020-04-30 09:47:14 -04:00
if (!paused) {
t += ImGui::GetIO().DeltaTime;
for (int i = 0; i < K_CHANNELS; ++i) {
2020-04-30 09:47:14 -04:00
if (show[i])
data[i].AddPoint(t, (i+1)*0.1f + RandomRange(-0.01f,0.01f));
2020-04-30 09:47:14 -04:00
}
}
2020-05-29 13:39:30 -04:00
ImPlot::SetNextPlotLimitsX((double)t - 10, t, paused ? ImGuiCond_Once : ImGuiCond_Always);
if (ImPlot::BeginPlot("##DND", NULL, NULL, ImVec2(-1,0), ImPlotFlags_Legend | ImPlotFlags_Highlight | ImPlotFlags_BoxSelect | ImPlotFlags_ContextMenu | ImPlotFlags_NoChild | ImPlotFlags_YAxis2 | ImPlotFlags_YAxis3)) {
for (int i = 0; i < K_CHANNELS; ++i) {
2020-05-22 08:42:07 -04:00
if (show[i] && data[i].Data.size() > 0) {
char label[K_CHANNELS];
2020-04-30 09:47:14 -04:00
sprintf(label, "data_%d", i);
ImPlot::SetPlotYAxis(yAxis[i]);
2020-05-29 13:39:30 -04:00
ImPlot::PlotLine(label, &data[i].Data[0].x, &data[i].Data[0].y, data[i].Data.size(), data[i].Offset, 2 * sizeof(t_float));
2020-04-30 09:47:14 -04:00
}
}
if (ImGui::BeginDragDropTarget()) {
if (const ImGuiPayload* payload = ImGui::AcceptDragDropPayload("DND_PLOT")) {
int i = *(int*)payload->Data;
show[i] = true;
for (int y = 0; y < 3; y++) {
if (ImPlot::IsPlotYAxisHovered(y))
yAxis[i] = y;
}
}
ImGui::EndDragDropTarget();
}
2020-05-12 05:20:23 -04:00
ImPlot::EndPlot();
2020-04-30 09:47:14 -04:00
}
}
2020-05-12 05:20:23 -04:00
//-------------------------------------------------------------------------
if (ImGui::CollapsingHeader("Digital and Analog Signals")) {
2020-04-30 09:47:14 -04:00
static bool paused = false;
#define K_PLOT_DIGITAL_CH_COUNT 4
#define K_PLOT_ANALOG_CH_COUNT 4
2020-04-30 09:47:14 -04:00
static ScrollingData dataDigital[K_PLOT_DIGITAL_CH_COUNT];
static ScrollingData dataAnalog[K_PLOT_ANALOG_CH_COUNT];
static bool showDigital[K_PLOT_DIGITAL_CH_COUNT];
static bool showAnalog[K_PLOT_ANALOG_CH_COUNT];
ImGui::BulletText("You can plot digital and analog signals on the same plot.");
ImGui::BulletText("Digital signals do not respond to Y drag and zoom, so that");
ImGui::Indent();
ImGui::Text("you can drag analog signals over the rising/falling digital edge.");
ImGui::Unindent();
2020-04-30 09:47:14 -04:00
ImGui::BeginGroup();
if (ImGui::Button("Clear", ImVec2(100, 0))) {
2020-04-30 09:47:14 -04:00
for (int i = 0; i < K_PLOT_DIGITAL_CH_COUNT; ++i)
showDigital[i] = false;
for (int i = 0; i < K_PLOT_ANALOG_CH_COUNT; ++i)
showAnalog[i] = false;
}
if (ImGui::Button(paused ? "Resume" : "Pause", ImVec2(100,0)))
2020-04-30 09:47:14 -04:00
paused = !paused;
ImGui::SetNextItemWidth(100);
static float bitHeight = 8;
ImGui::DragFloat("##Bit Height", &bitHeight, 1, 5, 25, "%.0f px");
ImGui::SetNextItemWidth(100);
static float bitGap = 4;
ImGui::DragFloat("##Bit Gap", &bitGap, 1, 2, 20, "%.0f px");
2020-04-30 09:47:14 -04:00
for (int i = 0; i < K_PLOT_DIGITAL_CH_COUNT; ++i) {
char label[32];
sprintf(label, "digital_%d", i);
2020-04-30 09:47:14 -04:00
ImGui::Checkbox(label, &showDigital[i]);
if (ImGui::BeginDragDropSource(ImGuiDragDropFlags_None)) {
ImGui::SetDragDropPayload("DND_DIGITAL_PLOT", &i, sizeof(int));
ImGui::TextUnformatted(label);
ImGui::EndDragDropSource();
}
}
for (int i = 0; i < K_PLOT_ANALOG_CH_COUNT; ++i) {
char label[32];
sprintf(label, "analog_%d", i);
2020-04-30 09:47:14 -04:00
ImGui::Checkbox(label, &showAnalog[i]);
if (ImGui::BeginDragDropSource(ImGuiDragDropFlags_None)) {
ImGui::SetDragDropPayload("DND_ANALOG_PLOT", &i, sizeof(int));
ImGui::TextUnformatted(label);
ImGui::EndDragDropSource();
}
}
ImGui::EndGroup();
ImGui::SameLine();
2020-05-29 13:39:30 -04:00
static t_float t = 0;
if (!paused) {
2020-04-30 09:47:14 -04:00
t += ImGui::GetIO().DeltaTime;
//digital signal values
int i = 0;
if (showDigital[i])
2020-05-29 13:39:30 -04:00
dataDigital[i].AddPoint(t, Sin(2*t) > 0.45);
2020-04-30 09:47:14 -04:00
i++;
if (showDigital[i])
2020-05-29 13:39:30 -04:00
dataDigital[i].AddPoint(t, Sin(2*t) < 0.45);
2020-04-30 09:47:14 -04:00
i++;
if (showDigital[i])
2020-05-29 13:39:30 -04:00
dataDigital[i].AddPoint(t, Fmod(t,5.0f));
2020-04-30 09:47:14 -04:00
i++;
if (showDigital[i])
2020-05-29 13:39:30 -04:00
dataDigital[i].AddPoint(t, Sin(2*t) < 0.17);
2020-04-30 09:47:14 -04:00
//Analog signal values
i = 0;
if (showAnalog[i])
2020-05-29 13:39:30 -04:00
dataAnalog[i].AddPoint(t, Sin(2*t));
2020-04-30 09:47:14 -04:00
i++;
if (showAnalog[i])
2020-05-29 13:39:30 -04:00
dataAnalog[i].AddPoint(t, Cos(2*t));
2020-04-30 09:47:14 -04:00
i++;
if (showAnalog[i])
2020-05-29 13:39:30 -04:00
dataAnalog[i].AddPoint(t, Sin(2*t) * Cos(2*t));
2020-04-30 09:47:14 -04:00
i++;
if (showAnalog[i])
2020-05-29 13:39:30 -04:00
dataAnalog[i].AddPoint(t, Sin(2*t) - Cos(2*t));
2020-04-30 09:47:14 -04:00
}
2020-05-12 05:20:23 -04:00
ImPlot::SetNextPlotLimitsY(-1, 1);
2020-05-29 13:39:30 -04:00
ImPlot::SetNextPlotLimitsX(t - 10.0, t, paused ? ImGuiCond_Once : ImGuiCond_Always);
2020-05-16 10:11:29 -04:00
if (ImPlot::BeginPlot("##Digital")) {
2020-04-30 09:47:14 -04:00
for (int i = 0; i < K_PLOT_DIGITAL_CH_COUNT; ++i) {
2020-05-22 08:42:07 -04:00
if (showDigital[i] && dataDigital[i].Data.size() > 0) {
2020-04-30 09:47:14 -04:00
char label[32];
sprintf(label, "digital_%d", i);
2020-05-12 05:20:23 -04:00
ImPlot::PushStyleVar(ImPlotStyleVar_DigitalBitHeight, bitHeight);
ImPlot::PushStyleVar(ImPlotStyleVar_DigitalBitGap, bitGap);
2020-05-29 13:39:30 -04:00
ImPlot::PlotDigital(label, &dataDigital[i].Data[0].x, &dataDigital[i].Data[0].y, dataDigital[i].Data.size(), dataDigital[i].Offset, 2 * sizeof(t_float));
2020-05-12 05:20:23 -04:00
ImPlot::PopStyleVar(2);
2020-04-30 09:47:14 -04:00
}
}
for (int i = 0; i < K_PLOT_ANALOG_CH_COUNT; ++i) {
if (showAnalog[i]) {
char label[32];
sprintf(label, "analog_%d", i);
2020-04-30 09:47:14 -04:00
if (dataAnalog[i].Data.size() > 0)
2020-05-29 13:39:30 -04:00
ImPlot::PlotLine(label, &dataAnalog[i].Data[0].x, &dataAnalog[i].Data[0].y, dataAnalog[i].Data.size(), dataAnalog[i].Offset, 2 * sizeof(t_float));
2020-04-30 09:47:14 -04:00
}
}
2020-05-12 05:20:23 -04:00
ImPlot::EndPlot();
2020-04-30 09:47:14 -04:00
}
if (ImGui::BeginDragDropTarget()) {
const ImGuiPayload* payload = ImGui::AcceptDragDropPayload("DND_DIGITAL_PLOT");
if (payload) {
2020-04-30 09:47:14 -04:00
int i = *(int*)payload->Data;
showDigital[i] = true;
}
else
{
payload = ImGui::AcceptDragDropPayload("DND_ANALOG_PLOT");
if (payload) {
int i = *(int*)payload->Data;
showAnalog[i] = true;
}
2020-04-30 09:47:14 -04:00
}
ImGui::EndDragDropTarget();
}
}
//-------------------------------------------------------------------------
if (ImGui::CollapsingHeader("Offset and Stride")) {
static const int k_circles = 11;
static const int k_points_per = 50;
static const int k_size = 2 * k_points_per * k_circles;
static t_float interleaved_data[k_size];
for (int p = 0; p < k_points_per; ++p) {
for (int c = 0; c < k_circles; ++c) {
t_float r = (t_float)c / (k_circles - 1) * 0.2f + 0.2f;
interleaved_data[p*2*k_circles + 2*c + 0] = 0.5f + r * Cos((t_float)p/k_points_per * 6.28f);
interleaved_data[p*2*k_circles + 2*c + 1] = 0.5f + r * Sin((t_float)p/k_points_per * 6.28f);
}
}
static int offset = 0;
ImGui::BulletText("Offsetting is useful for realtime plots (see above) and circular buffers.");
ImGui::BulletText("Striding is useful for interleaved data (e.g. audio) or plotting structs.");
ImGui::BulletText("Here, all circle data is stored in a single interleaved buffer:");
ImGui::BulletText("[c0.x0 c0.y0 ... cn.x0 cn.y0 c0.x1 c0.y1 ... cn.x1 cn.y1 ... cn.xm cn.ym]");
ImGui::BulletText("The offset value indicates which circle point index is considered the first.");
ImGui::BulletText("Offsets can be negative and/or larger than the actual data count.");
ImGui::SliderInt("Offset", &offset, -2*k_points_per, 2*k_points_per);
if (ImPlot::BeginPlot("##strideoffset")) {
ImPlot::SetColormap(ImPlotColormap_Jet);
char buff[16];
for (int c = 0; c < k_circles; ++c) {
sprintf(buff, "Circle %d", c);
ImPlot::PlotLine(buff, &interleaved_data[c*2 + 0], &interleaved_data[c*2 + 1], k_points_per, offset, 2*k_circles*sizeof(t_float));
}
ImPlot::EndPlot();
ImPlot::SetColormap(ImPlotColormap_Default);
}
// offset++; uncomment for animation!
}
//-------------------------------------------------------------------------
2020-06-03 15:37:01 -04:00
if (ImGui::CollapsingHeader("Custom Ticks")) {
static bool custom_ticks = true;
static bool custom_labels = true;
ImGui::Checkbox("Show Custom Ticks", &custom_ticks);
if (custom_ticks) {
ImGui::SameLine();
ImGui::Checkbox("Show Custom Labels", &custom_labels);
}
double pi = 3.14;
const char* pi_str[] = {"PI"};
static double yticks[] = {1,3,7,9};
static const char* ylabels[] = {"One","Three","Seven","Nine"};
static double yticks_aux[] = {0.2,0.4,0.6};
static const char* ylabels_aux[] = {"A","B","C","D","E","F"};
if (custom_ticks) {
ImPlot::SetNextPlotTicksX(&pi,1,custom_labels ? pi_str : NULL, true);
ImPlot::SetNextPlotTicksY(yticks, 4, custom_labels ? ylabels : NULL);
ImPlot::SetNextPlotTicksY(yticks_aux, 3, custom_labels ? ylabels_aux : NULL, false, 1);
ImPlot::SetNextPlotTicksY(0, 1, 6, custom_labels ? ylabels_aux : NULL, false, 2);
}
ImPlot::SetNextPlotLimits(2.5,5,0,10);
if (ImPlot::BeginPlot("Custom Ticks", NULL, NULL, ImVec2(-1,0), ImPlotFlags_Default | ImPlotFlags_YAxis2 | ImPlotFlags_YAxis3)) {
ImPlot::EndPlot();
}
}
//-------------------------------------------------------------------------
2020-04-30 09:47:14 -04:00
if (ImGui::CollapsingHeader("Custom Styles")) {
2020-06-01 23:14:22 -04:00
static ImVec4 my_map[3] = {
ImVec4(0.000f, 0.980f, 0.604f, 1.0f),
ImVec4(0.996f, 0.278f, 0.380f, 1.0f),
ImVec4(0.1176470593f, 0.5647059083f, 1.0f, 1.0f),
2020-04-30 09:47:14 -04:00
};
2020-06-01 23:14:22 -04:00
ImPlot::SetColormap(my_map, 3);
2020-05-12 05:20:23 -04:00
ImPlot::PushStyleColor(ImPlotCol_FrameBg, IM_COL32(32,51,77,255));
ImPlot::PushStyleColor(ImPlotCol_PlotBg, ImVec4(0,0,0,0));
ImPlot::PushStyleColor(ImPlotCol_PlotBorder, ImVec4(0,0,0,0));
2020-05-12 05:20:23 -04:00
ImPlot::PushStyleColor(ImPlotCol_XAxis, IM_COL32(192, 192, 192, 192));
ImPlot::PushStyleColor(ImPlotCol_YAxis, IM_COL32(192, 192, 192, 192));
ImPlot::PushStyleVar(ImPlotStyleVar_LineWeight, 2);
ImPlot::SetNextPlotLimits(-0.5f, 9.5f, -0.5f, 9.5f);
2020-05-16 10:11:29 -04:00
if (ImPlot::BeginPlot("##Custom", NULL, NULL, ImVec2(-1,0), ImPlotFlags_Default & ~ImPlotFlags_Legend, 0)) {
2020-05-29 13:39:30 -04:00
t_float lin[10] = {8,8,9,7,8,8,8,9,7,8};
t_float bar[10] = {1,2,5,3,4,1,2,5,3,4};
t_float dot[10] = {7,6,6,7,8,5,6,5,8,7};
2020-05-16 10:14:48 -04:00
ImPlot::PlotBars("Bar", bar, 10, 0.5f);
ImPlot::PlotLine("Line", lin, 10);
2020-05-12 05:20:23 -04:00
ImPlot::PushStyleVar(ImPlotStyleVar_LineWeight, 0);
ImPlot::PushStyleVar(ImPlotStyleVar_Marker, ImPlotMarker_Square);
ImPlot::PlotLine("Dot", dot, 10);
2020-05-12 05:20:23 -04:00
ImPlot::PopStyleVar(2);
ImPlot::EndPlot();
}
ImPlot::PopStyleColor(5);
ImPlot::PopStyleVar();
2020-06-02 13:34:14 -04:00
ImPlot::SetColormap(ImPlotColormap_Default);
2020-04-30 09:47:14 -04:00
}
2020-05-12 05:20:23 -04:00
//-------------------------------------------------------------------------
2020-04-30 09:47:14 -04:00
if (ImGui::CollapsingHeader("Custom Rendering")) {
2020-05-16 10:11:29 -04:00
if (ImPlot::BeginPlot("##CustomRend")) {
2020-05-16 22:09:36 -04:00
ImVec2 cntr = ImPlot::PlotToPixels(ImPlotPoint(0.5f, 0.5f));
ImVec2 rmin = ImPlot::PlotToPixels(ImPlotPoint(0.25f, 0.75f));
ImVec2 rmax = ImPlot::PlotToPixels(ImPlotPoint(0.75f, 0.25f));
2020-05-12 05:20:23 -04:00
ImPlot::PushPlotClipRect();
2020-04-30 09:47:14 -04:00
ImGui::GetWindowDrawList()->AddCircleFilled(cntr,20,IM_COL32(255,255,0,255),20);
ImGui::GetWindowDrawList()->AddRect(rmin, rmax, IM_COL32(128,0,255,255));
2020-05-12 05:20:23 -04:00
ImPlot::PopPlotClipRect();
ImPlot::EndPlot();
2020-04-30 09:47:14 -04:00
}
}
//-------------------------------------------------------------------------
2020-08-17 21:20:15 -04:00
if (ImGui::CollapsingHeader("Custom Plotters")) {
ImGui::BulletText("You can create customer plotters or extend ImPlot using implot_internal.h.");
double dates[] = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49};
double opens[] = {1284.7,1319.9,1318.7,1328,1317.6,1321.6,1314.3,1325,1319.3,1323.1,1324.7,1321.3,1323.5,1322,1281.3,1281.95,1311.1,1315,1314,1313.1,1331.9,1334.2,1341.3,1350.6,1349.8,1346.4,1343.4,1344.9,1335.6,1337.9,1342.5,1337,1338.6,1337,1340.4,1324.65,1324.35,1349.5,1371.3,1367.9,1351.3,1357.8,1356.1,1356,1347.6,1339.1,1320.6,1311.8,1314,1312.4,};
double closes[] = {1283.35,1315.3,1326.1,1317.4,1321.5,1317.4,1323.5,1319.2,1321.3,1323.3,1319.7,1325.1,1323.6,1313.8,1282.05,1279.05,1314.2,1315.2,1310.8,1329.1,1334.5,1340.2,1340.5,1350,1347.1,1344.3,1344.6,1339.7,1339.4,1343.7,1337,1338.9,1340.1,1338.7,1346.8,1324.25,1329.55,1369.6,1372.5,1352.4,1357.6,1354.2,1353.4,1346,1341,1323.8,1311.9,1309.1,1312.2,1310.7};
double lows[] = {1282.85,1315,1318.7,1309.6,1317.6,1312.9,1312.4,1319.1,1319,1321,1318.1,1321.3,1319.9,1312,1280.5,1276.15,1308,1309.9,1308.5,1312.3,1329.3,1333.1,1340.2,1347,1345.9,1338,1340.8,1335,1332,1337.9,1333,1336.8,1333.2,1329.9,1340.4,1323.85,1324.05,1349,1366.3,1351.2,1349.1,1352.4,1350.7,1344.3,1338.9,1316.3,1308.4,1306.9,1309.6,1306.7};
double highs[] = {1284.75,1320.6,1327,1330.8,1326.8,1321.6,1326,1328,1325.8,1327.1,1326,1326,1323.5,1322.1,1282.7,1282.95,1315.8,1316.3,1314,1333.2,1334.7,1341.7,1353.2,1354.6,1352.2,1346.4,1345.7,1344.9,1340.7,1344.2,1342.7,1342.1,1345.2,1342,1350,1324.95,1330.75,1369.6,1374.3,1368.4,1359.8,1359,1357,1356,1353.4,1340.6,1322.3,1314.1,1316.1,1312.9};
ImPlot::SetNextPlotLimits(0, 50, 1260, 1380);
if (ImPlot::BeginPlot("##CustomPlotter","Day","Price [USD]")) {
MyImPlot::PlotCandlestick("GOOGL",dates, opens, closes, lows, highs, 50);
ImPlot::EndPlot();
}
}
//-------------------------------------------------------------------------
if (ImGui::CollapsingHeader("Benchmark")) {
static const int n_items = 100;
static BenchmarkItem items[n_items];
ImGui::BulletText("Make sure VSync is disabled.");
ImGui::BulletText("%d lines with %d points each @ %.3f FPS.",n_items,1000,ImGui::GetIO().Framerate);
ImGui::BulletText("ImDrawIdx: %d-bit", (int)(sizeof(ImDrawIdx) * 8));
ImGui::BulletText("ImGuiBackendFlags_RendererHasVtxOffset: %s", (ImGui::GetIO().BackendFlags & ImGuiBackendFlags_RendererHasVtxOffset) ? "True" : "False");
ImGui::BulletText("If you see visual artifacts, do one of the following:");
ImGui::Indent();
ImGui::BulletText("Handle ImGuiBackendFlags_RendererHasVtxOffset for 16-bit indices in your backend.");
ImGui::BulletText("Enable 32-bit indices in imconfig.h.");
ImGui::Unindent();
2020-06-12 08:59:17 -04:00
ImPlot::SetNextPlotLimits(0,1,0,1,ImGuiCond_Always);
2020-05-16 10:11:29 -04:00
if (ImPlot::BeginPlot("##Bench",NULL,NULL,ImVec2(-1,0),ImPlotFlags_Default | ImPlotFlags_NoChild)) {
char buff[16];
for (int i = 0; i < 100; ++i) {
sprintf(buff, "item_%d",i);
2020-05-12 05:20:23 -04:00
ImPlot::PushStyleColor(ImPlotCol_Line, items[i].Col);
ImPlot::PlotLine(buff, items[i].Data, 1000);
2020-05-12 05:20:23 -04:00
ImPlot::PopStyleColor();
}
2020-05-12 05:20:23 -04:00
ImPlot::EndPlot();
}
}
2020-04-30 09:47:14 -04:00
//-------------------------------------------------------------------------
ImGui::End();
2020-04-27 11:27:59 -04:00
}
2020-06-04 01:17:38 -04:00
} // namespace ImPlot
2020-08-17 21:20:15 -04:00
// WARNING:
//
// You can use "implot_internal.h" to build custom plotting fuctions or extend ImPlot.
// However, note that forward compatibility of this file is not guaranteed and the
// internal API is subject to change. At some point we hope to bring more of this
// into the public API and expose the necessary building blocks to fully support
// custom plotters. For now, proceed at your own risk!
#include <implot_internal.h>
namespace MyImPlot {
void PlotCandlestick(const char* label_id, const double* xs, const double* opens, const double* closes, const double* lows, const double* highs, int count, float tail_width, float real_width, ImVec4 bullCol, ImVec4 bearCol) {
// get current implot context
ImPlotContext* implot = ImPlot::GetCurrentContext();
// register item
ImPlotItem* item = ImPlot::RegisterOrGetItem(label_id);
// override legend icon color
item->Color = ImVec4(1,1,1,1);
// return if item not shown (i.e. hidden by legend button)
if (!item->Show)
return;
// fit data if requested
if (implot->FitThisFrame) {
for (int i = 0; i < count; ++i) {
ImPlot::FitPoint(ImPlotPoint(xs[i], lows[i]));
ImPlot::FitPoint(ImPlotPoint(xs[i], highs[i]));
}
}
// get ImGui window DrawList
ImDrawList* draw_list = ImGui::GetWindowDrawList();
// push clip rect for the current plot
ImPlot::PushPlotClipRect();
for (int i = 0; i < count; ++i) {
ImVec2 open_pos = ImPlot::PlotToPixels(xs[i], opens[i]);
ImVec2 close_pos = ImPlot::PlotToPixels(xs[i], closes[i]);
ImVec2 low_pos = ImPlot::PlotToPixels(xs[i], lows[i]);
ImVec2 high_pos = ImPlot::PlotToPixels(xs[i], highs[i]);
ImU32 col = ImGui::GetColorU32(opens[i] > closes[i] ? bearCol : bullCol);
draw_list->AddLine(low_pos, high_pos, col, tail_width);
draw_list->AddLine(open_pos, close_pos, col, real_width);
}
// pop clip rect for the current plot
ImPlot::PopPlotClipRect();
}
}