From 6a00aad2a1098c85cd5c209e7ef0f74a6c3781eb Mon Sep 17 00:00:00 2001 From: XANTRONIX Industrial Date: Mon, 3 Mar 2025 23:46:38 -0500 Subject: [PATCH] Show direction legends in all four cardinals --- lib/xmet/hodograph.py | 47 ++++++++++++++++++++++++++----------------- 1 file changed, 29 insertions(+), 18 deletions(-) diff --git a/lib/xmet/hodograph.py b/lib/xmet/hodograph.py index 9923e8b..586212a 100644 --- a/lib/xmet/hodograph.py +++ b/lib/xmet/hodograph.py @@ -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 = { + '0°': ( + 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()