Modifying InfLineLabel

159 views
Skip to first unread message

Csaba Benkó

unread,
Aug 2, 2021, 12:51:48 PM8/2/21
to pyqtgraph
Hey guys,

i'm trying to modify the InfLineLabel class so that its x-position is fixed and its y-position is relative to the viewbox, just like when a normal InflineLabel is attached to a vertical InfiniteLine. If it's parent isn't a InfLine, it behaves like it's attached to a horizontal one, meaning it's locked to the y-position instead to the x and it can be moved along the x-axis instead of the y. I simply cannot find at all where or how the alignment of the line is checked. 

The changes are really rudimentary, but i attached the modified class. I'd really appreciate if someone could help me out. 
MyInfLineLabel.py

JJ

unread,
Aug 6, 2021, 8:00:12 AM8/6/21
to pyqtgraph
In __init__:

 self.setAnchor(self.anchors[1]) #set to left of line
# self.setAnchor(self.anchors[0]) #set to right of line

Now just change updatePosition as follows:
    def updatePosition(self):
        # update text position to relative view location along line
        self._endpoints = (None, None)
        pt1, pt2 = self.getEndpoints()
        if pt1 is None:
            return
        pt = pt2 * self.orthoPos + pt1 * (1-self.orthoPos)
        self.setPos(pt)
        
        #This flips the text label automatically to the left or right of the line when the 
        #line transverses the middle of the viewbox
        # update anchor to keep text visible as it nears the view box edge
        # vr = self.line.viewRect()
        # if vr is not None:
        #     logger.debug(vr.center().y())
        #     self.setAnchor(self.anchors[0 if vr.center().y() < 0 else 1])
Reply all
Reply to author
Forward
0 new messages