epezent / implot

Immediate Mode Plotting
MIT License
4.78k stars 531 forks source link

Another strange way to change the color of graph lines. #307

Open MichaelKv opened 2 years ago

MichaelKv commented 2 years ago

Hello, From implot.h // ImPlot version string.

define IMPLOT_VERSION "0.13 WIP"

I have modified my example from another ticket to demonstrate a new way to change the color of graph lines. Just use the right mouse button click to do it. Such a behavior shall not happen. The culprit is ImPlot::IsPlotHovered() call. BTW, this call helps this issue https://github.com/epezent/implot/issues/306 a lot. Please, help!!!

`void ShowDemo_DragLines() { ImGui::BulletText("Click and drag the horizontal and vertical lines."); static double x1 = 0.2; static double x2 = 0.8; static double y1 = 0.25; static double y2 = 0.75; static double f = 0.1; ImGui::SetNextWindowSize(ImGui::GetIO().DisplaySize); ImGui::SetNextWindowPos(ImVec2()); ImGui::Begin("AAA", nullptr, ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoResize); ImVec2 graphWindowSize = ImGui::GetContentRegionAvail();// ImGui::GetWindowSize(); constexpr size_t GraphAmount = 15; ImVec2 oneGraphSize = ImVec2(-1, graphWindowSize.y / GraphAmount); if (oneGraphSize.y < 150.f) { oneGraphSize.y = 150.f; }

static ImPlotDragToolFlags flags = ImPlotDragToolFlags_None;
ImGui::BeginChild("GraphWindow", graphWindowSize, false);
for (size_t i = 0; i < GraphAmount; ++i) {
    std::string s = "##lines" + std::to_string(i);
    if (ImPlot::BeginPlot(s.c_str(), oneGraphSize)) {
        ImPlot::SetupAxesLimits(0, 1, 0, 1, ImPlotCond_Always);
        static bool b = false;
        if (b && ImPlot::IsPlotHovered() && ImGui::GetIO().KeyMods == ImGuiKeyModFlags_Ctrl) {
            if (ImGui::IsMouseClicked(ImGuiMouseButton_Left)) {
                oneGraphSize.y = oneGraphSize.y;
            }
        }
        if (ImGui::IsMouseClicked(ImGuiMouseButton_Right)) {
            b = !b;
        }

        ImPlot::DragLineX(0, &x1, ImVec4(1, 1, 1, 1), 1, flags);
        ImPlot::DragLineX(1, &x2, ImVec4(1, 1, 1, 1), 1, flags);

        ImPlot::DragLineY(2, &y1, ImVec4(1, 1, 1, 1), 1, flags);
        ImPlot::DragLineY(3, &y2, ImVec4(1, 1, 1, 1), 1, flags);
        double xs[1000], ys[1000];
        for (int i = 0; i < 1000; ++i) {
            xs[i] = (x2 + x1) / 2 + fabs(x2 - x1) * (i / 1000.0f - 0.5f);
            ys[i] = (y1 + y2) / 2 + fabs(y2 - y1) / 2 * sin(f * i / 10);
        }
        ImPlot::PlotLine("Interactive Data", xs, ys, 1000);
        ImPlot::DragLineY(120482, &f, ImVec4(1, 0.5f, 1, 1), 1, flags);
        ImPlot::EndPlot();
    }
}
ImGui::EndChild();
ImGui::End();

}`

MichaelKv commented 2 years ago

Hello again. Are there any plans to fix this and at least this https://github.com/epezent/implot/issues/306 issues? They do not allow to let the software out. It is a kind of usable for in-house purposes but not for a production. We just need to make a decision. Thanks.