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

Right-clicking legend does not pop up button #2409

Open
iamdongge opened this issue Nov 2, 2024 · 7 comments
Open

Right-clicking legend does not pop up button #2409

iamdongge opened this issue Nov 2, 2024 · 7 comments
Labels
state: pending not addressed yet type: bug bug

Comments

@iamdongge
Copy link

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 iamdongge added state: pending not addressed yet type: bug bug labels Nov 2, 2024
@nvglucifer
Copy link
Contributor

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()

@iamdongge
Copy link
Author

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.

@nvglucifer
Copy link
Contributor

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
Copy link
Contributor

ImPlot::GetInputMap().OverrideMod = IO.KeyMods;
// Note: this will lock the setup and might therefore skip changes
// to the legend, drag points, and lines in this frame. Nothing we
// can do about that, really.
ImPlot::CancelPlotSelection();
// We've updated the list, let's report this
query_dirty = true;
}
// legend, drag point and lines
for (auto& child : item.childslots[0]) // Using "ImPlot::GetPlotPos()" here trigger an assert
child->draw(drawlist, context->CurrentPlot->PlotRect.Min.x, context->CurrentPlot->PlotRect.Min.y);

@nvglucifer
Copy link
Contributor

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
Copy link
Contributor

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).

@iamdongge
Copy link
Author

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
state: pending not addressed yet type: bug bug
Projects
None yet
Development

No branches or pull requests

2 participants