Skip to content

Commit cdef091

Browse files
authored
Merge pull request #50 from bablokb/sparkline_opt
implement parameter update for add_values()
2 parents e5495c3 + 29ce3af commit cdef091

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

adafruit_display_shapes/sparkline.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,14 @@ def clear_values(self) -> None:
9999
self.pop()
100100
self._spark_list = [] # empty the list
101101

102-
def add_value(self, value: float) -> None:
102+
def add_value(self, value: float, update: bool = True) -> None:
103103
"""Add a value to the sparkline.
104104
:param value: The value to be added to the sparkline
105+
:param update: trigger recreation of primitives
106+
107+
Note: when adding multiple values it is more efficient to call
108+
this method with parameter 'update=False' and then to manually
109+
call the update()-method
105110
"""
106111

107112
if value is not None:
@@ -110,7 +115,8 @@ def add_value(self, value: float) -> None:
110115
): # if list is full, remove the first item
111116
self._spark_list.pop(0)
112117
self._spark_list.append(value)
113-
self.update()
118+
if update:
119+
self.update()
114120

115121
# pylint: disable=no-else-return
116122
@staticmethod

0 commit comments

Comments
 (0)