Try to automatically zoom into hodograph activity
This commit is contained in:
parent
72d8195943
commit
edf1af526f
1 changed files with 35 additions and 2 deletions
|
@ -22,8 +22,13 @@ def knots(ms: float) -> float:
|
|||
class Hodograph():
|
||||
def __init__(self, width, height):
|
||||
self.zoom = 1.2
|
||||
self.offset_x = 0.1
|
||||
self.offset_y = 0.9
|
||||
self.offset_x = 0.1 # Percentage of the upper left quadrant rendered
|
||||
self.offset_y = 0.9 # Percentage of the upper right quadrant rendered
|
||||
|
||||
self.min_x = 0
|
||||
self.min_y = 0
|
||||
self.max_x = 0
|
||||
self.max_y = 0
|
||||
|
||||
self.width = min(width, height)
|
||||
self.height = min(width, height)
|
||||
|
@ -45,6 +50,32 @@ class Hodograph():
|
|||
self.offset_y * self.height + gy
|
||||
)
|
||||
|
||||
def find_extents(self, sounding: Sounding):
|
||||
"""
|
||||
Determine the boundaries of the sounding to set the center and zoom
|
||||
appropriately.
|
||||
"""
|
||||
for sample in sounding.samples:
|
||||
x, y = self.sample_to_graph(sample.wind_speed, sample.wind_dir)
|
||||
|
||||
if self.min_x > x:
|
||||
self.min_x = x
|
||||
|
||||
if self.min_y > y:
|
||||
self.min_y = y
|
||||
|
||||
if self.max_x < x:
|
||||
self.max_x = x
|
||||
|
||||
if self.max_y < y:
|
||||
self.max_y = y
|
||||
|
||||
self.offset_x = self.min_x / self.radius + 0.1
|
||||
self.offset_y = (self.radius - self.max_y) / self.radius
|
||||
self.zoom = min(self.width, self.height) / max(self.max_x - self.min_x,
|
||||
self.max_y - self.min_y) / 2
|
||||
self.radius = min(self.width, self.height) * self.zoom
|
||||
|
||||
def draw_speed_lines(self, cr: cairo.Context, x, y):
|
||||
cr.save()
|
||||
|
||||
|
@ -199,6 +230,8 @@ class Hodograph():
|
|||
offset += interval
|
||||
|
||||
def draw(self, cr: cairo.Context, x, y, sounding: Sounding):
|
||||
self.find_extents(sounding)
|
||||
|
||||
cr.rectangle(x, y, self.width, self.height)
|
||||
cr.clip()
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue