Skip to content

Commit 7fe45cb

Browse files
author
Margaret Matocha
committed
Updates for pylint, ran black
1 parent 28dc4ae commit 7fe45cb

File tree

1 file changed

+33
-8
lines changed

1 file changed

+33
-8
lines changed

adafruit_display_shapes/sparkline.py

Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,36 @@
44
# See the bottom for a code example using the `sparkline` Class.
55

66
# # File: display_shapes_sparkline.py
7-
# A sparkline is a scrolling line graph, where any values added to sparkline using `add_value` are plotted.
7+
# A sparkline is a scrolling line graph, where any values added to sparkline using `
8+
# add_value` are plotted.
89
#
9-
# The `sparkline` class creates an element suitable for adding to the display using `display.show(mySparkline)`
10+
# The `sparkline` class creates an element suitable for adding to the display using
11+
# `display.show(mySparkline)`
1012
# or adding to a `displayio.Group` to be displayed.
1113
#
12-
# When creating the sparkline, identify the number of `max_items` that will be included in the graph.
13-
# When additional elements are added to the sparkline and the number of items has exceeded max_items,
14-
# any excess values are removed from the left of the graph, and new values are added to the right.
14+
# When creating the sparkline, identify the number of `max_items` that will be
15+
# included in the graph. When additional elements are added to the sparkline and
16+
# the number of items has exceeded max_items, any excess values are removed from
17+
# the left of the graph, and new values are added to the right.
1518

1619
import displayio
1720
from adafruit_display_shapes.line import Line
1821

1922

2023
class Sparkline(displayio.Group):
24+
# pylint: disable=invalid-name
25+
""" A sparkline graph.
26+
27+
: param width: Width of the sparkline graph in pixels
28+
: param height: Height of the sparkline graph in pixels
29+
: param max_items: Maximum number of values housed in the sparkline
30+
: param yMin: Lower range for the y-axis. Set to None for autorange.
31+
: param yMax: Upper range for the y-axis. Set to None for autorange.
32+
: param x: X-position on the screen, in pixels
33+
: param y: Y-position on the screen, in pixels
34+
: param color: Line color, the default value is 0xFFFFFF (WHITE)
35+
"""
36+
2137
def __init__(
2238
self,
2339
width,
@@ -48,6 +64,11 @@ def __init__(
4864
) # self is a group of lines
4965

5066
def add_value(self, value):
67+
""" Add a value to the sparkline.
68+
69+
: param value: The value to be added to the sparkline
70+
"""
71+
5172
if value is not None:
5273
if (
5374
len(self._spark_list) >= self._max_items
@@ -77,16 +98,20 @@ def _plotLine(self, x1, last_value, x2, value, yBottom, yTop):
7798
y1 = int(self.height * (yTop - last_value) / (yTop - yBottom))
7899
self.append(Line(x1, y1, x2, y2, self.color)) # plot the line
79100

101+
# pylint: disable=invalid-name, too-many-branches
102+
80103
def update(self):
81-
# What to do if there is 0 or 1 element?
104+
"""Update the drawing of the sparkline
105+
106+
"""
82107

83108
# get the y range
84-
if self.yMin == None:
109+
if self.yMin is None:
85110
self.yBottom = min(self._spark_list)
86111
else:
87112
self.yBottom = self.yMin
88113

89-
if self.yMax == None:
114+
if self.yMax is None:
90115
self.yTop = max(self._spark_list)
91116
else:
92117
self.yTop = self.yMax

0 commit comments

Comments
 (0)