DearPyGui icon indicating copy to clipboard operation
DearPyGui copied to clipboard

Right-clicking legend does not pop up button

Open iamdongge opened this issue 1 year ago • 7 comments

Version of Dear PyGui

Version: 2.0.0 Operating System: Windows 11

My Issue/Question

After adding the dpg.add_drag_line(), right-clicking legend does not pop up button.

To Reproduce

# Here's some code anyone can copy and paste to reproduce your issue
import dearpygui.dearpygui as dpg
from math import sin

dpg.create_context()

sindatax = []
sindatay = []
for i in range(0, 100):
    sindatax.append(i / 100)
    sindatay.append(0.5 + 0.5 * sin(50 * i / 100))

with dpg.window(label="Tutorial", width=400, height=400):
    # create plot
    dpg.add_text("Right click a series in the legend!")
    with dpg.plot(label="Line Series", height=-1, width=-1):
        dpg.add_plot_legend()
        dpg.add_drag_line()     #  Here is problem

        dpg.add_plot_axis(dpg.mvXAxis, label="x")
        dpg.add_plot_axis(dpg.mvYAxis, label="y", tag="yaxis")

        # series 1
        dpg.add_line_series(sindatax, sindatay, label="series 1", parent="yaxis", tag="series_1")
        dpg.add_button(label="Delete Series 1", parent=dpg.last_item(), callback=lambda: dpg.delete_item("series_1"))

        # series 2
        dpg.add_line_series(sindatax, sindatay, label="series 2", parent="yaxis", tag="series_2")
        dpg.add_button(label="Delete Series 2", parent=dpg.last_item(), callback=lambda: dpg.delete_item("series_2"))

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

iamdongge avatar Nov 02 '24 00:11 iamdongge

drag_line is added to the plot. It's not like series added to the y axis. So, drag_line might need to be show/hide using an item's callback.

import dearpygui.dearpygui as dpg
from math import sin

dpg.create_context()

sindatax = []
sindatay = []
for i in range(0, 100):
    sindatax.append(i / 100)
    sindatay.append(0.5 + 0.5 * sin(50 * i / 100))

def toggle_drag_line_cb(sender, app_data, user_data):
    dpg.configure_item(drag_line, show=app_data)  # app_data in this case is checkbox's value
    # dpg.show_item
    # dpg.hide_item

with dpg.window(label="Tutorial", width=400, height=400):
    dpg.add_checkbox(label="toggle drag_line", callback=lambda s, a, u: toggle_drag_line_cb(s, a, u))
    with dpg.plot(label="Line Series", height=-1, width=-1):
        dpg.add_plot_legend()
        drag_line = dpg.add_drag_line()     #  drag_line is added to plot, not like series

        dpg.add_plot_axis(dpg.mvXAxis, label="x")
        dpg.add_plot_axis(dpg.mvYAxis, label="y", tag="yaxis")

        dpg.add_line_series(sindatax, sindatay, label="series 1", parent="yaxis", tag="series_1")
        dpg.add_line_series(sindatax, sindatay, label="series 2", parent="yaxis", tag="series_2")

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

nvglucifer avatar Nov 24 '24 15:11 nvglucifer

drag_line is added to the plot. It's not like series added to the y axis. So, drag_line might need to be show/hide using an item's callback.

import dearpygui.dearpygui as dpg
from math import sin

dpg.create_context()

sindatax = []
sindatay = []
for i in range(0, 100):
    sindatax.append(i / 100)
    sindatay.append(0.5 + 0.5 * sin(50 * i / 100))

def toggle_drag_line_cb(sender, app_data, user_data):
    dpg.configure_item(drag_line, show=app_data)  # app_data in this case is checkbox's value
    # dpg.show_item
    # dpg.hide_item

