Skip to content

Updates for pylint, ran black #3

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 1 commit into from
Jul 22, 2020
Merged
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
41 changes: 33 additions & 8 deletions adafruit_display_shapes/sparkline.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,36 @@
# See the bottom for a code example using the `sparkline` Class.

# # File: display_shapes_sparkline.py
# A sparkline is a scrolling line graph, where any values added to sparkline using `add_value` are plotted.
# A sparkline is a scrolling line graph, where any values added to sparkline using `
# add_value` are plotted.
#
# The `sparkline` class creates an element suitable for adding to the display using `display.show(mySparkline)`
# The `sparkline` class creates an element suitable for adding to the display using
# `display.show(mySparkline)`
# or adding to a `displayio.Group` to be displayed.
#
# When creating the sparkline, identify the number of `max_items` that will be included in the graph.
# When additional elements are added to the sparkline and the number of items has exceeded max_items,
# any excess values are removed from the left of the graph, and new values are added to the right.
# When creating the sparkline, identify the number of `max_items` that will be
# included in the graph. When additional elements are added to the sparkline and
# the number of items has exceeded max_items, any excess values are removed from
# the left of the graph, and new values are added to the right.

import displayio
from adafruit_display_shapes.line import Line


class Sparkline(displayio.Group):
# pylint: disable=invalid-name
""" A sparkline graph.

: param width: Width of the sparkline graph in pixels
: param height: Height of the sparkline graph in pixels
: param max_items: Maximum number of values housed in the sparkline
: param yMin: Lower range for the y-axis. Set to None for autorange.
: param yMax: Upper range for the y-axis. Set to None for autorange.
: param x: X-position on the screen, in pixels
: param y: Y-position on the screen, in pixels
: param color: Line color, the default value is 0xFFFFFF (WHITE)
"""

def __init__(
self,
width,
Expand Down Expand Up @@ -48,6 +64,11 @@ def __init__(
) # self is a group of lines

def add_value(self, value):
""" Add a value to the sparkline.

: param value: The value to be added to the sparkline
"""

if value is not None:
if (
len(self._spark_list) >= self._max_items
Expand Down Expand Up @@ -77,16 +98,20 @@ def _plotLine(self, x1, last_value, x2, value, yBottom, yTop):
y1 = int(self.height * (yTop - last_value) / (yTop - yBottom))
self.append(Line(x1, y1, x2, y2, self.color)) # plot the line

# pylint: disable=invalid-name, too-many-branches

def update(self):
# What to do if there is 0 or 1 element?
"""Update the drawing of the sparkline

"""

# get the y range
if self.yMin == None:
if self.yMin is None:
self.yBottom = min(self._spark_list)
else:
self.yBottom = self.yMin

if self.yMax == None:
if self.yMax is None:
self.yTop = max(self._spark_list)
else:
self.yTop = self.yMax
Expand Down