Implement headWidth parameter for arrows (#385)
Although the documentation used to say that specifying tipAngle would override headWidth, headWidth was never used. The new behaviour is that tipAngle will be used, with a default value of 25, unless headWidth is specified. Co-authored-by: Ogi Moore <ognyan.moore@gmail.com>
This commit is contained in:
parent
dcef886a44
commit
e18af48b8d
|
@ -30,7 +30,7 @@ p2 = cw.addPlot(row=1, col=0)
|
|||
## variety of arrow shapes
|
||||
a1 = pg.ArrowItem(angle=-160, tipAngle=60, headLen=40, tailLen=40, tailWidth=20, pen={'color': 'w', 'width': 3})
|
||||
a2 = pg.ArrowItem(angle=-120, tipAngle=30, baseAngle=20, headLen=40, tailLen=40, tailWidth=8, pen=None, brush='y')
|
||||
a3 = pg.ArrowItem(angle=-60, tipAngle=30, baseAngle=20, headLen=40, tailLen=None, brush=None)
|
||||
a3 = pg.ArrowItem(angle=-60, baseAngle=20, headLen=40, headWidth=20, tailLen=None, brush=None)
|
||||
a4 = pg.ArrowItem(angle=-20, tipAngle=30, baseAngle=-30, headLen=40, tailLen=None)
|
||||
a2.setPos(10,0)
|
||||
a3.setPos(20,0)
|
||||
|
|
|
@ -389,14 +389,15 @@ def glColor(*args, **kargs):
|
|||
|
||||
|
||||
|
||||
def makeArrowPath(headLen=20, tipAngle=20, tailLen=20, tailWidth=3, baseAngle=0):
|
||||
def makeArrowPath(headLen=20, headWidth=None, tipAngle=20, tailLen=20, tailWidth=3, baseAngle=0):
|
||||
"""
|
||||
Construct a path outlining an arrow with the given dimensions.
|
||||
The arrow points in the -x direction with tip positioned at 0,0.
|
||||
If *tipAngle* is supplied (in degrees), it overrides *headWidth*.
|
||||
If *headWidth* is supplied, it overrides *tipAngle* (in degrees).
|
||||
If *tailLen* is None, no tail will be drawn.
|
||||
"""
|
||||
headWidth = headLen * np.tan(tipAngle * 0.5 * np.pi/180.)
|
||||
if headWidth is None:
|
||||
headWidth = headLen * np.tan(tipAngle * 0.5 * np.pi/180.)
|
||||
path = QtGui.QPainterPath()
|
||||
path.moveTo(0,0)
|
||||
path.lineTo(headLen, -headWidth)
|
||||
|
|
|
@ -28,6 +28,7 @@ class ArrowItem(QtGui.QGraphicsPathItem):
|
|||
'angle': -150, ## If the angle is 0, the arrow points left
|
||||
'pos': (0,0),
|
||||
'headLen': 20,
|
||||
'headWidth': None,
|
||||
'tipAngle': 25,
|
||||
'baseAngle': 0,
|
||||
'tailLen': None,
|
||||
|
@ -52,10 +53,10 @@ class ArrowItem(QtGui.QGraphicsPathItem):
|
|||
0; arrow pointing to the left.
|
||||
headLen Length of the arrow head, from tip to base.
|
||||
default=20
|
||||
headWidth Width of the arrow head at its base.
|
||||
headWidth Width of the arrow head at its base. If
|
||||
headWidth is specified, it overrides tipAngle.
|
||||
tipAngle Angle of the tip of the arrow in degrees. Smaller
|
||||
values make a 'sharper' arrow. If tipAngle is
|
||||
specified, ot overrides headWidth. default=25
|
||||
values make a 'sharper' arrow. default=25
|
||||
baseAngle Angle of the base of the arrow head. Default is
|
||||
0, which means that the base of the arrow head
|
||||
is perpendicular to the arrow tail.
|
||||
|
@ -70,7 +71,7 @@ class ArrowItem(QtGui.QGraphicsPathItem):
|
|||
"""
|
||||
self.opts.update(opts)
|
||||
|
||||
opt = dict([(k,self.opts[k]) for k in ['headLen', 'tipAngle', 'baseAngle', 'tailLen', 'tailWidth']])
|
||||
opt = dict([(k,self.opts[k]) for k in ['headLen', 'headWidth', 'tipAngle', 'baseAngle', 'tailLen', 'tailWidth']])
|
||||
tr = QtGui.QTransform()
|
||||
tr.rotate(self.opts['angle'])
|
||||
self.path = tr.map(fn.makeArrowPath(**opt))
|
||||
|
|
Loading…
Reference in New Issue
Block a user