From 07f610950d567decca820509bece93d0687e99df Mon Sep 17 00:00:00 2001 From: lesauxvi Date: Mon, 1 Feb 2016 11:17:36 +0100 Subject: [PATCH] creation of a combined method for handling the label location --- examples/plottingItems.py | 1 + pyqtgraph/graphicsItems/InfiniteLine.py | 42 +++++++------------------ 2 files changed, 12 insertions(+), 31 deletions(-) diff --git a/examples/plottingItems.py b/examples/plottingItems.py index 6323e369..e4cb29bb 100644 --- a/examples/plottingItems.py +++ b/examples/plottingItems.py @@ -21,6 +21,7 @@ inf1 = pg.InfiniteLine(movable=True, angle=90, label=True, textColor=(200,200,10 inf2 = pg.InfiniteLine(movable=True, angle=0, label=True, pen=(0, 0, 200), bounds = [-2, 2], unit="mm", hoverPen=(0,200,0)) inf3 = pg.InfiniteLine(movable=True, angle=45) inf1.setPos([2,2]) +inf1.setTextLocation([0.25, 0.9]) p1.addItem(inf1) p1.addItem(inf2) p1.addItem(inf3) diff --git a/pyqtgraph/graphicsItems/InfiniteLine.py b/pyqtgraph/graphicsItems/InfiniteLine.py index bbd24fd2..00b517cf 100644 --- a/pyqtgraph/graphicsItems/InfiniteLine.py +++ b/pyqtgraph/graphicsItems/InfiniteLine.py @@ -307,13 +307,11 @@ class InfiniteLine(UIGraphicsItem): qpp.addPolygon(self._polygon) return qpp - def paint(self, p, *args): br = self.boundingRect() p.setPen(self.currentPen) p.drawLine(self._p1, self._p2) - def dataBounds(self, axis, frac=1.0, orthoRange=None): if axis == 0: return None ## x axis should never be auto-scaled @@ -397,7 +395,6 @@ class InfiniteLine(UIGraphicsItem): self.text.setText(fmt.format(self.value()), color=self.textColor) self.text.setPos(xpos, self.value()) - def showLabel(self, state): """ Display or not the label indicating the location of the line in data @@ -414,39 +411,22 @@ class InfiniteLine(UIGraphicsItem): self.text.hide() self.update() - def setLocation(self, loc): + def setTextLocation(self, param): """ - Set the location of the textItem with respect to a specific axis. If the - line is vertical, the location is based on the normalized range of the - yaxis. Otherwise, it is based on the normalized range of the xaxis. - + Set the location of the label. param is a list of two values. + param[0] defines the location of the label along the axis and + param[1] defines the shift value (defines the condition where the + label shifts from one side of the line to the other one). + New in version 0.9.11 ============== ============================================== **Arguments:** - loc the normalized location of the textItem. + param list of parameters. ============== ============================================== """ - if loc > 1.: - loc = 1. - if loc < 0.: - loc = 0. - self.location = loc - self.update() - - def setShift(self, shift): - """ - Set the value with respect to the normalized range of the corresponding - axis where the location of the textItem shifts from one side to another. - - ============== ============================================== - **Arguments:** - shift the normalized shift value of the textItem. - ============== ============================================== - """ - if shift > 1.: - shift = 1. - if shift < 0.: - shift = 0. - self.shift = shift + if len(param) != 2: # check that the input data are correct + return + self.location = np.clip(param[0], 0, 1) + self.shift = np.clip(param[1], 0, 1) self.update() def setFormat(self, format):