epezent / epezent/implot

PlotStems index problem?

Open
#550 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
6.2k
Forks
693
PR merge metrics
No merged PRs in 30d

Description

Hello

I have probelm with ImPlot::PlotStems. i'm trying to draw Real Time plot but some of line segments draw only at x=1 position.... When i change to PlotLine type everything is working fine.
Also I found that changing ScrollingBuffer implementation to have two independent vectors for x and y fix the problem, but i was wondering why PlotLines was working properly....

![Zrzut ekranu 2024-01-08 083953](https://github.com/epezent/implot/assets/34631947/417287f3-d19c-49a6-9949-08217810c86d)
![Zrzut ekranu 2024-01-08 084056](https://github.com/epezent/implot/assets/34631947/37093242-0b2f-4d4d-a3f8-5725078448f7)

```
struct ScrollingBuffer {
int MaxSize;
int Offset;
ImVector Data;

ScrollingBuffer(int max_size = 2000) {
MaxSize = max_size;
Offset = 0;
Data.reserve(MaxSize);
}
void AddPoint(float x, float y) {
if (Data.size() < MaxSize)
Data.push_back(ImVec2(x,y));
else {
Data[Offset] = ImVec2(x,y);
Offset = (Offset + 1) % MaxSize;
}
}
void Erase() {
if (Data.size() > 0) {
Data.shrink(0);
Offset = 0;
}
}
};

ImPlotFlags plotFlags = ImPlotFlags_NoTitle| ImPlotFlags_NoLegend;
ImPlotAxisFlags axisFlags = ImPlotAxisFlags_None;//ImPlotAxisFlags_NoTickLabels;

static bool m_plotEnable;
ImGui::Checkbox("Plot Enable", &m_plotEnable);

static ScrollingBuffer data1;

static float t = 0;
static float delta = 0;
delta += ImGui::GetIO().DeltaTime;

if(delta > 0.25f) {
delta = 0.0;
if(m_plotEnable) {
data1.AddPoint(t, 1.0);
t += 1;
}
}

static float history = 10.0f;
ImGui::SliderFloat("History",&history,0.1,30,"%.1f s");

if (ImPlot::BeginPlot("Stem Plots", ImVec2(-1,0), plotFlags) ) {
ImPlot::SetupAxes(nullptr, nullptr, axisFlags, axisFlags);

ImPlot::SetupAxisLimits(ImAxis_X1, t-history, t, ImGuiCond_Always);
ImPlot::SetupAxisLimits(ImAxis_Y1,-1,1.5);
if( data1.Data.size() > 0) {
ImPlot::SetNextMarkerStyle(ImPlotMarker_Circle);
ImPlot::PlotStems("Plot 1",&data1.Data[0].x, &data1.Data[0].y, data1.Data.size(), 0, data1.Offset, 2*sizeof(float));
}
ImPlot::EndPlot();
}
```

Compiler: gcc 12.2.0
ImPlot: 0.17

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.