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

Show/hide doesn't work on the legend in dpg.subplots #2318

Open
v-ein opened this issue Apr 8, 2024 · 0 comments
Open

Show/hide doesn't work on the legend in dpg.subplots #2318

v-ein opened this issue Apr 8, 2024 · 0 comments
Labels
state: pending not addressed yet type: bug bug

Comments

@v-ein
Copy link
Contributor

v-ein commented Apr 8, 2024

Version of Dear PyGui

Version: 1.11.2
Operating System: Windows 10

My Issue/Question

dpg.show_item() and dpg.hide_item() can dynamically show and hide the legend on a regular plot, but do not work on the legend within dpg.subplots (the one belonging to dpg.subplots itself).

This is caused by static_cast in DearPyGui::set_configuration for mvPlotLegendConfig. I bet it was supposed to be dynamic_cast. Currently, the if can't ever enter the mvSubPlots branch.

Moreover, if plot_legend is added directly to dpg.stage, that static_cast will lead to memory corruption as the code tries to modify bytes beyond the mvStage object. I couldn't get it crash but it's pure luck.

To Reproduce

Steps to reproduce the behavior:

Call dpg.show_item() or dpg.hide_item() on a plot_legend within dpg.subplots, and see if it works. Alternatively, run the below example and click the show/hide buttons.

Expected behavior

Show/hide should work for both plot legend and subplots legend.

Screenshots/Video

None.

Standalone, minimal, complete and verifiable example

#!/usr/local/bin/python3

from math import sin
import dearpygui.dearpygui as dpg

dpg.create_context()
dpg.create_viewport(title="Test", width=500, height=750)

with dpg.window() as wnd:
    dpg.set_primary_window(dpg.last_item(), True)

    x_data = [x/10 for x in range(0, 200)]
    y_data = [sin(x) for x in x_data]

    with dpg.group(horizontal=True):
        dpg.add_button(label="Show subplots legend", callback=lambda: dpg.show_item("subplots-legend"))
        dpg.add_button(label="Hide subplots legend", callback=lambda: dpg.hide_item("subplots-legend"))

    with dpg.subplots(2, 2, label="Subplots", width=-1, height=300):
        dpg.add_plot_legend(tag="subplots-legend")
        for i in range(4):
            with dpg.plot(no_title=True):
                dpg.add_plot_axis(dpg.mvXAxis, label="", no_tick_labels=True)
                with dpg.plot_axis(dpg.mvYAxis, label="", no_tick_labels=True):
                    dpg.add_line_series(x_data, y_data, label=f"Series {i}")

    dpg.add_spacer(height=20)

    with dpg.group(horizontal=True):
        dpg.add_button(label="Show plot legend", callback=lambda: dpg.show_item("plot-legend"))
        dpg.add_button(label="Hide plot legend", callback=lambda: dpg.hide_item("plot-legend"))

    with dpg.plot(label="Regular plot", width=-1, height=-1):
        dpg.add_plot_legend(tag="plot-legend")
        x_axis = dpg.add_plot_axis(dpg.mvXAxis, label="x")
        with dpg.plot_axis(dpg.mvYAxis, label="y") as y_axis:
            dpg.add_line_series(x_data, y_data, label="Line series")

dpg.setup_dearpygui()
dpg.show_viewport()
dpg.start_dearpygui()
dpg.destroy_context()
@v-ein v-ein added state: pending not addressed yet type: bug bug labels Apr 8, 2024
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

1 participant