Show direction legends in all four cardinals
This commit is contained in:
parent
59a82534dc
commit
6a00aad2a1
1 changed files with 29 additions and 18 deletions
|
@ -119,33 +119,44 @@ class Hodograph():
|
||||||
cr.restore()
|
cr.restore()
|
||||||
|
|
||||||
def draw_direction_legends(self, cr: cairo.Context, x, y):
|
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.save()
|
||||||
|
|
||||||
cr.select_font_face('Sans',
|
cr.select_font_face('Sans',
|
||||||
cairo.FONT_SLANT_NORMAL,
|
cairo.FONT_SLANT_NORMAL,
|
||||||
cairo.FONT_WEIGHT_BOLD)
|
cairo.FONT_WEIGHT_BOLD)
|
||||||
|
|
||||||
cx, cy = self.sample_to_screen(0, 0)
|
|
||||||
|
|
||||||
cr.set_font_size(14)
|
cr.set_font_size(14)
|
||||||
|
|
||||||
text = "%d°" % 180
|
for text in legends:
|
||||||
extents = cr.text_extents(text)
|
extents = cr.text_extents(text)
|
||||||
|
fx, fy = legends[text]
|
||||||
|
|
||||||
cr.move_to(x + cx - extents.width / 2,
|
cr.move_to(fx(extents), fy(extents))
|
||||||
y + 4 * extents.height)
|
|
||||||
|
|
||||||
cr.show_text(text)
|
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.restore()
|
cr.restore()
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue