diff options
Diffstat (limited to 'silx/gui/plot/PlotInteraction.py')
-rw-r--r-- | silx/gui/plot/PlotInteraction.py | 79 |
1 files changed, 21 insertions, 58 deletions
diff --git a/silx/gui/plot/PlotInteraction.py b/silx/gui/plot/PlotInteraction.py index fbc9c1f..865073b 100644 --- a/silx/gui/plot/PlotInteraction.py +++ b/silx/gui/plot/PlotInteraction.py @@ -26,7 +26,7 @@ __authors__ = ["T. Vincent"] __license__ = "MIT" -__date__ = "24/01/2017" +__date__ = "27/06/2017" import math @@ -153,11 +153,11 @@ class Pan(_ZoomOnWheel): xData, yData, y2Data = self._pixelToData(x, y) lastX, lastY, lastY2 = self._previousDataPos - xMin, xMax = self.plot.getGraphXLimits() - yMin, yMax = self.plot.getGraphYLimits(axis='left') - y2Min, y2Max = self.plot.getGraphYLimits(axis='right') + xMin, xMax = self.plot.getXAxis().getLimits() + yMin, yMax = self.plot.getYAxis().getLimits() + y2Min, y2Max = self.plot.getYAxis(axis='right').getLimits() - if self.plot.isXAxisLogarithmic(): + if self.plot.getXAxis()._isLogarithmic(): try: dx = math.log10(xData) - math.log10(lastX) newXMin = pow(10., (math.log10(xMin) - dx)) @@ -176,7 +176,7 @@ class Pan(_ZoomOnWheel): if newXMin < FLOAT32_SAFE_MIN or newXMax > FLOAT32_SAFE_MAX: newXMin, newXMax = xMin, xMax - if self.plot.isYAxisLogarithmic(): + if self.plot.getYAxis()._isLogarithmic(): try: dy = math.log10(yData) - math.log10(lastY) newYMin = pow(10., math.log10(yMin) - dy) @@ -233,10 +233,10 @@ class Zoom(_ZoomOnWheel): def __init__(self, plot, color): self.color = color - self.zoomStack = [] self._lastClick = 0., None super(Zoom, self).__init__(plot) + self.plot.getLimitsHistory().clear() def _areaWithAspectRatio(self, x0, y0, x1, y1): _plotLeft, _plotTop, plotW, plotH = self.plot.getPlotBoundsInPixels() @@ -286,25 +286,14 @@ class Zoom(_ZoomOnWheel): self._lastClick = time.time(), (dataPos[0], dataPos[1], x, y) - # Zoom-in centered on mouse cursor - # xMin, xMax = self.plot.getGraphXLimits() - # yMin, yMax = self.plot.getGraphYLimits() - # y2Min, y2Max = self.plot.getGraphYLimits(axis="right") - # self.zoomStack.append((xMin, xMax, yMin, yMax, y2Min, y2Max)) - # self._zoom(x, y, 2) elif btn == RIGHT_BTN: - try: - xMin, xMax, yMin, yMax, y2Min, y2Max = self.zoomStack.pop() - except IndexError: - # Signal mouse clicked event - dataPos = self.plot.pixelToData(x, y) - assert dataPos is not None - eventDict = prepareMouseSignal('mouseClicked', 'right', - dataPos[0], dataPos[1], - x, y) - self.plot.notify(**eventDict) - else: - self.plot.setLimits(xMin, xMax, yMin, yMax, y2Min, y2Max) + # Signal mouse clicked event + dataPos = self.plot.pixelToData(x, y) + assert dataPos is not None + eventDict = prepareMouseSignal('mouseClicked', 'right', + dataPos[0], dataPos[1], + x, y) + self.plot.notify(**eventDict) def beginDrag(self, x, y): dataPos = self.plot.pixelToData(x, y) @@ -354,10 +343,7 @@ class Zoom(_ZoomOnWheel): if x0 != x1 or y0 != y1: # Avoid empty zoom area # Store current zoom state in stack - xMin, xMax = self.plot.getGraphXLimits() - yMin, yMax = self.plot.getGraphYLimits() - y2Min, y2Max = self.plot.getGraphYLimits(axis="right") - self.zoomStack.append((xMin, xMax, yMin, yMax, y2Min, y2Max)) + self.plot.getLimitsHistory().push() if self.plot.isKeepDataAspectRatio(): x0, y0, x1, y1 = self._areaWithAspectRatio(x0, y0, x1, y1) @@ -510,33 +496,6 @@ class SelectPolygon(Select): self.points[-1] = dataPos return True - - elif btn == RIGHT_BTN: - self.machine.resetSelectionArea() - - firstPos = self.machine.plot.dataToPixel(*self._firstPos, - check=False) - dx, dy = abs(firstPos[0] - x), abs(firstPos[1] - y) - - if (dx < self.machine.DRAG_THRESHOLD_DIST and - dy < self.machine.DRAG_THRESHOLD_DIST): - self.points[-1] = self.points[0] - else: - dataPos = self.machine.plot.pixelToData(x, y) - assert dataPos is not None - self.points[-1] = dataPos - if self.points[-2] == self.points[-1]: - self.points.pop() - self.points.append(self.points[0]) - - eventDict = prepareDrawingSignal('drawingFinished', - 'polygon', - self.points, - self.machine.parameters) - self.machine.plot.notify(**eventDict) - self.goto('idle') - return False - return False def onMove(self, x, y): @@ -1100,14 +1059,19 @@ class ItemsInteraction(ClickOrDrag, _PlotInteraction): elif picked[0] == 'curve': curve = picked[1] + indices = picked[2] dataPos = self.plot.pixelToData(x, y) assert dataPos is not None + xData = curve.getXData(copy=False) + yData = curve.getYData(copy=False) + eventDict = prepareCurveSignal('left', curve.getLegend(), 'curve', - picked[2], picked[3], + xData[indices], + yData[indices], dataPos[0], dataPos[1], x, y) return eventDict @@ -1123,7 +1087,6 @@ class ItemsInteraction(ClickOrDrag, _PlotInteraction): scale = image.getScale() column = int((dataPos[0] - origin[0]) / float(scale[0])) row = int((dataPos[1] - origin[1]) / float(scale[1])) - eventDict = prepareImageSignal('left', image.getLegend(), 'image', |