Skip to content

Commit fff1de9

Browse files
committed
don't set y_top/y_bottom to arbitrary values
1 parent 1857b97 commit fff1de9

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

adafruit_display_shapes/sparkline.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -145,10 +145,6 @@ def add_value(self, value: float, update: bool = True) -> None:
145145
self._redraw = self._redraw or value > self.y_top
146146
self.y_top = value if not self.y_top else max(value, self.y_top)
147147

148-
# Guard for y_top and y_bottom being the same
149-
if self.y_top == self.y_bottom:
150-
self.y_bottom *= 0.99
151-
152148
if update:
153149
self.update()
154150

@@ -182,10 +178,15 @@ def _plotline(
182178
value: float,
183179
) -> None:
184180

185-
y_2 = int(self.height * (self.y_top - value) / (self.y_top - self.y_bottom))
186-
y_1 = int(
187-
self.height * (self.y_top - last_value) / (self.y_top - self.y_bottom)
188-
)
181+
# Guard for y_top and y_bottom being the same
182+
if self.y_top == self.y_bottom:
183+
y_2 = int(0.5 * self.height)
184+
y_1 = int(0.5 * self.height)
185+
else:
186+
y_2 = int(self.height * (self.y_top - value) / (self.y_top - self.y_bottom))
187+
y_1 = int(
188+
self.height * (self.y_top - last_value) / (self.y_top - self.y_bottom)
189+
)
189190
self.append(Line(x_1, y_1, x_2, y_2, self.color)) # plot the line
190191
self._last = [x_2, value]
191192

0 commit comments

Comments
 (0)