diff options
Diffstat (limited to 'silx/gui/plot/ScatterView.py')
-rw-r--r-- | silx/gui/plot/ScatterView.py | 45 |
1 files changed, 30 insertions, 15 deletions
diff --git a/silx/gui/plot/ScatterView.py b/silx/gui/plot/ScatterView.py index 1d015d4..bdbf3ab 100644 --- a/silx/gui/plot/ScatterView.py +++ b/silx/gui/plot/ScatterView.py @@ -79,7 +79,7 @@ class ScatterView(qt.QMainWindow): self._plot = weakref.ref(plot) # Add an empty scatter - plot.addScatter(x=(), y=(), value=(), legend=self._SCATTER_LEGEND) + self.__createEmptyScatter() # Create colorbar widget with white background self._colorbar = ColorBarWidget(parent=self, plot=plot) @@ -145,6 +145,21 @@ class ScatterView(qt.QMainWindow): for action in toolbar.actions(): self.addAction(action) + + def __createEmptyScatter(self): + """Create an empty scatter item that is used to display the data + + :rtype: ~silx.gui.plot.items.Scatter + """ + plot = self.getPlotWidget() + plot.addScatter(x=(), y=(), value=(), legend=self._SCATTER_LEGEND) + scatter = plot._getItem( + kind='scatter', legend=self._SCATTER_LEGEND) + # Profile is not selectable, + # so it does not interfere with profile interaction + scatter._setSelectable(False) + return scatter + def _pickScatterData(self, x, y): """Get data and index and value of top most scatter plot at position (x, y) @@ -162,17 +177,19 @@ class ScatterView(qt.QMainWindow): pixelPos = plot.dataToPixel(x, y) if pixelPos is not None: # Start from top-most item - for item, indices in reversed(plot._pick(*pixelPos)): - if isinstance(item, items.Scatter): - # Get last index - # with matplotlib it should be the top-most point - dataIndex = indices[-1] - self.__pickingCache = ( - dataIndex, - item.getXData(copy=False)[dataIndex], - item.getYData(copy=False)[dataIndex], - item.getValueData(copy=False)[dataIndex]) - break + result = plot._pickTopMost( + pixelPos[0], pixelPos[1], + lambda item: isinstance(item, items.Scatter)) + if result is not None: + # Get last index + # with matplotlib it should be the top-most point + dataIndex = result.getIndices(copy=False)[-1] + item = result.getItem() + self.__pickingCache = ( + dataIndex, + item.getXData(copy=False)[dataIndex], + item.getYData(copy=False)[dataIndex], + item.getValueData(copy=False)[dataIndex]) return self.__pickingCache @@ -343,9 +360,7 @@ class ScatterView(qt.QMainWindow): plot = self.getPlotWidget() scatter = plot._getItem(kind='scatter', legend=self._SCATTER_LEGEND) if scatter is None: # Resilient to call to PlotWidget API (e.g., clear) - plot.addScatter(x=(), y=(), value=(), legend=self._SCATTER_LEGEND) - scatter = plot._getItem( - kind='scatter', legend=self._SCATTER_LEGEND) + scatter = self.__createEmptyScatter() return scatter # Convenient proxies |