Skip to content

Commit 27818af

Browse files
author
Margaret Matocha
committed
Corrected two off-by-one errors due to rounding to integers
1 parent e86f641 commit 27818af

File tree

3 files changed

+12
-17
lines changed

3 files changed

+12
-17
lines changed

adafruit_display_shapes/rect.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,11 @@ def __init__(self, x, y, width, height, *, fill=None, outline=None, stroke=1):
6969
for w in range(width):
7070
for line in range(stroke):
7171
self._bitmap[w, line] = 1
72-
self._bitmap[w, height - line] = 1
72+
self._bitmap[w, height - 1 - line] = 1
7373
for _h in range(height):
7474
for line in range(stroke):
7575
self._bitmap[line, _h] = 1
76-
self._bitmap[width - line, _h] = 1
76+
self._bitmap[width -1 - line, _h] = 1
7777

7878
if fill is not None:
7979
self._palette[0] = fill

adafruit_display_shapes/sparkline.py

Lines changed: 1 addition & 1 deletion
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

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,8 @@
109109
max_items=40,
110110
y_min=0,
111111
y_max=10,
112-
x=40,
113-
y=30,
112+
x=20,
113+
y=20,
114114
color=line_color,
115115
)
116116

@@ -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

@@ -157,20 +157,15 @@
157157

158158
total_ticks = 10
159159

160-
for i in range(total_ticks + 1):
160+
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
166+
print('y_both: {}, i: {}'.format(y_both, i))
164167
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-
)
168+
174169

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

0 commit comments

Comments
 (0)