Skip to content
Snippets Groups Projects
Commit 7eb7da2e authored by mantid-builder's avatar mantid-builder
Browse files

Merge remote-tracking branch 'origin/release-next'

parents 0c30fcfc 15251014
No related branches found
No related tags found
No related merge requests found
...@@ -299,11 +299,6 @@ class FigureInteraction(object): ...@@ -299,11 +299,6 @@ class FigureInteraction(object):
self._add_normalization_option_menu(menu, event.inaxes) self._add_normalization_option_menu(menu, event.inaxes)
self.add_error_bars_menu(menu, event.inaxes) self.add_error_bars_menu(menu, event.inaxes)
self._add_marker_option_menu(menu, event) self._add_marker_option_menu(menu, event)
# Able to change the plot type to waterfall if there is only one axes, it is a MantidAxes, and there is more
# than one line on the axes.
if len(event.inaxes.get_figure().get_axes()) == 1 and isinstance(event.inaxes, MantidAxes)\
and len(event.inaxes.get_lines()) > 1:
self._add_plot_type_option_menu(menu, event.inaxes) self._add_plot_type_option_menu(menu, event.inaxes)
menu.exec_(QCursor.pos()) menu.exec_(QCursor.pos())
...@@ -441,6 +436,18 @@ class FigureInteraction(object): ...@@ -441,6 +436,18 @@ class FigureInteraction(object):
menu.addMenu(marker_menu) menu.addMenu(marker_menu)
def _add_plot_type_option_menu(self, menu, ax): def _add_plot_type_option_menu(self, menu, ax):
# Error bar caps are considered lines so they are removed before checking the number of lines on the axes so
# they aren't confused for "actual" lines.
error_bar_caps = datafunctions.remove_and_return_errorbar_cap_lines(ax)
# Able to change the plot type to waterfall if there is only one axes, it is a MantidAxes, and there is more
# than one line on the axes.
if len(ax.get_figure().get_axes()) > 1 or not isinstance(ax, MantidAxes) or len(ax.get_lines()) <= 1:
return
# Re-add error bar caps
ax.lines += error_bar_caps
plot_type_menu = QMenu("Plot Type", menu) plot_type_menu = QMenu("Plot Type", menu)
plot_type_action_group = QActionGroup(plot_type_menu) plot_type_action_group = QActionGroup(plot_type_menu)
standard = plot_type_menu.addAction("1D", lambda: self._change_plot_type( standard = plot_type_menu.addAction("1D", lambda: self._change_plot_type(
......
...@@ -296,6 +296,35 @@ class FigureInteractionTest(unittest.TestCase): ...@@ -296,6 +296,35 @@ class FigureInteractionTest(unittest.TestCase):
self.assertTrue( self.assertTrue(
any(FigureInteraction.HIDE_ERROR_BARS_BUTTON_TEXT == child.text() for child in added_menu.children())) any(FigureInteraction.HIDE_ERROR_BARS_BUTTON_TEXT == child.text() for child in added_menu.children()))
def test_context_menu_includes_plot_type_if_plot_has_multiple_lines(self):
fig, self.ax = plt.subplots(subplot_kw={'projection': 'mantid'})
self.ax.plot([0, 1], [0, 1])
self.ax.plot([0, 1], [0, 1])
main_menu = QMenu()
# QMenu always seems to have 1 child when empty,
# but just making sure the count as expected at this point in the test
self.assertEqual(1, len(main_menu.children()))
self.interactor._add_plot_type_option_menu(main_menu, self.ax)
added_menu = main_menu.children()[1]
self.assertEqual(added_menu.children()[0].text(), "Plot Type")
def test_context_menu_does_not_include_plot_type_if_plot_has_one_line(self):
fig, self.ax = plt.subplots(subplot_kw={'projection': 'mantid'})
self.ax.errorbar([0, 1], [0, 1], capsize=1)
main_menu = QMenu()
# QMenu always seems to have 1 child when empty,
# but just making sure the count as expected at this point in the test
self.assertEqual(1, len(main_menu.children()))
self.interactor._add_plot_type_option_menu(main_menu, self.ax)
# Number of children should remain unchanged
self.assertEqual(1, len(main_menu.children()))
def test_scripted_plot_show_and_hide_all(self): def test_scripted_plot_show_and_hide_all(self):
self.ax.plot([0, 15000], [0, 15000], label='MyLabel') self.ax.plot([0, 15000], [0, 15000], label='MyLabel')
self.ax.errorbar([0, 15000], [0, 14000], yerr=[10, 10000], label='MyLabel 2') self.ax.errorbar([0, 15000], [0, 14000], yerr=[10, 10000], label='MyLabel 2')
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment