Implement separate class for rendering Skew-T legends
This commit is contained in:
parent
eaa23d4b41
commit
dcf2f2034c
1 changed files with 59 additions and 1 deletions
|
@ -13,7 +13,7 @@ PRESSURE_LOG_MAX = math.log(PRESSURE_MAX)
|
|||
PRESSURE_LOG_MIN = math.log(PRESSURE_MIN)
|
||||
PRESSURE_LOG_RANGE = PRESSURE_LOG_MAX - PRESSURE_LOG_MIN
|
||||
|
||||
TEMP_MAX = 50
|
||||
TEMP_MAX = 50 # degrees C
|
||||
TEMP_MIN = -50
|
||||
TEMP_RANGE = TEMP_MAX - TEMP_MIN
|
||||
TEMP_CENTER = 0 # degrees C
|
||||
|
@ -131,3 +131,61 @@ class SkewTGraph():
|
|||
self.draw_samples(cr, x, y, samples, lambda s: s.dewpoint)
|
||||
|
||||
cr.reset_clip()
|
||||
|
||||
class SkewTLegend():
|
||||
@staticmethod
|
||||
def draw_isotherm_legends_for_graph(cr: cairo.Context,
|
||||
skew_t: SkewTGraph,
|
||||
x: float,
|
||||
y: float):
|
||||
temp = TEMP_MAX
|
||||
|
||||
while True:
|
||||
text = "%d°C" % (temp)
|
||||
extents = cr.text_extents(text)
|
||||
|
||||
x_rel, y_rel = skew_t.sample_to_screen(temp, PRESSURE_MAX)
|
||||
|
||||
if x_rel < 0:
|
||||
y_rel = skew_t.height + x_rel
|
||||
x_rel = 0
|
||||
|
||||
if y_rel <= 0:
|
||||
break
|
||||
|
||||
cr.move_to(x + x_rel - extents.width - 8,
|
||||
y + y_rel + extents.height / 2)
|
||||
else:
|
||||
cr.move_to(x + x_rel - extents.width / 2,
|
||||
y + y_rel + extents.height + 8)
|
||||
|
||||
cr.show_text(text)
|
||||
cr.stroke()
|
||||
|
||||
temp -= 2 * TEMP_STEP
|
||||
|
||||
@staticmethod
|
||||
def draw_isobar_legends_for_graph(cr: cairo.Context,
|
||||
skew_t: SkewTGraph,
|
||||
x: float,
|
||||
y: float):
|
||||
for pressure in range(PRESSURE_MAX, PRESSURE_MIN-1, -2*PRESSURE_STEP):
|
||||
x_rel = skew_t.width
|
||||
y_rel = skew_t.height - skew_t.pressure_to_y(pressure)
|
||||
|
||||
text = "%dmb" % (pressure)
|
||||
extents = cr.text_extents(text)
|
||||
|
||||
cr.move_to(x + x_rel + 8,
|
||||
y + y_rel + extents.height / 2)
|
||||
|
||||
cr.show_text(text)
|
||||
cr.stroke()
|
||||
|
||||
@staticmethod
|
||||
def draw_for_graph(cr: cairo.Context,
|
||||
skew_t: SkewTGraph,
|
||||
x: float,
|
||||
y: float):
|
||||
SkewTLegend.draw_isotherm_legends_for_graph(cr, skew_t, x, y)
|
||||
SkewTLegend.draw_isobar_legends_for_graph(cr, skew_t, x, y)
|
||||
|
|
Loading…
Add table
Reference in a new issue