MCPcopy Create free account
hub / github.com/PageBot/PageBot / drawArrow

Function drawArrow

Lib/pagebot/toolbox/drawing.py:20–72  ·  view source on GitHub ↗

Draw curved arrow marker between the two points. TODO: Add drawing of real arrow-heads, rotated in the right direction. TODO: move to elements?

(e, view, xs, ys, xt, yt, onText=1, startMarker=False,
        endMarker=False)

Source from the content-addressed store, hash-verified

18from pagebot.toolbox.color import noColor
19
20def drawArrow(e, view, xs, ys, xt, yt, onText=1, startMarker=False,
21 endMarker=False):
22 """Draw curved arrow marker between the two points.
23
24 TODO: Add drawing of real arrow-heads, rotated in the right direction.
25 TODO: move to elements?
26 """
27 context = view.context # Get current context
28 b = context.b
29
30 fms = e.css('flowMarkerSize')
31 fmf = e.css('flowCurvatureFactor')
32 if onText == 1:
33 c = e.css('flowConnectionStroke2', noColor)
34 else:
35 c = e.css('flowConnectionStroke1', noColor)
36 context.stroke(c, e.css('flowConnectionStrokeWidth'))
37 if startMarker:
38 context.fill(e.css('flowMarkerFill', noColor))
39 context.oval(xs - fms, ys - fms, 2 * fms, 2 * fms)
40 xm = (xt + xs)/2
41 ym = (yt + ys)/2
42 xb1 = xm + onText * (yt - ys) * fmf
43 yb1 = ym - onText * (xt - xs) * fmf
44 xb2 = xm - onText * (yt - ys) * fmf
45 yb2 = ym + onText * (xt - xs) * fmf
46
47 # Arrow head position.
48 arrowSize = 12
49 arrowAngle = 0.4
50 angle = atan2(xt-xb2, yt-yb2)
51 hookedAngle = radians(degrees(angle)-90)
52 ax1 = xt - cos(hookedAngle+arrowAngle) * arrowSize
53 ay1 = yt + sin(hookedAngle+arrowAngle) * arrowSize
54 ax2 = xt - cos(hookedAngle-arrowAngle) * arrowSize
55 ay2 = yt + sin(hookedAngle-arrowAngle) * arrowSize
56 b.newPath()
57 context.fill(None)
58 b.moveTo((xs, ys))
59 b.curveTo((xb1, yb1), (xb2, yb2), ((ax1+ax2)/2, (ay1+ay2)/2)) # End in middle of arrow head.
60 b.drawPath()
61
62 # Draw the arrow head.
63 b.newPath()
64 context.fill(c)
65 context.stroke(None)
66 b.moveTo((xt, yt))
67 b.lineTo((ax1, ay1))
68 b.lineTo((ax2, ay2))
69 b.closePath()
70 b.drawPath()
71 if endMarker:
72 context.oval(xt - fms, yt - fms, 2 * fms, 2 * fms)
73
74if __name__ == "__main__":
75 import doctest

Callers

nothing calls this directly

Calls 13

atan2Function · 0.85
radiansFunction · 0.85
degreesFunction · 0.85
cssMethod · 0.45
strokeMethod · 0.45
fillMethod · 0.45
ovalMethod · 0.45
newPathMethod · 0.45
moveToMethod · 0.45
curveToMethod · 0.45
drawPathMethod · 0.45
lineToMethod · 0.45

Tested by

no test coverage detected