def draw_arrow_w_text_middle(scene: Plot, start: tuple, point1: tuple, point2: tuple, end: tuple, height: int, arrowsize: int, is_curved: bool, text: str, font_size: int, font_family: str, over: bool, color: tuple): """ # Store the appropriate function ouside of the loop if is_curved: shape = [Path.MOVETO, Path.CURVE4, Path.CURVE4, Path.CURVE4] else: shape = [Path.MOVETO, Path.LINETO, Path.LINETO, Path.LINETO] # This should work, but matplotlib is not ready yet: FancyArrowPatch(path=Path([start, point1, point2, end], s hape) scene.add_patch(PathPatch(Path([start, point1, point2, end], shape), edgecolor='#{0:02x}{1:02x}{2:02x}'.format(*color), facecolor=(1, 1, 1, 0), # Transparent... linewidth=1)) # TODO Line width! """ if is_curved: # cubic Bezier curve glyph = Bezier(x0=start[0], y0=start[1], x1=end[0], y1=end[1], cx0=point1[0], line_color='#{0:02x}{1:02x}{2:02x}'.format(*color), cy0=point1[1], cx1=point2[0], cy1=point2[1], line_width=1) scene.add_glyph(glyph) else: source = ColumnDataSource( dict(x=[start[0], end[0]], y=[start[1], end[1]])) glyph = Line(x="x", y="y", line_width=1, line_color='#{0:02x}{1:02x}{2:02x}'.format(*color)) scene.add_glyph(source, glyph) # Draw arrow scene.line([end[0] - arrowsize, end[0], end[0] + arrowsize], [end[1] - arrowsize, end[1], end[1] - arrowsize], line_color='#{0:02x}{1:02x}{2:02x}'.format(*color)) direction = 1 if over: direction = -1 # Write label in the middle under labelx = min(start[0], point2[0]) + abs(start[0] - point2[0]) // 2 labely = height + direction * font_size # TODO: Should be font height! source = ColumnDataSource(dict(x=[labelx], y=[labely], text=[text])) glyph = Text(x="x", y="y", text="text", text_align="center", text_color='#{0:02x}{1:02x}{2:02x}'.format(*color), text_font_size=str(font_size) + "pt", text_font=font_family) # TODO: Here was TextToken (must align to left) scene.add_glyph(source, glyph)