1
0
Fork 0
mirror of https://github.com/gwm17/implot.git synced 2024-11-26 20:28:50 -05:00

fix bug where no offsetting was done for ImPlotPoint* and ImVec2* plotters

This commit is contained in:
epezent 2020-08-22 00:35:41 -05:00
parent 5039315122
commit eff8b5be43
2 changed files with 18 additions and 6 deletions

View File

@ -463,7 +463,7 @@ void ShowDemoWindow(bool* p_open) {
ImPlot::SetNextPlotLimitsX(t - history, t, paused ? ImGuiCond_Once : ImGuiCond_Always); ImPlot::SetNextPlotLimitsX(t - history, t, paused ? ImGuiCond_Once : ImGuiCond_Always);
static int rt_axis = ImPlotAxisFlags_Default & ~ImPlotAxisFlags_TickLabels; 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)) { if (ImPlot::BeginPlot("##Scrolling", NULL, NULL, ImVec2(-1,150), ImPlotFlags_Default, rt_axis, rt_axis | ImPlotAxisFlags_LockMin)) {
ImPlot::PlotLine("Data 1", &sdata1.Data[0].x, &sdata1.Data[0].y, sdata1.Data.size(), sdata1.Offset, 2 * sizeof(t_float)); ImPlot::PlotLine("Data 1", &sdata1.Data[0], sdata1.Data.size(), sdata1.Offset);
ImPlot::PushStyleVar(ImPlotStyleVar_FillAlpha, 0.25f); 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::PlotShaded("Data 2", &sdata2.Data[0].x, &sdata2.Data[0].y, sdata2.Data.size(), 0, sdata2.Offset, 2 * sizeof(t_float));
ImPlot::PopStyleVar(); ImPlot::PopStyleVar();
@ -471,7 +471,10 @@ void ShowDemoWindow(bool* p_open) {
} }
ImPlot::SetNextPlotLimitsX(0, history, ImGuiCond_Always); ImPlot::SetNextPlotLimitsX(0, history, ImGuiCond_Always);
if (ImPlot::BeginPlot("##Rolling", NULL, NULL, ImVec2(-1,150), ImPlotFlags_Default, rt_axis, rt_axis)) { if (ImPlot::BeginPlot("##Rolling", NULL, NULL, ImVec2(-1,150), ImPlotFlags_Default, rt_axis, rt_axis)) {
ImPlot::PlotLine("Data 1", &rdata1.Data[0].x, &rdata1.Data[0].y, rdata1.Data.size(), 0, 2 * sizeof(t_float)); // two methods of plotting Data
// as ImVec2* (or ImPlot*):
ImPlot::PlotLine("Data 1", &rdata1.Data[0], rdata1.Data.size());
// as float*, float* (or double*, double*)
ImPlot::PlotLine("Data 2", &rdata2.Data[0].x, &rdata2.Data[0].y, rdata2.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));
ImPlot::EndPlot(); ImPlot::EndPlot();
} }
@ -947,7 +950,7 @@ void ShowDemoWindow(bool* p_open) {
static float data[100]; static float data[100];
srand(row); srand(row);
for (int i = 0; i < 100; ++i) for (int i = 0; i < 100; ++i)
data[i] = RandomRange(0,10); data[i] = (float)RandomRange(0,10);
ImGui::TableSetColumnIndex(0); ImGui::TableSetColumnIndex(0);
ImGui::Text("EMG %d", row); ImGui::Text("EMG %d", row);
ImGui::TableSetColumnIndex(1); ImGui::TableSetColumnIndex(1);

View File

@ -126,7 +126,10 @@ struct GetterImVec2 {
Count = count; Count = count;
Offset = count ? ImPosMod(offset, count) : 0; Offset = count ? ImPosMod(offset, count) : 0;
} }
inline ImPlotPoint operator()(int idx) { return ImPlotPoint(Data[idx].x, Data[idx].y); } inline ImPlotPoint operator()(int idx) {
idx = ImPosMod(Offset + idx, Count);
return ImPlotPoint(Data[idx].x, Data[idx].y);
}
const ImVec2* Data; const ImVec2* Data;
int Count; int Count;
int Offset; int Offset;
@ -139,7 +142,10 @@ struct GetterImPlotPoint {
Count = count; Count = count;
Offset = count ? ImPosMod(offset, count) : 0; Offset = count ? ImPosMod(offset, count) : 0;
} }
inline ImPlotPoint operator()(int idx) { return Data[idx]; } inline ImPlotPoint operator()(int idx) {
idx = ImPosMod(Offset + idx, Count);
return Data[idx];
}
const ImPlotPoint* Data; const ImPlotPoint* Data;
int Count; int Count;
int Offset; int Offset;
@ -153,7 +159,10 @@ struct GetterFuncPtrImPlotPoint {
Count = count; Count = count;
Offset = count ? ImPosMod(offset, count) : 0; Offset = count ? ImPosMod(offset, count) : 0;
} }
inline ImPlotPoint operator()(int idx) { return getter(Data, idx); } inline ImPlotPoint operator()(int idx) {
idx = ImPosMod(Offset + idx, Count);
return getter(Data, idx);
}
ImPlotPoint (*getter)(void* data, int idx); ImPlotPoint (*getter)(void* data, int idx);
void* Data; void* Data;
int Count; int Count;