Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PlotStems index problem? #550

Open
tasiek30 opened this issue Jan 8, 2024 · 0 comments
Open

PlotStems index problem? #550

tasiek30 opened this issue Jan 8, 2024 · 0 comments

Comments

@tasiek30
Copy link

tasiek30 commented Jan 8, 2024

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
Zrzut ekranu 2024-01-08 084056

struct ScrollingBuffer {
    int MaxSize;
    int Offset;
    ImVector<ImVec2> 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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant