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)
| 18 | from pagebot.toolbox.color import noColor |
| 19 | |
| 20 | def 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 | |
| 74 | if __name__ == "__main__": |
| 75 | import doctest |
nothing calls this directly
no test coverage detected