Skip to content

Commit f83cee7

Browse files
authored
Merge pull request #20 from kmatch98/master
Corrects off-by-one error in due to rounding errors
2 parents 5dee81e + f2c84b0 commit f83cee7

File tree

2 files changed

+6
-12
lines changed

2 files changed

+6
-12
lines changed

adafruit_display_shapes/sparkline.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ def update(self):
139139
self.y_top = self.y_max
140140

141141
if len(self._spark_list) > 2:
142-
xpitch = self.width / (
142+
xpitch = (self.width - 1) / (
143143
len(self._spark_list) - 1
144144
) # this is a float, only make int when plotting the line
145145

examples/display_shapes_sparkline_ticks.py

+5-11
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@
137137

138138

139139
bounding_rectangle = Rect(
140-
sparkline1.x, sparkline1.y, chart_width + 1, chart_height + 1, outline=line_color
140+
sparkline1.x, sparkline1.y, chart_width, chart_height, outline=line_color
141141
)
142142

143143

@@ -160,17 +160,11 @@
160160
for i in range(total_ticks + 1):
161161
x_start = sparkline1.x - 5
162162
x_end = sparkline1.x
163-
y_both = sparkline1.y + i * int(round(chart_height / (total_ticks)))
163+
y_both = int(round(sparkline1.y + (i * (chart_height) / (total_ticks))))
164+
if y_both > sparkline1.y + chart_height - 1:
165+
y_both = sparkline1.y + chart_height - 1
164166
my_group.append(Line(x_start, y_both, x_end, y_both, color=line_color))
165-
my_group.append(
166-
Line(
167-
x_start,
168-
sparkline1.y + chart_height,
169-
x_end,
170-
sparkline1.y + chart_height,
171-
color=line_color,
172-
)
173-
)
167+
174168

175169
# Set the display to show my_group that contains the sparkline and other graphics
176170
display.show(my_group)

0 commit comments

Comments
 (0)