Skip to content

Commit 5b7283e

Browse files
committed
selectively update lines in add_values
`add_values` would repeatedly call `update` for each line where a value was added, and `update` calls `_draw` which re-draws _all_ lines each time it is called. By keeping track of lines that need to be updated and only calling `update` once at the end of `add_values`, we avoid $(n-1)^2$ spurious line re-draws.
1 parent f975229 commit 5b7283e

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

adafruit_display_shapes/multisparkline.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,8 +172,10 @@ def add_values(self, values: List[float], update: bool = True) -> None:
172172
call the update()-method
173173
"""
174174

175+
lines_to_update = []
175176
for i, value in enumerate(values):
176177
if value is not None:
178+
lines_to_update.append(i)
177179
top = self.y_tops[i]
178180
bottom = self.y_bottoms[i]
179181
if (
@@ -195,8 +197,8 @@ def add_values(self, values: List[float], update: bool = True) -> None:
195197
self.y_tops[i] = top
196198
self.y_bottoms[i] = bottom
197199

198-
if update:
199-
self.update_line(i)
200+
if update and lines_to_update:
201+
self.update_line(lines_to_update)
200202

201203
def _add_point(
202204
self,

0 commit comments

Comments
 (0)