DearPyGui icon indicating copy to clipboard operation
DearPyGui copied to clipboard

Hiding a dragline shows plot series that should remain hidden

Open nkraemer2 opened this issue 8 months ago • 6 comments

Version of Dear PyGui

Version: 2.0.0, clean venv. Python 3.11.7 Operating System: Windows 11

My Issue/Question

Hiding/showing a dragline unexpectedly hides, shows, and changes the color of a line series

To Reproduce

Steps to reproduce the behavior (see video and example code):

  1. Hide plot series via legend
  2. Click "Hide dragline"
  3. Observe hidden plot re-appearing and changing color

Expected behavior

Dragline hides itself. Plot stays hidden

Screenshots/Video

https://github.com/user-attachments/assets/de6318eb-0928-427e-aa63-03ece6572501

Standalone, minimal, complete and verifiable example

import dearpygui.dearpygui as dpg
from math import sin

dpg.create_context()


# creating data
sindatax = []
sindatay = []
for i in range(0, 500):
    sindatax.append(i / 1000)
    sindatay.append(0.5 + 0.5 * sin(50 * i / 1000))


def hide_dl():
    dpg.hide_item("dline1")


def show_dl():
    dpg.show_item("dline1")


with dpg.window(label="Example", width=400, height=500):
    with dpg.plot(label="Drag Lines/Points", height=400, width=-1):
        dpg.add_plot_legend()
        dpg.add_plot_axis(dpg.mvXAxis, label="x")
        dpg.add_plot_axis(dpg.mvYAxis, label="y", tag="y_axis")
        dpg.add_line_series(
            sindatax, sindatay, label="0.5 + 0.5 * sin(x)", parent="y_axis"
        )

        dpg.add_drag_line(tag="dline1", color=[255, 0, 0, 255], default_value=0.2)

    dpg.add_button(label="Hide dragline", callback=hide_dl)
    dpg.add_button(label="Show dragline", callback=show_dl)

dpg.create_viewport(title="Custom Title", width=800, height=600)
dpg.setup_dearpygui()
dpg.show_viewport()
dpg.start_dearpygui()
dpg.destroy_context()

nkraemer2 avatar Apr 18 '25 00:04 nkraemer2

Related to #2409 and #2459 .

It might caused by mvPlotting.cpp line#513 - commit bbd1df6 Image

If you replace it with this line (it was there before): child->draw(drawlist, ImPlot::GetPlotPos().x, ImPlot::GetPlotPos().y);

then build the wheel and pip install it, the issue seems go away.

nvglucifer avatar Apr 23 '25 03:04 nvglucifer

#2387

nvglucifer avatar Apr 24 '25 15:04 nvglucifer

I appreciate the information @nvglucifer, thank you. Do you know if there is any ongoing effort to address this? I'm not confident enough in my knowledge of ImPlot to fix it myself.

nkraemer2 avatar May 01 '25 23:05 nkraemer2

@nkraemer2 I would modify mvPlotting.cpp line#513 to use child->draw(drawlist, ImPlot::GetPlotPos().x, ImPlot::GetPlotPos().y);

And for custom series to not crash, I would remove its section about // Begin a popup for a legend entry. https://github.com/hoffstadt/DearPyGui/blob/master/src/mvPlotting.cpp#L2354-L2369

so,

  • I won't rely on legend popup (only for custom series).
  • python - I can check some mouse event on custom_series's callback.

@SamuMazzi, @v-ein, what do you think ?

nvglucifer avatar May 02 '25 05:05 nvglucifer

My bad for not using "Copy permalink" in previous comment. https://github.com/hoffstadt/DearPyGui/blob/d3577817fa69d6b5a8b56fde023b0200c0ff83ef/src/mvPlotting.cpp#L2354-L2369

nvglucifer avatar May 02 '25 06:05 nvglucifer

Well, the comment in the current version states that GetPlotPos triggers an assert. I can't test it right now but it might be that it triggers an assert in some cases, and while it works fine for you, it might break in some other scenarios. One needs to be cautious with changes like that.

To reliably fix it, one needs to go back to ImPlot documentation (or comments or implementation, whatever) and see how to do this drawing call properly.

Regarding the legend entry for a custom series, I haven't decided yet how to deal with it. Like I said in another ticket, there are multiple issues here that can and need to be solved separately; also, we can probably support legend popup for custom series that have tooltip=False. Something to think over.

v-ein avatar May 02 '25 14:05 v-ein