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

Method drawArrow

Lib/pagebot/elements/views/mapview.py:365–428  ·  view source on GitHub ↗

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

(self, e, xs, ys, xt, yt, onText=1, startMarker=False,
            endMarker=False, fms=None, fmf=None, fill=noColor, stroke=noColor,
            strokeWidth=None)

Source from the content-addressed store, hash-verified

363 px+tbTarget.x, py+tbTarget.y+tbTarget.h-e.h, 1)
364
365 def drawArrow(self, e, xs, ys, xt, yt, onText=1, startMarker=False,
366 endMarker=False, fms=None, fmf=None, fill=noColor, stroke=noColor,
367 strokeWidth=None):
368 """Draw curved arrow marker between the two points.
369
370 TODO: Add drawing of real arrow-heads, rotated in the right direction."""
371 if fms is None:
372 fms = self.css('viewFlowMarkerSize')
373 if fmf is None:
374 fmf = self.css('viewFlowCurvatureFactor')
375
376 if stroke is None:
377 if onText == 1:
378 stroke = self.css('viewFlowConnectionStroke2', noColor)
379 else:
380 stroke = self.css('viewFlowConnectionStroke1', noColor)
381 if strokeWidth is None:
382 strokeWidth = self.css('viewFlowConnectionStrokeWidth', 0.5)
383
384 self.setStrokeColor(stroke, strokeWidth)
385 if startMarker:
386 if fill is None:
387 fill = self.css('viewFlowMarkerFill', noColor)
388 self.setFillColor(fill)
389 self.context.oval(xs - fms, ys - fms, 2 * fms, 2 * fms)
390
391 xm = (xt + xs)/2
392 ym = (yt + ys)/2
393 xb1 = xm + onText * (yt - ys) * fmf
394 yb1 = ym - onText * (xt - xs) * fmf
395 xb2 = xm - onText * (yt - ys) * fmf
396 yb2 = ym + onText * (xt - xs) * fmf
397 # Arrow head position.
398 arrowSize = 12
399 arrowAngle = 0.4
400 angle = atan2(xt-xb2, yt-yb2)
401 hookedAngle = radians(degrees(angle)-90)
402 ax1 = xt - cos(hookedAngle+arrowAngle) * arrowSize
403 ay1 = yt + sin(hookedAngle+arrowAngle) * arrowSize
404 ax2 = xt - cos(hookedAngle-arrowAngle) * arrowSize
405 ay2 = yt + sin(hookedAngle-arrowAngle) * arrowSize
406
407 # FIXME: don't use builder, use context.
408 b = self.context.b
409 b.newPath()
410 self.setFillColor(noColor)
411 b.moveTo((xs, ys))
412 # End in middle of arrow head.
413 b.curveTo((xb1, yb1), (xb2, yb2), ((ax1+ax2)/2, (ay1+ay2)/2))
414 b.drawPath()
415
416 # Draw the arrow head.
417 b.newPath()
418 self.setFillColor(stroke)
419 self.setStrokeColor(noColor)
420 b.moveTo((xt, yt))
421 b.lineTo((ax1, ay1))
422 b.lineTo((ax2, ay2))

Callers 1

drawFlowConnectionsMethod · 0.95

Calls 11

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

Tested by

no test coverage detected