Skip to content

Corrects off-by-one error in due to rounding errors #20

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Jul 27, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion adafruit_display_shapes/sparkline.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ def update(self):
self.y_top = self.y_max

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

Expand Down
16 changes: 5 additions & 11 deletions examples/display_shapes_sparkline_ticks.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@


bounding_rectangle = Rect(
sparkline1.x, sparkline1.y, chart_width + 1, chart_height + 1, outline=line_color
sparkline1.x, sparkline1.y, chart_width, chart_height, outline=line_color
)


Expand All @@ -160,17 +160,11 @@
for i in range(total_ticks + 1):
x_start = sparkline1.x - 5
x_end = sparkline1.x
y_both = sparkline1.y + i * int(round(chart_height / (total_ticks)))
y_both = int(round(sparkline1.y + (i * (chart_height) / (total_ticks))))
if y_both > sparkline1.y + chart_height - 1:
y_both = sparkline1.y + chart_height - 1
my_group.append(Line(x_start, y_both, x_end, y_both, color=line_color))
my_group.append(
Line(
x_start,
sparkline1.y + chart_height,
x_end,
sparkline1.y + chart_height,
color=line_color,
)
)


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