From 2567867164cd50a71758b68e3e18b4232cc95549 Mon Sep 17 00:00:00 2001 From: Bernhard Bablok Date: Tue, 5 Jul 2022 16:41:22 +0200 Subject: [PATCH 1/2] implement parameter update for add_values() --- adafruit_display_shapes/sparkline.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/adafruit_display_shapes/sparkline.py b/adafruit_display_shapes/sparkline.py index 39e8056..3894e94 100644 --- a/adafruit_display_shapes/sparkline.py +++ b/adafruit_display_shapes/sparkline.py @@ -99,9 +99,14 @@ def clear_values(self) -> None: self.pop() self._spark_list = [] # empty the list - def add_value(self, value: float) -> None: + def add_value(self, value: float, update: boolean = True) -> None: """Add a value to the sparkline. :param value: The value to be added to the sparkline + :param update: trigger recreation of primitives + + Note: when adding multiple values it is more efficient to call + this method with parameter 'update=False' and then to manually + call the update()-method """ if value is not None: @@ -110,7 +115,8 @@ def add_value(self, value: float) -> None: ): # if list is full, remove the first item self._spark_list.pop(0) self._spark_list.append(value) - self.update() + if update: + self.update() # pylint: disable=no-else-return @staticmethod From 29ce3afd91652137d0d5f088909b4bb7338385d8 Mon Sep 17 00:00:00 2001 From: Bernhard Bablok Date: Tue, 5 Jul 2022 17:01:57 +0200 Subject: [PATCH 2/2] fixed typing boolean->bool --- adafruit_display_shapes/sparkline.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/adafruit_display_shapes/sparkline.py b/adafruit_display_shapes/sparkline.py index 3894e94..362a345 100644 --- a/adafruit_display_shapes/sparkline.py +++ b/adafruit_display_shapes/sparkline.py @@ -99,7 +99,7 @@ def clear_values(self) -> None: self.pop() self._spark_list = [] # empty the list - def add_value(self, value: float, update: boolean = True) -> None: + def add_value(self, value: float, update: bool = True) -> None: """Add a value to the sparkline. :param value: The value to be added to the sparkline :param update: trigger recreation of primitives