From c8ced7f982ae788770f338a34d0dc0272bb0a830 Mon Sep 17 00:00:00 2001 From: AlanFromJapan Date: Mon, 3 Nov 2025 22:34:10 +0900 Subject: [PATCH] Added min/max formatter to DisplayLineGraph(), useful for CPU load where min/max can be usually within 0 to 1. --- library/lcd/lcd_comm.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/library/lcd/lcd_comm.py b/library/lcd/lcd_comm.py index 4e2714fe..a31f0e27 100644 --- a/library/lcd/lcd_comm.py +++ b/library/lcd/lcd_comm.py @@ -380,7 +380,8 @@ def DisplayLineGraph(self, x: int, y: int, width: int, height: int, axis_font: str = "./res/fonts/roboto/Roboto-Black.ttf", axis_font_size: int = 10, background_color: Color = (255, 255, 255), - background_image: Optional[str] = None): + background_image: Optional[str] = None, + axis_minmax_format: str = "{:0.0f}"): # Generate a plot graph and display it # Provide the background image path to display plot graph with transparent background @@ -451,13 +452,13 @@ def DisplayLineGraph(self, x: int, y: int, width: int, height: int, # Draw Legend draw.line([0, 0, 1, 0], fill=axis_color) - text = f"{int(max_value)}" + text = axis_minmax_format.format(max_value) ttfont = self.open_font(axis_font, axis_font_size) _, top, right, bottom = ttfont.getbbox(text) draw.text((2, 0 - top), text, font=ttfont, fill=axis_color) - text = f"{int(min_value)}" + text = axis_minmax_format.format(min_value) _, top, right, bottom = ttfont.getbbox(text) draw.text((width - 1 - right, height - 2 - bottom), text, font=ttfont, fill=axis_color)