Skip to content

Commit

Permalink
Merge pull request #2266 from SasView/2215-plot-legend-enabledisable-…
Browse files Browse the repository at this point in the history
…does-not-persist

Add persistent legend visibility toggle
  • Loading branch information
butlerpd authored Oct 25, 2022
2 parents 06ea4a8 + c72bbc2 commit 5609ff0
Showing 1 changed file with 7 additions and 4 deletions.
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

0 comments on commit 5609ff0

Please sign in to comment.