Introduced an if statement that checks a boolean flag on whether the legend is supposed to be shown or not.
Edited the unit test of the changed function to include testing of both options, i.e. when legend is not shown and when legend is shown
Description of Work
Finding the problem
When the legends box is clicked, a _toggle_legend function is activated which sets the boolean attribute _legends_shown to its opposite
The attribute _legends_shown of CutPlot is thus supposed to control whether or not the legend is visible in the plot.
The update_legend function does not make use of the attribute _legends_shown in its scope, which leads to legends being shown even when _legends_shown is set to False.
This behaviour is present in 3 scenarios on cut viewer, as all these instances call the function update_legend:
When Waterfall is clicked
When the Intensity is changed
When any line in the plot is clicked
Fixing the problem
Introduced an if statement inside update_legend
Same if statement is used in the analogous slice viewer
Edited unit test
Introduced the new scenario of making sure axes.legend() is not called when _legends_shown is set to False.
To test
Open cut viewer in mslice and run over the 3 scenarios that were previously making the legend visible:
Click Legend so legends become invisible
Click Waterfall and check legends remain invisible
Click any plot line > cancel, and check legends remain invisible
Click Intensity > any intensity that works, and check legends remain invisible
Comment out if`` statement and run testcut_plot_test.py. It should fail the testtest_update_legend. Restoreif` statement and check the test passes.
Summary of changes
Description of Work
Finding the problem
_toggle_legend
function is activated which sets the boolean attribute_legends_shown
to its opposite_legends_shown
ofCutPlot
is thus supposed to control whether or not the legend is visible in the plot.update_legend
function does not make use of the attribute_legends_shown
in its scope, which leads to legends being shown even when_legends_shown
is set to False.update_legend
:Fixing the problem
if
statement insideupdate_legend
if
statement is used in the analogous slice viewerEdited unit test
axes.legend()
is not called when_legends_shown
is set toFalse
.To test
Open cut viewer in mslice and run over the 3 scenarios that were previously making the legend visible:
Comment out
if`` statement and run test
cut_plot_test.py. It should fail the test
test_update_legend. Restore
if` statement and check the test passes.Fixes #863 .