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

Add persistent legend visibility toggle #2266

Merged
merged 2 commits into from
Oct 25, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions src/sas/qtgui/Plotting/Plotter.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ def __init__(self, parent=None, manager=None, quickplot=False):
self.toolbar._actions['pan'].triggered.connect(self._pan)
self.toolbar._actions['zoom'].triggered.connect(self._zoom)

self.legendVisible = True

parent.geometry()

@property
Expand Down Expand Up @@ -258,7 +260,7 @@ def plot(self, data=None, color=None, marker=None, hide_error=False, transform=T
self.legend = ax.legend(loc='upper right', shadow=True)
if self.legend:
self.legend.set_picker(True)

self.legend.set_visible(self.legendVisible)
# Current labels for axes
if self.yLabel and not is_fit:
ax.set_ylabel(self.yLabel)
Expand Down Expand Up @@ -303,7 +305,7 @@ def onResize(self, event):
"""
Resize the legend window/font on canvas resize
"""
if not self.showLegend:
if not self.showLegend or not self.legendVisible:
return
width = _legendResize(event.width, self.parent)
# resize the legend to follow the canvas width.
Expand Down Expand Up @@ -799,8 +801,9 @@ def onToggleLegend(self):
if not self.showLegend:
return

visible = self.legend.get_visible()
self.legend.set_visible(not visible)
#visible = self.legend.get_visible()
self.legendVisible = not self.legendVisible
self.legend.set_visible(self.legendVisible)
self.canvas.draw_idle()

def onCusotmizeLabel(self):
Expand Down