Show direction legends in all four cardinals

This commit is contained in:
XANTRONIX 2025-03-03 23:46:38 -05:00
parent 59a82534dc
commit 6a00aad2a1

View file

@ -119,33 +119,44 @@ class Hodograph():
cr.restore()
def draw_direction_legends(self, cr: cairo.Context, x, y):
cx, cy = self.sample_to_screen(0, 0)
legends = {
'': (
lambda e: x + cx - e.width / 2,
lambda e: y + self.height - 2 * e.height
),
'90°': (
lambda e: x + cx - e.width * 2,
lambda e: y + cy + e.height / 2
),
'180°': (
lambda e: x + cx - e.width / 2,
lambda e: y + 2 * e.height
),
'270°': (
lambda e: x + self.width - e.width * 2,
lambda e: y + cy + e.height / 2
)
}
cr.save()
cr.select_font_face('Sans',
cairo.FONT_SLANT_NORMAL,
cairo.FONT_WEIGHT_BOLD)
cx, cy = self.sample_to_screen(0, 0)
cr.set_font_size(14)
text = "%d°" % 180
extents = cr.text_extents(text)
for text in legends:
extents = cr.text_extents(text)
fx, fy = legends[text]
cr.move_to(x + cx - extents.width / 2,
y + 4 * extents.height)
cr.show_text(text)
cr.stroke()
text = "%d°" % 0
extents = cr.text_extents(text)
cr.move_to(x + cx - extents.width / 2,
y + self.height - 4 * extents.height)
cr.show_text(text)
cr.stroke()
cr.move_to(fx(extents), fy(extents))
cr.show_text(text)
cr.restore()