Skip to content

Commit f7742d2

Browse files
authored
Update sparkline.py
Formatting fixes
1 parent 81c1cee commit f7742d2

1 file changed

Lines changed: 20 additions & 18 deletions

File tree

adafruit_display_shapes/sparkline.py

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -47,27 +47,27 @@
4747
from adafruit_display_shapes.polygon import Polygon
4848

4949

50-
class _CyclicBuffer():
50+
class _CyclicBuffer:
5151
def __init__(self, size: int) -> None:
5252
self._buffer = [None] * size
53-
self._start = 0 # between 0 and size-1
54-
self._end = 0 # between 0 and 2*size-1
55-
53+
self._start = 0 # between 0 and size-1
54+
self._end = 0 # between 0 and 2*size-1
55+
5656
def push(self, value: float) -> None:
5757
"""Pushes value at the end of the buffer.
5858
5959
:param float value: value to be pushed
6060
6161
"""
62-
62+
6363
if self.len() == len(self._buffer):
6464
raise RuntimeError("Trying to push to full buffer")
6565
self._buffer[self._end % len(self._buffer)] = value
6666
self._end += 1
67-
67+
6868
def pop(self) -> float:
6969
"""Pop value from the start of the buffer and returns it."""
70-
70+
7171
if self.len() == 0:
7272
raise RuntimeError("Trying to pop from empty buffer")
7373
result = self._buffer[self._start]
@@ -76,21 +76,21 @@ def pop(self) -> float:
7676
self._start -= len(self._buffer)
7777
self._end -= len(self._buffer)
7878
return result
79-
79+
8080
def len(self) -> int:
8181
"""Returns count of valid data in the buffer."""
82-
82+
8383
return self._end - self._start
84-
84+
8585
def clear(self) -> None:
8686
"""Marks all data as invalid."""
87-
87+
8888
self._start = 0
8989
self._end = 0
90-
90+
9191
def values(self) -> List[float]:
9292
"""Returns valid data from the buffer."""
93-
93+
9494
if self.len() == 0:
9595
return []
9696
start = self._start
@@ -153,7 +153,7 @@ def __init__(
153153
self._points = [] # _points: all points of sparkline
154154

155155
super().__init__(x=x, y=y) # self is a group of single Polygon
156-
# (TODO: it has one element, maybe group is no longer needed?)
156+
# (TODO: it has one element, maybe group is no longer needed?)
157157

158158
def clear_values(self) -> None:
159159
"""Clears _buffer and removes all lines in the group"""
@@ -229,11 +229,13 @@ def _add_point(
229229
else:
230230
y = int(self.height * (self.y_top - value) / (self.y_top - self.y_bottom))
231231
self._points.append((x, y))
232-
232+
233233
def _draw(self) -> None:
234-
while(len(self)):
234+
while len(self):
235235
self.pop()
236-
self.append(Polygon(self._points, outline=self.color, close=False)) # plot the polyline
236+
self.append(
237+
Polygon(self._points, outline=self.color, close=False)
238+
) # plot the polyline
237239

238240
# pylint: disable= too-many-branches, too-many-nested-blocks, too-many-locals, too-many-statements
239241

@@ -299,7 +301,7 @@ def update(self) -> None:
299301
self._add_point(adj_x, adj_value)
300302

301303
last_value = value # store value for the next iteration
302-
304+
303305
self._draw()
304306

305307
def values(self) -> List[float]:

0 commit comments

Comments
 (0)