From 654a6ac93513c3cc1ef97cacd782ff674c6f4559 Mon Sep 17 00:00:00 2001 From: Alexandre Marie Date: Tue, 9 Jul 2019 10:20:20 +0200 Subject: New upstream version 0.11.0+dfsg --- silx/gui/plot/ScatterView.py | 74 ++++++++++++++++++++++++++------------------ 1 file changed, 44 insertions(+), 30 deletions(-) (limited to 'silx/gui/plot/ScatterView.py') diff --git a/silx/gui/plot/ScatterView.py b/silx/gui/plot/ScatterView.py index 5fc66ef..1d015d4 100644 --- a/silx/gui/plot/ScatterView.py +++ b/silx/gui/plot/ScatterView.py @@ -47,6 +47,8 @@ from .ScatterMaskToolsWidget import ScatterMaskToolsWidget from ..widgets.BoxLayoutDockWidget import BoxLayoutDockWidget from .. import qt, icons +from ...utils.proxy import docstring +from ...utils.weakref import WeakMethodProxy _logger = logging.getLogger(__name__) @@ -92,10 +94,10 @@ class ScatterView(qt.QMainWindow): self.__pickingCache = None self._positionInfo = tools.PositionInfo( plot=plot, - converters=(('X', lambda x, y: x), - ('Y', lambda x, y: y), - ('Data', lambda x, y: self._getScatterValue(x, y)), - ('Index', lambda x, y: self._getScatterIndex(x, y)))) + converters=(('X', WeakMethodProxy(self._getPickedX)), + ('Y', WeakMethodProxy(self._getPickedY)), + ('Data', WeakMethodProxy(self._getPickedValue)), + ('Index', WeakMethodProxy(self._getPickedIndex)))) # Combine plot, position info and colorbar into central widget gridLayout = qt.QGridLayout() @@ -167,32 +169,52 @@ class ScatterView(qt.QMainWindow): dataIndex = indices[-1] self.__pickingCache = ( dataIndex, + item.getXData(copy=False)[dataIndex], + item.getYData(copy=False)[dataIndex], item.getValueData(copy=False)[dataIndex]) break return self.__pickingCache - def _getScatterValue(self, x, y): - """Get data value of top most scatter plot at position (x, y) + def _getPickedIndex(self, x, y): + """Get data index of top most scatter plot at position (x, y) :param float x: X position in plot coordinates :param float y: Y position in plot coordinates - :return: The data value at that point or '-' + :return: The data index at that point or '-' """ picking = self._pickScatterData(x, y) - return '-' if picking is None else picking[1] + return '-' if picking is None else picking[0] - def _getScatterIndex(self, x, y): - """Get data index of top most scatter plot at position (x, y) + def _getPickedX(self, x, y): + """Returns X position snapped to scatter plot when close enough + + :param float x: + :param float y: + :rtype: float + """ + picking = self._pickScatterData(x, y) + return x if picking is None else picking[1] + + def _getPickedY(self, x, y): + """Returns Y position snapped to scatter plot when close enough + + :param float x: + :param float y: + :rtype: float + """ + picking = self._pickScatterData(x, y) + return y if picking is None else picking[2] + + def _getPickedValue(self, x, y): + """Get data value of top most scatter plot at position (x, y) :param float x: X position in plot coordinates :param float y: Y position in plot coordinates - :return: The data index at that point or '-' + :return: The data value at that point or '-' """ picking = self._pickScatterData(x, y) - return '-' if picking is None else picking[0] - - _PICK_OFFSET = 3 # Offset in pixel used for picking + return '-' if picking is None else picking[3] def _mouseInPlotArea(self, x, y): """Clip mouse coordinates to plot area coordinates @@ -307,11 +329,10 @@ class ScatterView(qt.QMainWindow): self.getScatterItem().setData( x=x, y=y, value=value, xerror=xerror, yerror=yerror, alpha=alpha, copy=copy) + @docstring(items.Scatter) def getData(self, *args, **kwargs): return self.getScatterItem().getData(*args, **kwargs) - getData.__doc__ = items.Scatter.getData.__doc__ - def getScatterItem(self): """Returns the plot item displaying the scatter data. @@ -329,37 +350,30 @@ class ScatterView(qt.QMainWindow): # Convenient proxies + @docstring(PlotWidget) def getXAxis(self, *args, **kwargs): return self.getPlotWidget().getXAxis(*args, **kwargs) - getXAxis.__doc__ = PlotWidget.getXAxis.__doc__ - + @docstring(PlotWidget) def getYAxis(self, *args, **kwargs): return self.getPlotWidget().getYAxis(*args, **kwargs) - getYAxis.__doc__ = PlotWidget.getYAxis.__doc__ - + @docstring(PlotWidget) def setGraphTitle(self, *args, **kwargs): return self.getPlotWidget().setGraphTitle(*args, **kwargs) - setGraphTitle.__doc__ = PlotWidget.setGraphTitle.__doc__ - + @docstring(PlotWidget) def getGraphTitle(self, *args, **kwargs): return self.getPlotWidget().getGraphTitle(*args, **kwargs) - getGraphTitle.__doc__ = PlotWidget.getGraphTitle.__doc__ - + @docstring(PlotWidget) def resetZoom(self, *args, **kwargs): return self.getPlotWidget().resetZoom(*args, **kwargs) - resetZoom.__doc__ = PlotWidget.resetZoom.__doc__ - + @docstring(ScatterMaskToolsWidget) def getSelectionMask(self, *args, **kwargs): return self.getMaskToolsWidget().getSelectionMask(*args, **kwargs) - getSelectionMask.__doc__ = ScatterMaskToolsWidget.getSelectionMask.__doc__ - + @docstring(ScatterMaskToolsWidget) def setSelectionMask(self, *args, **kwargs): return self.getMaskToolsWidget().setSelectionMask(*args, **kwargs) - - setSelectionMask.__doc__ = ScatterMaskToolsWidget.setSelectionMask.__doc__ -- cgit v1.2.3