From b783185acc1a8c4007517f13bfec2c663fe5961e Mon Sep 17 00:00:00 2001 From: Evan Pezent Date: Sat, 16 May 2020 08:39:43 -0500 Subject: [PATCH] rename plotting functions, add PlotScatter --- README.md | 2 +- implot.cpp | 90 +++++++++++++++++++++------- implot.h | 51 ++++++++-------- implot_demo.cpp | 153 ++++++++++++++++++++++++------------------------ 4 files changed, 175 insertions(+), 121 deletions(-) diff --git a/README.md b/README.md index b6900a5..6c1f578 100644 --- a/README.md +++ b/README.md @@ -27,7 +27,7 @@ ImPlot is an immediate mode plotting widget for [Dear ImGui](https://github.com/ - size-aware grid with smart labels that are always power-of-ten multiples of 1, 2, and 5 - default styling based on current ImGui theme, but most elements can be customized independently - mouse cursor location display and optional crosshairs cursor -- customizable data getters and data striding (just like ImGui:PlotLines) +- customizable data getters and data striding (just like ImGui:PlotLine) - relatively good performance for high density plots ## Usage diff --git a/implot.cpp b/implot.cpp index 134184a..231dd3c 100644 --- a/implot.cpp +++ b/implot.cpp @@ -31,8 +31,10 @@ Below is a change-log of API breaking changes only. If you are using one of the When you are not sure about a old symbol or function name, try using the Search/Find function of your IDE to look for comments or references in all implot files. You can read releases logs https://github.com/epezent/implot/releases for more details. -- 2020/05/13 (0.2) - ImMarker was change to ImPlotMarker and ImAxisFlags was changed to ImPlotAxisFlags -- 2020/05/11 (0.2) - ImPlotFlags_Selection was changed to ImPlotFlags_BoxSelect +- 2020/05/16 (0.2) - All plotting functions were reverted to being prefixed with "Plot" to maintain a consistent VerbNoun style. `Plot` was split into `PlotLine` + and `PlotScatter` (however, `PlotLine` can still be used to plot scatter points as `Plot` did before.) +- 2020/05/13 (0.2) - `ImMarker` was change to `ImPlotMarker` and `ImAxisFlags` was changed to `ImPlotAxisFlags`. +- 2020/05/11 (0.2) - `ImPlotFlags_Selection` was changed to `ImPlotFlags_BoxSelect` - 2020/05/11 (0.2) - The namespace ImGui:: was replaced with ImPlot::. As a result, the following additional changes were made: - Functions that were prefixed or decorated with the word "Plot" have been truncated. E.g., `ImGui::PlotBar` is now just `ImPlot::Bar`. It should be fairly obvious what was what. @@ -77,7 +79,7 @@ You can read releases logs https://github.com/epezent/implot/releases for more d ImPlotStyle::ImPlotStyle() { LineWeight = 1; Marker = ImPlotMarker_None; - MarkerSize = 5; + MarkerSize = 4; MarkerWeight = 1; ErrorBarSize = 5; ErrorBarWeight = 1.5; @@ -2243,26 +2245,74 @@ inline void PlotEx(const char* label_id, Getter getter, int count, int offset) PopPlotClipRect(); } -void Plot(const char* label_id, const float* values, int count, int offset, int stride) { +void PlotLine(const char* label_id, const float* values, int count, int offset, int stride) { GetterYs getter(values,stride); PlotEx(label_id, getter, count, offset); } -void Plot(const char* label_id, const float* xs, const float* ys, int count, int offset, int stride) { +void PlotLine(const char* label_id, const float* xs, const float* ys, int count, int offset, int stride) { Getter2D getter(xs,ys,stride); return PlotEx(label_id, getter, count, offset); } -void Plot(const char* label_id, const ImVec2* data, int count, int offset) { +void PlotLine(const char* label_id, const ImVec2* data, int count, int offset) { GetterImVec2 getter(data); return PlotEx(label_id, getter, count, offset); } -void Plot(const char* label_id, ImVec2 (*getter_func)(void* data, int idx), void* data, int count, int offset) { +void PlotLine(const char* label_id, ImVec2 (*getter_func)(void* data, int idx), void* data, int count, int offset) { GetterFuncPtrImVec2 getter(getter_func,data); return PlotEx(label_id, getter, count, offset); } +//----------------------------------------------------------------------------- +// PLOT SCATTER +//----------------------------------------------------------------------------- + +void PlotScatter(const char* label_id, const float* values, int count, int offset, int stride) { + int pops = 1; + PushStyleVar(ImPlotStyleVar_LineWeight, 0); + if (GetStyle().Marker == ImPlotMarker_None) { + PushStyleVar(ImPlotStyleVar_Marker, ImPlotMarker_Circle); + pops++; + } + PlotLine(label_id, values, count, offset, stride); + PopStyleVar(pops); +} + +void PlotScatter(const char* label_id, const float* xs, const float* ys, int count, int offset, int stride) { + int pops = 1; + PushStyleVar(ImPlotStyleVar_LineWeight, 0); + if (GetStyle().Marker == ImPlotMarker_None) { + PushStyleVar(ImPlotStyleVar_Marker, ImPlotMarker_Circle); + pops++; + } + PlotLine(label_id, xs, ys, count, offset, stride); + PopStyleVar(pops); +} + +void PlotScatter(const char* label_id, const ImVec2* data, int count, int offset) { + int pops = 1; + PushStyleVar(ImPlotStyleVar_LineWeight, 0); + if (GetStyle().Marker == ImPlotMarker_None) { + PushStyleVar(ImPlotStyleVar_Marker, ImPlotMarker_Circle); + pops++; + } + PlotLine(label_id, data, count, offset); + PopStyleVar(pops); +} + +void PlotScatter(const char* label_id, ImVec2 (*getter)(void* data, int idx), void* data, int count, int offset) { + int pops = 1; + PushStyleVar(ImPlotStyleVar_LineWeight, 0); + if (GetStyle().Marker == ImPlotMarker_None) { + PushStyleVar(ImPlotStyleVar_Marker, ImPlotMarker_Circle); + pops++; + } + PlotLine(label_id, getter, data, count, offset); + PopStyleVar(pops); +} + //----------------------------------------------------------------------------- // PLOT BAR //----------------------------------------------------------------------------- @@ -2333,17 +2383,17 @@ void PlotBarEx(const char* label_id, Getter getter, int count, float width, int PopPlotClipRect(); } -void Bar(const char* label_id, const float* values, int count, float width, float shift, int offset, int stride) { +void PlotBar(const char* label_id, const float* values, int count, float width, float shift, int offset, int stride) { GetterBarV getter(values,shift,stride); PlotBarEx(label_id, getter, count, width, offset); } -void Bar(const char* label_id, const float* xs, const float* ys, int count, float width, int offset, int stride) { +void PlotBar(const char* label_id, const float* xs, const float* ys, int count, float width, int offset, int stride) { Getter2D getter(xs,ys,stride); PlotBarEx(label_id, getter, count, width, offset); } -void Bar(const char* label_id, ImVec2 (*getter_func)(void* data, int idx), void* data, int count, float width, int offset) { +void PlotBar(const char* label_id, ImVec2 (*getter_func)(void* data, int idx), void* data, int count, float width, int offset) { GetterFuncPtrImVec2 getter(getter_func, data); PlotBarEx(label_id, getter, count, width, offset); } @@ -2403,17 +2453,17 @@ void PlotBarHEx(const char* label_id, Getter getter, int count, float height, i PopPlotClipRect(); } -void BarH(const char* label_id, const float* values, int count, float height, float shift, int offset, int stride) { +void PlotBarH(const char* label_id, const float* values, int count, float height, float shift, int offset, int stride) { GetterBarH getter(values,shift,stride); PlotBarHEx(label_id, getter, count, height, offset); } -void BarH(const char* label_id, const float* xs, const float* ys, int count, float height, int offset, int stride) { +void PlotBarH(const char* label_id, const float* xs, const float* ys, int count, float height, int offset, int stride) { Getter2D getter(xs,ys,stride); PlotBarHEx(label_id, getter, count, height, offset); } -void BarH(const char* label_id, ImVec2 (*getter_func)(void* data, int idx), void* data, int count, float height, int offset) { +void PlotBarH(const char* label_id, ImVec2 (*getter_func)(void* data, int idx), void* data, int count, float height, int offset) { GetterFuncPtrImVec2 getter(getter_func, data); PlotBarHEx(label_id, getter, count, height, offset); } @@ -2478,17 +2528,17 @@ void PlotErrorBarsEx(const char* label_id, Getter getter, int count, int offset) PopPlotClipRect(); } -void ErrorBars(const char* label_id, const float* xs, const float* ys, const float* err, int count, int offset, int stride) { +void PlotErrorBars(const char* label_id, const float* xs, const float* ys, const float* err, int count, int offset, int stride) { GetterError getter(xs, ys, err, err, stride); PlotErrorBarsEx(label_id, getter, count, offset); } -void ErrorBars(const char* label_id, const float* xs, const float* ys, const float* neg, const float* pos, int count, int offset, int stride) { +void PlotErrorBars(const char* label_id, const float* xs, const float* ys, const float* neg, const float* pos, int count, int offset, int stride) { GetterError getter(xs, ys, neg, pos, stride); PlotErrorBarsEx(label_id, getter, count, offset); } -void ErrorBars(const char* label_id, ImVec4 (*getter_func)(void* data, int idx), void* data, int count, int offset) { +void PlotErrorBars(const char* label_id, ImVec4 (*getter_func)(void* data, int idx), void* data, int count, int offset) { GetterFuncPtrImVec4 getter(getter_func, data); PlotErrorBarsEx(label_id, getter, count, offset); } @@ -2511,7 +2561,7 @@ inline void DrawPieSlice(ImDrawList& DrawList, const ImVec2& center, float radiu } -void PieChart(const char** label_ids, float* values, int count, const ImVec2& center, float radius, bool show_percents, float angle0) { +void PlotPieChart(const char** label_ids, float* values, int count, const ImVec2& center, float radius, bool show_percents, float angle0) { IM_ASSERT_USER_ERROR(gp.CurrentPlot != NULL, "PieChart() Needs to be called between BeginPlot() and EndPlot()!"); ImDrawList & DrawList = *ImGui::GetWindowDrawList(); @@ -2552,7 +2602,7 @@ void PieChart(const char** label_ids, float* values, int count, const ImVec2& ce PopPlotClipRect(); } -void Text(const char* text, float x, float y, bool vertical, const ImVec2& pixel_offset) { +void PlotText(const char* text, float x, float y, bool vertical, const ImVec2& pixel_offset) { IM_ASSERT_USER_ERROR(gp.CurrentPlot != NULL, "Text() Needs to be called between BeginPlot() and EndPlot()!"); ImDrawList & DrawList = *ImGui::GetWindowDrawList(); PushPlotClipRect(); @@ -2645,12 +2695,12 @@ inline void PlotDigitalEx(const char* label_id, Getter getter, int count, int of ImGui::PopClipRect(); } -void Digital(const char* label_id, const float* xs, const float* ys, int count, int offset, int stride) { +void PlotDigital(const char* label_id, const float* xs, const float* ys, int count, int offset, int stride) { Getter2D getter(xs,ys,stride); return PlotDigitalEx(label_id, getter, count, offset); } -void Digital(const char* label_id, ImVec2 (*getter_func)(void* data, int idx), void* data, int count, int offset) { +void PlotDigital(const char* label_id, ImVec2 (*getter_func)(void* data, int idx), void* data, int count, int offset) { GetterFuncPtrImVec2 getter(getter_func,data); return PlotDigitalEx(label_id, getter, count, offset); } diff --git a/implot.h b/implot.h index ca22a07..909d20d 100644 --- a/implot.h +++ b/implot.h @@ -133,8 +133,8 @@ struct ImPlotLimits { // Plot style structure struct ImPlotStyle { float LineWeight; // = 1, line weight in pixels - ImPlotMarker Marker; // = ImPlotMarker_None, marker specification - float MarkerSize; // = 5, marker size in pixels (roughly the marker's "radius") + ImPlotMarker Marker; // = ImPlotMarker_None, marker specification + float MarkerSize; // = 4, marker size in pixels (roughly the marker's "radius") float MarkerWeight; // = 1, outline weight of markers in pixels float ErrorBarSize; // = 5, error bar whisker width in pixels float ErrorBarWeight; // = 1.5, error bar whisker weight in pixels @@ -172,30 +172,35 @@ void EndPlot(); // Plot Items //----------------------------------------------------------------------------- -// Plots a standard 2D line and/or scatter plot. -void Plot(const char* label_id, const float* values, int count, int offset = 0, int stride = sizeof(float)); -void Plot(const char* label_id, const float* xs, const float* ys, int count, int offset = 0, int stride = sizeof(float)); -void Plot(const char* label_id, const ImVec2* data, int count, int offset = 0); -void Plot(const char* label_id, ImVec2 (*getter)(void* data, int idx), void* data, int count, int offset = 0); -// Plots vertical bars. -void Bar(const char* label_id, const float* values, int count, float width = 0.67f, float shift = 0, int offset = 0, int stride = sizeof(float)); -void Bar(const char* label_id, const float* xs, const float* ys, int count, float width, int offset = 0, int stride = sizeof(float)); -void Bar(const char* label_id, ImVec2 (*getter)(void* data, int idx), void* data, int count, float width, int offset = 0); -// Plots horizontal bars. -void BarH(const char* label_id, const float* values, int count, float height = 0.67f, float shift = 0, int offset = 0, int stride = sizeof(float)); -void BarH(const char* label_id, const float* xs, const float* ys, int count, float height, int offset = 0, int stride = sizeof(float)); -void BarH(const char* label_id, ImVec2 (*getter)(void* data, int idx), void* data, int count, float height, int offset = 0); +// Plots a standard 2D line plot. +void PlotLine(const char* label_id, const float* values, int count, int offset = 0, int stride = sizeof(float)); +void PlotLine(const char* label_id, const float* xs, const float* ys, int count, int offset = 0, int stride = sizeof(float)); +void PlotLine(const char* label_id, const ImVec2* data, int count, int offset = 0); +void PlotLine(const char* label_id, ImVec2 (*getter)(void* data, int idx), void* data, int count, int offset = 0); +// Plots a standard 2D scatter plot. +void PlotScatter(const char* label_id, const float* values, int count, int offset = 0, int stride = sizeof(float)); +void PlotScatter(const char* label_id, const float* xs, const float* ys, int count, int offset = 0, int stride = sizeof(float)); +void PlotScatter(const char* label_id, const ImVec2* data, int count, int offset = 0); +void PlotScatter(const char* label_id, ImVec2 (*getter)(void* data, int idx), void* data, int count, int offset = 0); +// Plots a vertical bar graph. +void PlotBar(const char* label_id, const float* values, int count, float width = 0.67f, float shift = 0, int offset = 0, int stride = sizeof(float)); +void PlotBar(const char* label_id, const float* xs, const float* ys, int count, float width, int offset = 0, int stride = sizeof(float)); +void PlotBar(const char* label_id, ImVec2 (*getter)(void* data, int idx), void* data, int count, float width, int offset = 0); +// Plots a horizontal bars graph. +void PlotBarH(const char* label_id, const float* values, int count, float height = 0.67f, float shift = 0, int offset = 0, int stride = sizeof(float)); +void PlotBarH(const char* label_id, const float* xs, const float* ys, int count, float height, int offset = 0, int stride = sizeof(float)); +void PlotBarH(const char* label_id, ImVec2 (*getter)(void* data, int idx), void* data, int count, float height, int offset = 0); // Plots vertical error bars. -void ErrorBars(const char* label_id, const float* xs, const float* ys, const float* err, int count, int offset = 0, int stride = sizeof(float)); -void ErrorBars(const char* label_id, const float* xs, const float* ys, const float* neg, const float* pos, int count, int offset = 0, int stride = sizeof(float)); -void ErrorBars(const char* label_id, ImVec4 (*getter)(void* data, int idx), void* data, int count, int offset = 0); +void PlotErrorBars(const char* label_id, const float* xs, const float* ys, const float* err, int count, int offset = 0, int stride = sizeof(float)); +void PlotErrorBars(const char* label_id, const float* xs, const float* ys, const float* neg, const float* pos, int count, int offset = 0, int stride = sizeof(float)); +void PlotErrorBars(const char* label_id, ImVec4 (*getter)(void* data, int idx), void* data, int count, int offset = 0); // Plots a pie chart. If the sum of values > 1, each value will be normalized. Center and radius are in plot coordinates. -void PieChart(const char** label_ids, float* values, int count, const ImVec2& center, float radius, bool show_percents = true, float angle0 = 90); -// Plots digital channels. -void Digital(const char* label_id, const float* xs, const float* ys, int count, int offset = 0, int stride = sizeof(float)); -void Digital(const char* label_id, ImVec2 (*getter)(void* data, int idx), void* data, int count, int offset = 0); +void PlotPieChart(const char** label_ids, float* values, int count, const ImVec2& center, float radius, bool show_percents = true, float angle0 = 90); +// Plots digital data. +void PlotDigital(const char* label_id, const float* xs, const float* ys, int count, int offset = 0, int stride = sizeof(float)); +void PlotDigital(const char* label_id, ImVec2 (*getter)(void* data, int idx), void* data, int count, int offset = 0); // Plots a text label at point x,y. -void Text(const char* text, float x, float y, bool vertical = false, const ImVec2& pixel_offset = ImVec2(0,0)); +void PlotText(const char* text, float x, float y, bool vertical = false, const ImVec2& pixel_offset = ImVec2(0,0)); //----------------------------------------------------------------------------- // Plot Queries diff --git a/implot_demo.cpp b/implot_demo.cpp index df91b18..fdf1800 100644 --- a/implot_demo.cpp +++ b/implot_demo.cpp @@ -153,9 +153,9 @@ void ShowDemoWindow(bool* p_open) { ys2[i] = xs2[i] * xs2[i]; } if (ImPlot::BeginPlot("Line Plot", "x", "f(x)", ImVec2(-1,300))) { - ImPlot::Plot("sin(50*x)", xs1, ys1, 1001); + ImPlot::PlotLine("sin(50*x)", xs1, ys1, 1001); ImPlot::PushStyleVar(ImPlotStyleVar_Marker, ImPlotMarker_Circle); - ImPlot::Plot("x^2", xs2, ys2, 11); + ImPlot::PlotLine("x^2", xs2, ys2, 11); ImPlot::PopStyleVar(); ImPlot::EndPlot(); } @@ -174,16 +174,16 @@ void ShowDemoWindow(bool* p_open) { ys2[i] = 0.75f + 0.2f * ((float)rand() / (float)RAND_MAX); } if (ImPlot::BeginPlot("Scatter Plot", NULL, NULL, ImVec2(-1,300))) { - ImPlot::PushStyleVar(ImPlotStyleVar_LineWeight, 0); - ImPlot::PushStyleVar(ImPlotStyleVar_Marker, ImPlotMarker_Cross); - ImPlot::PushStyleVar(ImPlotStyleVar_MarkerSize, 3); - ImPlot::Plot("Data 1", xs1, ys1, 100); - ImPlot::PopStyleVar(2); - ImPlot::PushStyleVar(ImPlotStyleVar_Marker, ImPlotMarker_Circle); - ImPlot::PushStyleColor(ImPlotCol_MarkerFill, ImVec4(1,0,0,0.25f)); - ImPlot::Plot("Data 2", xs2, ys2, 50); - ImPlot::PopStyleColor(); + ImPlot::PlotScatter("Data 1", xs1, ys1, 100); + + ImPlot::PushStyleVar(ImPlotStyleVar_MarkerSize, 6); + ImPlot::PushStyleVar(ImPlotStyleVar_Marker, ImPlotMarker_Square); + ImPlot::PushStyleColor(ImPlotCol_MarkerFill, ImVec4(1,0,0,0.25f)); + ImPlot::PushStyleColor(ImPlotCol_MarkerOutline, ImVec4(0,0,0,0)); + ImPlot::PlotScatter("Data 2", xs2, ys2, 50); + ImPlot::PopStyleColor(2); ImPlot::PopStyleVar(2); + ImPlot::EndPlot(); } } @@ -200,14 +200,14 @@ void ShowDemoWindow(bool* p_open) { static float final[10] = {80, 62, 56, 99, 55, 78, 88, 78, 90, 100}; static float grade[10] = {80, 69, 52, 92, 72, 78, 75, 76, 89, 95}; if (horz) { - ImPlot::BarH("Midterm Exam", midtm, 10, 0.2f, -0.2f); - ImPlot::BarH("Final Exam", final, 10, 0.2f, 0); - ImPlot::BarH("Course Grade", grade, 10, 0.2f, 0.2f); + ImPlot::PlotBarH("Midterm Exam", midtm, 10, 0.2f, -0.2f); + ImPlot::PlotBarH("Final Exam", final, 10, 0.2f, 0); + ImPlot::PlotBarH("Course Grade", grade, 10, 0.2f, 0.2f); } else { - ImPlot::Bar("Midterm Exam", midtm, 10, 0.2f, -0.2f); - ImPlot::Bar("Final Exam", final, 10, 0.2f, 0); - ImPlot::Bar("Course Grade", grade, 10, 0.2f, 0.2f); + ImPlot::PlotBar("Midterm Exam", midtm, 10, 0.2f, -0.2f); + ImPlot::PlotBar("Final Exam", final, 10, 0.2f, 0); + ImPlot::PlotBar("Course Grade", grade, 10, 0.2f, 0.2f); } ImPlot::EndPlot(); } @@ -222,14 +222,14 @@ void ShowDemoWindow(bool* p_open) { ImPlot::SetNextPlotLimits(0, 6, 0, 10); if (ImPlot::BeginPlot("##ErrorBars",NULL,NULL,ImVec2(-1,300))) { - ImPlot::Bar("Bar", xs, bar, 5, 0.5f); - ImPlot::ErrorBars("Bar", xs, bar, err1, 5); + ImPlot::PlotBar("Bar", xs, bar, 5, 0.5f); + ImPlot::PlotErrorBars("Bar", xs, bar, err1, 5); ImPlot::PushStyleVar(ImPlotStyleVar_Marker, ImPlotMarker_Circle); ImPlot::PushStyleVar(ImPlotStyleVar_MarkerSize, 3); ImPlot::PushStyleColor(ImPlotCol_ErrorBar, ImVec4(1,0,0,1)); - ImPlot::ErrorBars("Line", xs, lin, err1, err2, 5); - ImPlot::Plot("Line", xs, lin, 5); + ImPlot::PlotErrorBars("Line", xs, lin, err1, err2, 5); + ImPlot::PlotLine("Line", xs, lin, 5); ImPlot::PopStyleVar(2); ImPlot::PopStyleColor(); @@ -245,7 +245,7 @@ void ShowDemoWindow(bool* p_open) { SetNextPlotLimits(0,1,0,1,ImGuiCond_Always); if (ImPlot::BeginPlot("##Pie1", NULL, NULL, ImVec2(250,250), ImPlotFlags_Legend, 0, 0)) { - ImPlot::PieChart(labels1, pre_normalized, 4, center, radius); + ImPlot::PlotPieChart(labels1, pre_normalized, 4, center, radius); ImPlot::EndPlot(); } ImGui::SameLine(); @@ -262,7 +262,7 @@ void ShowDemoWindow(bool* p_open) { static const char* labels2[] = {"One","Two","Three","Four","Five"}; static float not_normalized[] = {1,2,3,4,5}; if (ImPlot::BeginPlot("##Pie2", NULL, NULL, ImVec2(250,250), ImPlotFlags_Legend, 0, 0)) { - ImPlot::PieChart(labels2, not_normalized, 5, center, radius); + ImPlot::PlotPieChart(labels2, not_normalized, 5, center, radius); ImPlot::EndPlot(); } ImPlot::RestorePalette(); @@ -286,14 +286,14 @@ void ShowDemoWindow(bool* p_open) { ImPlot::SetNextPlotLimitsX(t - 10, 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)) { - ImPlot::Plot("Data 1", &sdata1.Data[0].x, &sdata1.Data[0].y, sdata1.Data.size(), sdata1.Offset, 2 * sizeof(float)); - ImPlot::Plot("Data 2", &sdata2.Data[0].x, &sdata2.Data[0].y, sdata2.Data.size(), sdata2.Offset, 2 * sizeof(float)); + ImPlot::PlotLine("Data 1", &sdata1.Data[0].x, &sdata1.Data[0].y, sdata1.Data.size(), sdata1.Offset, 2 * sizeof(float)); + ImPlot::PlotLine("Data 2", &sdata2.Data[0].x, &sdata2.Data[0].y, sdata2.Data.size(), sdata2.Offset, 2 * sizeof(float)); ImPlot::EndPlot(); } ImPlot::SetNextPlotLimitsX(0, 10, ImGuiCond_Always); if (ImPlot::BeginPlot("##Rolling", NULL, NULL, ImVec2(-1,150), ImPlotFlags_Default, rt_axis, rt_axis)) { - ImPlot::Plot("Data 1", &rdata1.Data[0].x, &rdata1.Data[0].y, rdata1.Data.size(), 0, 2 * sizeof(float)); - ImPlot::Plot("Data 2", &rdata2.Data[0].x, &rdata2.Data[0].y, rdata2.Data.size(), 0, 2 * sizeof(float)); + ImPlot::PlotLine("Data 1", &rdata1.Data[0].x, &rdata1.Data[0].y, rdata1.Data.size(), 0, 2 * sizeof(float)); + ImPlot::PlotLine("Data 2", &rdata2.Data[0].x, &rdata2.Data[0].y, rdata2.Data.size(), 0, 2 * sizeof(float)); ImPlot::EndPlot(); } } @@ -305,50 +305,50 @@ void ShowDemoWindow(bool* p_open) { float ys[2] = {10,11}; // filled ImPlot::PushStyleVar(ImPlotStyleVar_Marker, ImPlotMarker_Circle); - ImPlot::Plot("Circle##Fill", xs, ys, 2); + ImPlot::PlotLine("Circle##Fill", xs, ys, 2); ImPlot::PushStyleVar(ImPlotStyleVar_Marker, ImPlotMarker_Square); ys[0]--; ys[1]--; - ImPlot::Plot("Square##Fill", xs, ys, 2); + ImPlot::PlotLine("Square##Fill", xs, ys, 2); ImPlot::PushStyleVar(ImPlotStyleVar_Marker, ImPlotMarker_Diamond); ys[0]--; ys[1]--; - ImPlot::Plot("Diamond##Fill", xs, ys, 2); + ImPlot::PlotLine("Diamond##Fill", xs, ys, 2); ImPlot::PushStyleVar(ImPlotStyleVar_Marker, ImPlotMarker_Up); ys[0]--; ys[1]--; - ImPlot::Plot("Up##Fill", xs, ys, 2); + ImPlot::PlotLine("Up##Fill", xs, ys, 2); ImPlot::PushStyleVar(ImPlotStyleVar_Marker, ImPlotMarker_Down); ys[0]--; ys[1]--; - ImPlot::Plot("Down##Fill", xs, ys, 2); + ImPlot::PlotLine("Down##Fill", xs, ys, 2); ImPlot::PushStyleVar(ImPlotStyleVar_Marker, ImPlotMarker_Left); ys[0]--; ys[1]--; - ImPlot::Plot("Left##Fill", xs, ys, 2); + ImPlot::PlotLine("Left##Fill", xs, ys, 2); ImPlot::PushStyleVar(ImPlotStyleVar_Marker, ImPlotMarker_Right); ys[0]--; ys[1]--; - ImPlot::Plot("Right##Fill", xs, ys, 2); + ImPlot::PlotLine("Right##Fill", xs, ys, 2); ImPlot::PushStyleVar(ImPlotStyleVar_Marker, ImPlotMarker_Cross); ys[0]--; ys[1]--; - ImPlot::Plot("Cross##Fill", xs, ys, 2); + ImPlot::PlotLine("Cross##Fill", xs, ys, 2); ImPlot::PushStyleVar(ImPlotStyleVar_Marker, ImPlotMarker_Plus); ys[0]--; ys[1]--; - ImPlot::Plot("Plus##Fill", xs, ys, 2); + ImPlot::PlotLine("Plus##Fill", xs, ys, 2); ImPlot::PushStyleVar(ImPlotStyleVar_Marker, ImPlotMarker_Asterisk); ys[0]--; ys[1]--; - ImPlot::Plot("Asterisk##Fill", xs, ys, 2); + ImPlot::PlotLine("Asterisk##Fill", xs, ys, 2); ImPlot::PopStyleVar(10); xs[0] = 6; xs[1] = 9; ys[0] = 10; ys[1] = 11; ImPlot::PushStyleColor(ImPlotCol_MarkerFill, ImVec4(0,0,0,0)); ImPlot::PushStyleVar(ImPlotStyleVar_Marker, ImPlotMarker_Circle); - ImPlot::Plot("Circle", xs, ys, 2); + ImPlot::PlotLine("Circle", xs, ys, 2); ImPlot::PushStyleVar(ImPlotStyleVar_Marker, ImPlotMarker_Square); ys[0]--; ys[1]--; - ImPlot::Plot("Square", xs, ys, 2); + ImPlot::PlotLine("Square", xs, ys, 2); ImPlot::PushStyleVar(ImPlotStyleVar_Marker, ImPlotMarker_Diamond); ys[0]--; ys[1]--; - ImPlot::Plot("Diamond", xs, ys, 2); + ImPlot::PlotLine("Diamond", xs, ys, 2); ImPlot::PushStyleVar(ImPlotStyleVar_Marker, ImPlotMarker_Up); ys[0]--; ys[1]--; - ImPlot::Plot("Up", xs, ys, 2); + ImPlot::PlotLine("Up", xs, ys, 2); ImPlot::PushStyleVar(ImPlotStyleVar_Marker, ImPlotMarker_Down); ys[0]--; ys[1]--; - ImPlot::Plot("Down", xs, ys, 2); + ImPlot::PlotLine("Down", xs, ys, 2); ImPlot::PushStyleVar(ImPlotStyleVar_Marker, ImPlotMarker_Left); ys[0]--; ys[1]--; - ImPlot::Plot("Left", xs, ys, 2); + ImPlot::PlotLine("Left", xs, ys, 2); ImPlot::PushStyleVar(ImPlotStyleVar_Marker, ImPlotMarker_Right); ys[0]--; ys[1]--; - ImPlot::Plot("Right", xs, ys, 2); + ImPlot::PlotLine("Right", xs, ys, 2); ImPlot::PushStyleVar(ImPlotStyleVar_Marker, ImPlotMarker_Cross); ys[0]--; ys[1]--; - ImPlot::Plot("Cross", xs, ys, 2); + ImPlot::PlotLine("Cross", xs, ys, 2); ImPlot::PushStyleVar(ImPlotStyleVar_Marker, ImPlotMarker_Plus); ys[0]--; ys[1]--; - ImPlot::Plot("Plus", xs, ys, 2); + ImPlot::PlotLine("Plus", xs, ys, 2); ImPlot::PushStyleVar(ImPlotStyleVar_Marker, ImPlotMarker_Asterisk); ys[0]--; ys[1]--; - ImPlot::Plot("Asterisk", xs, ys, 2); + ImPlot::PlotLine("Asterisk", xs, ys, 2); ImPlot::PopStyleColor(); ImPlot::PopStyleVar(10); @@ -362,13 +362,13 @@ void ShowDemoWindow(bool* p_open) { 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::Plot("Circle|Cross", xs, ys, 2); + ImPlot::PlotLine("Circle|Cross", xs, ys, 2); ImPlot::PopStyleVar(4); ImPlot::PopStyleColor(3); - ImPlot::Text("Filled Markers", 1.5, 11.75); - ImPlot::Text("Open Markers", 6.75, 11.75); - ImPlot::Text("Fancy Markers", 4.5, 4.25, true); + ImPlot::PlotText("Filled Markers", 1.5, 11.75); + ImPlot::PlotText("Open Markers", 6.75, 11.75); + ImPlot::PlotText("Fancy Markers", 4.5, 4.25, true); ImPlot::EndPlot(); } @@ -385,10 +385,10 @@ void ShowDemoWindow(bool* p_open) { } ImPlot::SetNextPlotLimits(0.1f, 100, 0, 10); if (ImPlot::BeginPlot("Log Plot", NULL, NULL, ImVec2(-1,300), ImPlotFlags_Default, ImPlotAxisFlags_Default | ImPlotAxisFlags_LogScale )) { - ImPlot::Plot("f(x) = x", xs, xs, 1001); - ImPlot::Plot("f(x) = sin(x)+1", xs, ys1, 1001); - ImPlot::Plot("f(x) = log(x)", xs, ys2, 1001); - ImPlot::Plot("f(x) = 10^x", xs, ys3, 21); + 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); ImPlot::EndPlot(); } } @@ -430,17 +430,17 @@ void ShowDemoWindow(bool* p_open) { ImPlotFlags_Default | (y2_axis ? ImPlotFlags_YAxis2 : 0) | (y3_axis ? ImPlotFlags_YAxis3 : 0))) { - ImPlot::Plot("f(x) = x", xs, xs, 1001); - ImPlot::Plot("f(x) = sin(x)*3+1", xs, ys1, 1001); + ImPlot::PlotLine("f(x) = x", xs, xs, 1001); + ImPlot::PlotLine("f(x) = sin(x)*3+1", xs, ys1, 1001); if (y2_axis) { ImPlot::SetPlotYAxis(1); - ImPlot::Plot("f(x) = cos(x)*.2+.5 (Y2)", xs, ys2, 1001); + ImPlot::PlotLine("f(x) = cos(x)*.2+.5 (Y2)", xs, ys2, 1001); } if (y3_axis) { ImPlot::SetPlotYAxis(2); - ImPlot::Plot("f(x) = sin(x+.5)*100+200 (Y3)", xs2, ys3, 1001); + ImPlot::PlotLine("f(x) = sin(x+.5)*100+200 (Y3)", xs2, ys3, 1001); } ImPlot::EndPlot(); @@ -461,10 +461,9 @@ void ShowDemoWindow(bool* p_open) { if (ImPlot::BeginPlot("##Drawing", NULL, NULL, ImVec2(-1,300), ImPlotFlags_Default | ImPlotFlags_Query, ImPlotAxisFlags_GridLines, ImPlotAxisFlags_GridLines)) { if (ImPlot::IsPlotHovered() && ImGui::IsMouseClicked(0) && ImGui::GetIO().KeyCtrl) data.push_back(ImPlot::GetPlotMousePos()); - ImPlot::PushStyleVar(ImPlotStyleVar_LineWeight, 0); ImPlot::PushStyleVar(ImPlotStyleVar_Marker, ImPlotMarker_Diamond); if (data.size() > 0) - ImPlot::Plot("Points", &data[0].x, &data[0].y, data.size(), 0, 2 * sizeof(float)); + ImPlot::PlotScatter("Points", &data[0].x, &data[0].y, data.size(), 0, 2 * sizeof(float)); if (ImPlot::IsPlotQueried() && data.size() > 0) { ImPlotLimits range2 = ImPlot::GetPlotQuery(); int cnt = 0; @@ -479,10 +478,10 @@ void ShowDemoWindow(bool* p_open) { if (cnt > 0) { avg.x = avg.x / cnt; avg.y = avg.y / cnt; - ImPlot::Plot("Average", &avg.x, &avg.y, 1); + ImPlot::PlotScatter("Average", &avg.x, &avg.y, 1); } } - ImPlot::PopStyleVar(2); + ImPlot::PopStyleVar(); range = ImPlot::GetPlotLimits(); query = ImPlot::GetPlotQuery(); ImPlot::EndPlot(); @@ -512,17 +511,17 @@ void ShowDemoWindow(bool* p_open) { ImPlotAxisFlags flgs = ImPlotAxisFlags_Default & ~ImPlotAxisFlags_TickLabels; ImPlotLimits query; if (ImPlot::BeginPlot("##View1",NULL,NULL,ImVec2(-1,150), ImPlotFlags_Default | ImPlotFlags_Query, flgs, flgs)) { - ImPlot::Plot("Signal 1", x_data, y_data1, 512); - ImPlot::Plot("Signal 2", x_data, y_data2, 512); - ImPlot::Plot("Signal 3", x_data, y_data3, 512); + 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); 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::Plot("Signal 1", x_data, y_data1, 512); - ImPlot::Plot("Signal 2", x_data, y_data2, 512); - ImPlot::Plot("Signal 3", x_data, y_data3, 512); + 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); ImPlot::EndPlot(); } } @@ -579,7 +578,7 @@ void ShowDemoWindow(bool* p_open) { if (show[i]) { char label[8]; sprintf(label, "data_%d", i); - ImPlot::Plot(label, &data[i].Data[0].x, &data[i].Data[0].y, data[i].Data.size(), data[i].Offset, 2 * sizeof(float)); + ImPlot::PlotLine(label, &data[i].Data[0].x, &data[i].Data[0].y, data[i].Data.size(), data[i].Offset, 2 * sizeof(float)); } } ImPlot::EndPlot(); @@ -684,7 +683,7 @@ void ShowDemoWindow(bool* p_open) { sprintf(label, "digital_%d", i); ImPlot::PushStyleVar(ImPlotStyleVar_DigitalBitHeight, bitHeight); ImPlot::PushStyleVar(ImPlotStyleVar_DigitalBitGap, bitGap); - ImPlot::Digital(label, &dataDigital[i].Data[0].x, &dataDigital[i].Data[0].y, dataDigital[i].Data.size(), dataDigital[i].Offset, 2 * sizeof(float)); + ImPlot::PlotDigital(label, &dataDigital[i].Data[0].x, &dataDigital[i].Data[0].y, dataDigital[i].Data.size(), dataDigital[i].Offset, 2 * sizeof(float)); ImPlot::PopStyleVar(2); } } @@ -693,7 +692,7 @@ void ShowDemoWindow(bool* p_open) { char label[32]; sprintf(label, "analog_%d", i); if (dataAnalog[i].Data.size() > 0) - ImPlot::Plot(label, &dataAnalog[i].Data[0].x, &dataAnalog[i].Data[0].y, dataAnalog[i].Data.size(), dataAnalog[i].Offset, 2 * sizeof(float)); + ImPlot::PlotLine(label, &dataAnalog[i].Data[0].x, &dataAnalog[i].Data[0].y, dataAnalog[i].Data.size(), dataAnalog[i].Offset, 2 * sizeof(float)); } } ImPlot::EndPlot(); @@ -725,7 +724,7 @@ void ShowDemoWindow(bool* p_open) { static int offset = 0; ImGui::SliderInt("Offset", &offset, -100, 100); if (ImPlot::BeginPlot("##offset")) { - ImPlot::Plot("circle", xs, ys, 50, offset); + ImPlot::PlotLine("circle", xs, ys, 50, offset); ImPlot::EndPlot(); } } @@ -748,11 +747,11 @@ void ShowDemoWindow(bool* p_open) { float lin[10] = {8,8,9,7,8,8,8,9,7,8}; float bar[10] = {1,2,5,3,4,1,2,5,3,4}; float dot[10] = {7,6,6,7,8,5,6,5,8,7}; - ImPlot::Bar("Bar", bar, 10, 0.5f); - ImPlot::Plot("Line", lin, 10); + ImPlot::PlotBar("Bar", bar, 10, 0.5f); + ImPlot::PlotLine("Line", lin, 10); ImPlot::PushStyleVar(ImPlotStyleVar_LineWeight, 0); ImPlot::PushStyleVar(ImPlotStyleVar_Marker, ImPlotMarker_Square); - ImPlot::Plot("Dot", dot, 10); + ImPlot::PlotLine("Dot", dot, 10); ImPlot::PopStyleVar(2); ImPlot::EndPlot(); } @@ -785,7 +784,7 @@ void ShowDemoWindow(bool* p_open) { for (int i = 0; i < 100; ++i) { sprintf(buff, "item_%d",i); ImPlot::PushStyleColor(ImPlotCol_Line, items[i].Col); - ImPlot::Plot(buff, items[i].Data, 1000); + ImPlot::PlotLine(buff, items[i].Data, 1000); ImPlot::PopStyleColor(); } ImPlot::EndPlot();