creation of a combined method for handling the label location

This commit is contained in:
lesauxvi 2016-02-01 11:17:36 +01:00
parent 0d4c78a6be
commit 07f610950d
2 changed files with 12 additions and 31 deletions

View File

@ -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)) 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) inf3 = pg.InfiniteLine(movable=True, angle=45)
inf1.setPos([2,2]) inf1.setPos([2,2])
inf1.setTextLocation([0.25, 0.9])
p1.addItem(inf1) p1.addItem(inf1)
p1.addItem(inf2) p1.addItem(inf2)
p1.addItem(inf3) p1.addItem(inf3)

View File

@ -307,13 +307,11 @@ class InfiniteLine(UIGraphicsItem):
qpp.addPolygon(self._polygon) qpp.addPolygon(self._polygon)
return qpp return qpp
def paint(self, p, *args): def paint(self, p, *args):
br = self.boundingRect() br = self.boundingRect()
p.setPen(self.currentPen) p.setPen(self.currentPen)
p.drawLine(self._p1, self._p2) p.drawLine(self._p1, self._p2)
def dataBounds(self, axis, frac=1.0, orthoRange=None): def dataBounds(self, axis, frac=1.0, orthoRange=None):
if axis == 0: if axis == 0:
return None ## x axis should never be auto-scaled 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.setText(fmt.format(self.value()), color=self.textColor)
self.text.setPos(xpos, self.value()) self.text.setPos(xpos, self.value())
def showLabel(self, state): def showLabel(self, state):
""" """
Display or not the label indicating the location of the line in data Display or not the label indicating the location of the line in data
@ -414,39 +411,22 @@ class InfiniteLine(UIGraphicsItem):
self.text.hide() self.text.hide()
self.update() self.update()
def setLocation(self, loc): def setTextLocation(self, param):
""" """
Set the location of the textItem with respect to a specific axis. If the Set the location of the label. param is a list of two values.
line is vertical, the location is based on the normalized range of the param[0] defines the location of the label along the axis and
yaxis. Otherwise, it is based on the normalized range of the xaxis. 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:** **Arguments:**
loc the normalized location of the textItem. param list of parameters.
============== ============================================== ============== ==============================================
""" """
if loc > 1.: if len(param) != 2: # check that the input data are correct
loc = 1. return
if loc < 0.: self.location = np.clip(param[0], 0, 1)
loc = 0. self.shift = np.clip(param[1], 0, 1)
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
self.update() self.update()
def setFormat(self, format): def setFormat(self, format):