Skip to content

Commit

Permalink
Merge pull request #38956 from mantidproject/revert_crosshair
Browse files Browse the repository at this point in the history
Revert added crosshair option in mantid
  • Loading branch information
jmborr authored Feb 24, 2025
2 parents dee818e + d9e270e commit a8f64cc
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 68 deletions.
1 change: 0 additions & 1 deletion docs/source/release/v6.12.0/mantidworkbench.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ New Features
- ``mantidworkbench`` is now an additional entry point for launching the ``mantidworkbench`` Conda package.
- ``workbench`` and ``mantidworkbench`` Conda entry points now launch workbench with ``jemalloc`` configured as the memory allocator on Linux.
- Surface and contour plots can now be generated more easily for multiple single-spectrum workspaces (via the `Plot Advanced` dialog when multiple single-spectrum workspaces are selected).
- A crosshair tool has been added to plot toolbars.
- Added an `Email mantid-help@mantidproject.org` action to the Help menu.
- The settings dialog now has `Okay`, `Apply` and `Cancel` buttons. Settings are no longer immediately applied when parameters are changed.
- MacOS compiler updated from version 16 to version 18, which should result in performance improvements. See https://releases.llvm.org for release notes.
Expand Down
40 changes: 4 additions & 36 deletions qt/applications/workbench/workbench/plotting/figuremanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,6 @@ def __init__(self, canvas, num):
self.toolbar.sig_waterfall_conversion.connect(self.update_toolbar_waterfall_plot)
self.toolbar.sig_change_line_collection_colour_triggered.connect(self.change_line_collection_colour)
self.toolbar.sig_hide_plot_triggered.connect(self.hide_plot)
self.toolbar.sig_crosshair_toggle_triggered.connect(self.crosshair_toggle)
self.toolbar.setFloatable(False)
tbs_height = self.toolbar.sizeHint().height()
else:
Expand All @@ -252,7 +251,9 @@ def __init__(self, canvas, num):
self.window.addDockWidget(Qt.LeftDockWidgetArea, self.fit_browser)

self.superplot = None

self.fit_browser.hide()

if matplotlib.is_interactive():
self.window.show()
canvas.draw_idle()
Expand All @@ -263,9 +264,11 @@ def notify_axes_change(fig):
self.toolbar.update()

canvas.figure.add_axobserver(notify_axes_change)

# Register canvas observers
self._fig_interaction = FigureInteraction(self)
self._ads_observer = FigureManagerADSObserver(self)

self.window.raise_()

def full_screen_toggle(self):
Expand Down Expand Up @@ -600,41 +603,6 @@ def _reverse_axis_lines(ax):
line.remove()
ax.add_line(line)

def crosshair_toggle(self, on):
cid = self.canvas.mpl_connect("motion_notify_event", self.crosshair)
if not on:
self.canvas.mpl_disconnect(cid)

def crosshair(self, event):
axes = self.canvas.figure.gca()

# create a crosshair made from horizontal and verticle lines.
self.horizontal_line = axes.axhline(color="r", lw=1.0, ls="-")
self.vertical_line = axes.axvline(color="r", lw=1.0, ls="-")

def set_cross_hair_visible(visible):
need_redraw = self.horizontal_line.get_visible() != visible
self.horizontal_line.set_visible(visible)
self.vertical_line.set_visible(visible)
return need_redraw

# if event is out-of-bound we update
if not event.inaxes:
need_redraw = set_cross_hair_visible(False)
if need_redraw:
axes.figure.canvas.draw()

else:
set_cross_hair_visible(True)
x, y = event.xdata, event.ydata
self.horizontal_line.set_ydata([y])
self.vertical_line.set_xdata([x])
self.canvas.draw()

# after update we remove
self.horizontal_line.remove()
self.vertical_line.remove()


# -----------------------------------------------------------------------------
# Figure control
Expand Down
22 changes: 0 additions & 22 deletions qt/applications/workbench/workbench/plotting/test/test_toolbar.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,15 +117,6 @@ def test_button_checked_for_plot_with_grid(self, mock_qappthread):
# Grid button should be ON because we enabled the grid.
self.assertTrue(self._is_grid_button_checked(fig))

@patch("workbench.plotting.figuremanager.QAppThreadCall")
def test_button_checked_for_plot_with_no_crosshair(self, mock_qappthread):
mock_qappthread.return_value = mock_qappthread

fig, axes = plt.subplots(subplot_kw={"projection": "mantid"})
axes.plot([-10, 10], [1, 2])
# Grid button should be OFF because we have not enabled the crosshair.
self.assertFalse(self._is_crosshair_button_checked(fig))

@patch("workbench.plotting.figuremanager.QAppThreadCall")
def test_button_checked_for_plot_with_grid_using_kwargs(self, mock_qappthread):
mock_qappthread.return_value = mock_qappthread
Expand Down Expand Up @@ -275,19 +266,6 @@ def _is_button_enabled(cls, fig, button):
fig_manager.toolbar.set_buttons_visibility(fig)
return fig_manager.toolbar._actions[button].isEnabled()

@classmethod
def _is_crosshair_button_checked(cls, fig):
"""
Create the figure manager and check whether its toolbar is toggled on or off for the given figure.
We have to explicitly call set_button_visibility() here, which would otherwise be called within the show()
function.
"""
canvas = MantidFigureCanvas(fig)
fig_manager = FigureManagerWorkbench(canvas, 1)
# This is only called when show() is called on the figure manager, so we have to manually call it here.
fig_manager.toolbar.set_buttons_visibility(fig)
return fig_manager.toolbar._actions["toggle_crosshair"].isChecked()


if __name__ == "__main__":
unittest.main()
9 changes: 0 additions & 9 deletions qt/applications/workbench/workbench/plotting/toolbar.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ def _create_script_action(self, text, tooltip_text, mdi_icon, *args):
class WorkbenchNavigationToolbar(MantidNavigationToolbar):
sig_home_clicked = QtCore.Signal()
sig_grid_toggle_triggered = QtCore.Signal(bool)
sig_crosshair_toggle_triggered = QtCore.Signal(bool)
sig_active_triggered = QtCore.Signal()
sig_hold_triggered = QtCore.Signal()
sig_toggle_fit_triggered = QtCore.Signal()
Expand Down Expand Up @@ -85,7 +84,6 @@ class WorkbenchNavigationToolbar(MantidNavigationToolbar):
MantidNavigationTool("Fill Area", "Fill area under curves", "mdi.format-color-fill", "waterfall_fill_area", None),
MantidStandardNavigationTools.SEPARATOR,
MantidNavigationTool("Help", "Open plotting help documentation", "mdi.help", "launch_plot_help", None),
MantidNavigationTool("Crosshair", "Toggle crosshair", "mdi.plus", "toggle_crosshair", False),
MantidNavigationTool("Hide", "Hide the plot", "mdi.eye", "hide_plot", None),
)

Expand All @@ -96,13 +94,6 @@ def __init__(self, canvas, parent, coordinates=True):
dpi_ratio = QtWidgets.QApplication.instance().desktop().physicalDpiX() / 100
self.setIconSize(QtCore.QSize(int(24 * dpi_ratio), int(24 * dpi_ratio)))

def toggle_crosshair(self, enable=None):
if enable is None:
enable = self._actions["toggle_crosshair"].isChecked()
else:
self._actions["toggle_crosshair"].setChecked(enable)
self.sig_crosshair_toggle_triggered.emit(enable)

def hide_plot(self):
self.sig_hide_plot_triggered.emit()

Expand Down

0 comments on commit a8f64cc

Please sign in to comment.