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()
Version of Dear PyGui
Version: 1.11.2 Operating System: Windows 10
My Issue/Question
dpg.show_item()
anddpg.hide_item()
can dynamically show and hide the legend on a regular plot, but do not work on the legend withindpg.subplots
(the one belonging todpg.subplots
itself).This is caused by
static_cast
inDearPyGui::set_configuration
formvPlotLegendConfig
. I bet it was supposed to bedynamic_cast
. Currently, theif
can't ever enter themvSubPlots
branch.Moreover, if
plot_legend
is added directly todpg.stage
, thatstatic_cast
will lead to memory corruption as the code tries to modify bytes beyond themvStage
object. I couldn't get it crash but it's pure luck.To Reproduce
Steps to reproduce the behavior:
Call
dpg.show_item()
ordpg.hide_item()
on aplot_legend
withindpg.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