temp mahony filter
This commit is contained in:
61
plot.py
61
plot.py
@@ -238,6 +238,32 @@ def draw_grid(
|
||||
surface.blit(font.render(title, True, TEXT), (rect.left + 8, rect.top + 8))
|
||||
|
||||
|
||||
def draw_graph_info(
|
||||
surface: pygame.Surface,
|
||||
rect: pygame.Rect,
|
||||
font: pygame.font.Font,
|
||||
graph_streams: list[dict],
|
||||
latest_values: dict[str, float | None],
|
||||
) -> None:
|
||||
line_height = font.get_height() + 6
|
||||
y = rect.top + 8
|
||||
for stream in graph_streams:
|
||||
color = color_tuple(stream["color"])
|
||||
label = stream.get("label", stream["key"])
|
||||
latest_value = latest_values.get(stream["key"])
|
||||
value_text = "--" if latest_value is None else f"{latest_value:.3f}"
|
||||
pygame.draw.line(
|
||||
surface,
|
||||
color,
|
||||
(rect.left, y + 8),
|
||||
(rect.left + 24, y + 8),
|
||||
3,
|
||||
)
|
||||
text = font.render(f"{label}: {value_text}", True, TEXT)
|
||||
surface.blit(text, (rect.left + 32, y))
|
||||
y += line_height
|
||||
|
||||
|
||||
def draw_trace(
|
||||
surface: pygame.Surface,
|
||||
rect: pygame.Rect,
|
||||
@@ -348,16 +374,20 @@ def main() -> int:
|
||||
width, height = screen.get_size()
|
||||
now = time.monotonic()
|
||||
graph_count = len(graphs)
|
||||
plot_width = max(100, width - 100)
|
||||
left_margin = 70
|
||||
right_margin = 20
|
||||
info_width = min(280, max(180, width // 4))
|
||||
plot_width = max(100, width - left_margin - right_margin - info_width - 16)
|
||||
available_height = max(100, height - 120 - (graph_count - 1) * 30)
|
||||
panel_height = max(100, available_height // graph_count)
|
||||
|
||||
screen.fill(BACKGROUND)
|
||||
|
||||
latest_values: dict[str, int | None] = {}
|
||||
latest_values: dict[str, float | None] = {}
|
||||
top = 40
|
||||
for graph in graphs:
|
||||
rect = pygame.Rect(70, top, plot_width, panel_height)
|
||||
rect = pygame.Rect(left_margin, top, plot_width, panel_height)
|
||||
info_rect = pygame.Rect(rect.right + 16, top, info_width, panel_height)
|
||||
graph_streams = graph["streams"]
|
||||
stream_names = [stream["key"] for stream in graph_streams]
|
||||
y_min, y_max = visible_range(sample_sets, stream_names, now, view_span)
|
||||
@@ -381,39 +411,16 @@ def main() -> int:
|
||||
y_max,
|
||||
color_tuple(stream["color"]),
|
||||
)
|
||||
draw_graph_info(screen, info_rect, small_font, graph_streams, latest_values)
|
||||
top = rect.bottom + 30
|
||||
|
||||
header = f"port={args.port} baud={args.baudrate} zoom={view_span:.1f}s"
|
||||
for graph in graphs:
|
||||
graph_parts = []
|
||||
for stream in graph["streams"]:
|
||||
latest_value = latest_values.get(stream["key"])
|
||||
if latest_value is not None:
|
||||
graph_parts.append(f"{stream.get('label', stream['key'])}={latest_value:.3f}")
|
||||
if graph_parts:
|
||||
header += " | " + " ".join(graph_parts)
|
||||
screen.blit(font.render(header, True, TEXT), (10, 8))
|
||||
screen.blit(
|
||||
small_font.render("mouse wheel: zoom horizontal axis", True, AXIS),
|
||||
(10, height - 24),
|
||||
)
|
||||
|
||||
legend_x = 10
|
||||
legend_y = 34
|
||||
for graph in graphs:
|
||||
for stream in graph["streams"]:
|
||||
color = color_tuple(stream["color"])
|
||||
label = stream.get("label", stream["key"])
|
||||
pygame.draw.line(
|
||||
screen,
|
||||
color,
|
||||
(legend_x, legend_y + 9),
|
||||
(legend_x + 24, legend_y + 9),
|
||||
3,
|
||||
)
|
||||
screen.blit(small_font.render(label, True, TEXT), (legend_x + 30, legend_y))
|
||||
legend_x += max(90, 42 + len(label) * 10)
|
||||
|
||||
if error_message:
|
||||
error_surface = font.render(error_message, True, ERROR)
|
||||
screen.blit(error_surface, (10, height - 52))
|
||||
|
||||
Reference in New Issue
Block a user