hoffstadt / DearPyGui

Dear PyGui: A fast and powerful Graphical User Interface Toolkit for Python with minimal dependencies
https://dearpygui.readthedocs.io/en/latest/
MIT License
12.62k stars 669 forks source link

dpg.hide() on plot_axis also hides the legend #2319

Open v-ein opened 2 months ago

v-ein commented 2 months ago

Version of Dear PyGui

Version: 1.11.2 Operating System: Windows 10

My Issue/Question

Basically what the title says. It's not clear why should axis visibility affect legend visibility. Looking at the code, I suspect it was a copy-paste mistake: DearPyGui::set_configuration for mvPlotAxisConfig repeats the code from DearPyGui::set_configuration for mvPlotLegendConfig. One more proof of that is that DearPyGui::OnChildAdded for mvPlotAxis does not update the legend visibility, whereas it does so when mvPlotLegend gets added.

To Reproduce

Steps to reproduce the behavior:

Call dpg.hide() on one of plot axes.

Expected behavior

Axis visibility should not affect the legend in any way.

Screenshots/Video

image Where is my "visible" legend? :)

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=500)

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 X axis", callback=lambda: dpg.show_item("x-axis"))
        dpg.add_button(label="Hide X axis", callback=lambda: dpg.hide_item("x-axis"))
        dpg.add_button(label="Have fun", callback=lambda: print(f"Is 'plot-legend' visible? {dpg.is_item_shown('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", tag="x-axis")
        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()