with dpg.window(label="Tutorial", width=400, height=400):
    dpg.add_checkbox(label="toggle drag_line", callback=lambda s, a, u: toggle_drag_line_cb(s, a, u))
    with dpg.plot(label="Line Series", height=-1, width=-1):
        dpg.add_plot_legend()
        drag_line = dpg.add_drag_line()     #  drag_line is added to plot, not like series

        dpg.add_plot_axis(dpg.mvXAxis, label="x")
        dpg.add_plot_axis(dpg.mvYAxis, label="y", tag="yaxis")

        dpg.add_line_series(sindatax, sindatay, label="series 1", parent="yaxis", tag="series_1")
        dpg.add_line_series(sindatax, sindatay, label="series 2", parent="yaxis", tag="series_2")

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

Thank you but my question is actually about "Delete Series 1"button. My code, without dpg.add_drag_line() the "Delete Series 1"button can be popup by right-clicking legend, but adding dpg.add_drag_line() and right-clicking will not work.

iamdongge avatar Nov 26 '24 16:11 iamdongge

Ah, it's really that drag_line disturbs the showing of buttons.

I've tested that DPG 1.11.1 showing fine, but not DPG2.0. I will investigate and report the different here, not sure I can modify the underlying code though.

nvglucifer avatar Nov 27 '24 01:11 nvglucifer

https://github.com/hoffstadt/DearPyGui/blob/65c26203a7c474635c1cb403daf1a4c66109ffa5/src/mvPlotting.cpp#L502-L513

nvglucifer avatar Nov 27 '24 03:11 nvglucifer

Temporary workaround for DPG 2.0 is toggle hide all drag items like using checkbox's callback above (after that you can right click legend to show buttons).

# Here's some code anyone can copy and paste to reproduce your issue
import dearpygui.dearpygui as dpg
from math import sin

dpg.create_context()
dpg.show_item_registry()

sindatax = []
sindatay = []
for i in range(0, 100):
    sindatax.append(i / 100)
    sindatay.append(0.5 + 0.5 * sin(50 * i / 100))

with dpg.window(label="Tutorial", width=400, height=400):
    # create plot
    dpg.add_text("Right click a series in the legend!")
    dpg.add_checkbox(label="toggle drag items", callback=lambda s, a, u: [
            dpg.configure_item(a_drag_line, show=a), dpg.configure_item(a_drag_point, show=a)
        ]
    )
    with dpg.plot(label="Line Series", height=-1, width=-1) as plot_1:
        dpg.add_plot_legend()

        # show=True >> buttons won't show
        a_drag_line = dpg.add_drag_line(parent=plot_1, show=True)
        a_drag_point = dpg.add_drag_point()
        # custom_series ?

        dpg.add_plot_axis(dpg.mvXAxis, label="x")
        dpg.add_plot_axis(dpg.mvYAxis, label="y", tag="yaxis")

        # series 1
        dpg.add_line_series(sindatax, sindatay, label="series 1", parent="yaxis", tag="series_1")
        btn_1 = dpg.add_button(label="Delete Series 1", parent=dpg.last_item(), callback=lambda: dpg.delete_item("series_1"))

        # series 2
        dpg.add_line_series(sindatax, sindatay, label="series 2", parent="yaxis", tag="series_2")
        dpg.add_button(label="Delete Series 2", parent=dpg.last_item(), callback=lambda: dpg.delete_item("series_2"))

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

nvglucifer avatar Nov 27 '24 04:11 nvglucifer

Likely that DPG 2.0 duplicate series items for each drag item - different hide/show each combination. (color map change when check the checkbox).

2 series + 2 drag item can result in: 4 or 6 series, (only 2 in that 4 or 6 get to show 2 buttons).

nvglucifer avatar Nov 27 '24 04:11 nvglucifer

Likely that DPG 2.0 duplicate series items for each drag item - different hide/show each combination. (color map change when check the checkbox).

2 series + 2 drag item can result in: 4 or 6 series, (only 2 in that 4 or 6 get to show 2 buttons).

Thank you very much for your job!

iamdongge avatar Nov 30 '24 00:11 iamdongge