Skip to content

Commit 0289b8a

Browse files
author
Margaret Matocha
committed
sparkline.py Updated camelCase to snake_case
1 parent 2141e5d commit 0289b8a

File tree

2 files changed

+49
-49
lines changed

2 files changed

+49
-49
lines changed

adafruit_display_shapes/sparkline.py

Lines changed: 48 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,14 @@
3939

4040

4141
class Sparkline(displayio.Group):
42-
# pylint: disable=invalid-name, too-many-arguments
42+
# pylint: disable=too-many-arguments
4343
""" A sparkline graph.
4444
4545
: param width: Width of the sparkline graph in pixels
4646
: param height: Height of the sparkline graph in pixels
4747
: param max_items: Maximum number of values housed in the sparkline
48-
: param yMin: Lower range for the y-axis. Set to None for autorange.
49-
: param yMax: Upper range for the y-axis. Set to None for autorange.
48+
: param y_min: Lower range for the y-axis. Set to None for autorange.
49+
: param y_max: Upper range for the y-axis. Set to None for autorange.
5050
: param x: X-position on the screen, in pixels
5151
: param y: Y-position on the screen, in pixels
5252
: param color: Line color, the default value is 0xFFFFFF (WHITE)
@@ -57,8 +57,8 @@ def __init__(
5757
width,
5858
height,
5959
max_items,
60-
yMin=None, # None = autoscaling
61-
yMax=None, # None = autoscaling
60+
y_min=None, # None = autoscaling
61+
y_max=None, # None = autoscaling
6262
x=0,
6363
y=0,
6464
color=0xFFFFFF, # line color, default is WHITE
@@ -70,13 +70,13 @@ def __init__(
7070
self.color = color #
7171
self._max_items = max_items # maximum number of items in the list
7272
self._spark_list = [] # list containing the values
73-
self.yMin = yMin # minimum of y-axis (None: autoscale)
74-
self.yMax = yMax # maximum of y-axis (None: autoscale)
75-
self.yBottom = yMin
76-
# yBottom: The actual minimum value of the vertical scale, will be
73+
self.y_min = y_min # minimum of y-axis (None: autoscale)
74+
self.y_max = y_max # maximum of y-axis (None: autoscale)
75+
self.y_bottom = y_min
76+
# y_bottom: The actual minimum value of the vertical scale, will be
7777
# updated if autorange
78-
self.yTop = yMax
79-
# yTop: The actual minimum value of the vertical scale, will be
78+
self.y_top = y_max
79+
# y_top: The actual minimum value of the vertical scale, will be
8080
# updated if autorange
8181
self._x = x
8282
self._y = y
@@ -101,23 +101,23 @@ def add_value(self, value):
101101
# pylint: disable=no-else-return
102102
@staticmethod
103103
def _xintercept(
104-
x1, y1, x2, y2, horizontalY
104+
x1, y1, x2, y2, horizontal_y
105105
): # finds intercept of the line and a horizontal line at horizontalY
106106
slope = (y2 - y1) / (x2 - x1)
107107
b = y1 - slope * x1
108108

109-
if slope == 0 and y1 != horizontalY: # does not intercept horizontalY
109+
if slope == 0 and y1 != horizontal_y: # does not intercept horizontalY
110110
return None
111111
else:
112112
xint = (
113-
horizontalY - b
113+
horizontal_y - b
114114
) / slope # calculate the x-intercept at position y=horizontalY
115115
return int(xint)
116116

117-
def _plotLine(self, x1, last_value, x2, value, yBottom, yTop):
117+
def _plotLine(self, x1, last_value, x2, value, y_bottom, y_top):
118118

119-
y2 = int(self.height * (yTop - value) / (yTop - yBottom))
120-
y1 = int(self.height * (yTop - last_value) / (yTop - yBottom))
119+
y2 = int(self.height * (y_top - value) / (y_top - y_bottom))
120+
y1 = int(self.height * (y_top - last_value) / (y_top - y_bottom))
121121
self.append(Line(x1, y1, x2, y2, self.color)) # plot the line
122122

123123
# pylint: disable=invalid-name, too-many-branches, too-many-nested-blocks
@@ -128,15 +128,15 @@ def update(self):
128128
"""
129129

130130
# get the y range
131-
if self.yMin is None:
132-
self.yBottom = min(self._spark_list)
131+
if self.y_min is None:
132+
self.y_bottom = min(self._spark_list)
133133
else:
134-
self.yBottom = self.yMin
134+
self.y_bottom = self.y_min
135135

136-
if self.yMax is None:
137-
self.yTop = max(self._spark_list)
136+
if self.y_max is None:
137+
self.y_top = max(self._spark_list)
138138
else:
139-
self.yTop = self.yMax
139+
self.y_top = self.y_max
140140

141141
if len(self._spark_list) > 2:
142142
xpitch = self.width / (
@@ -155,29 +155,29 @@ def update(self):
155155

156156
# print("x1: {}, x2: {}".format(x1,x2))
157157

158-
if (self.yBottom <= last_value <= self.yTop) and (
159-
self.yBottom <= value <= self.yTop
158+
if (self.y_bottom <= last_value <= self.y_top) and (
159+
self.y_bottom <= value <= self.y_top
160160
): # both points are in range, plot the line
161161
self._plotLine(
162-
x1, last_value, x2, value, self.yBottom, self.yTop
162+
x1, last_value, x2, value, self.y_bottom, self.y_top
163163
)
164164

165165
else: # at least one point is out of range, clip one or both ends the line
166-
if ((last_value > self.yTop) and (value > self.yTop)) or (
167-
(last_value < self.yBottom) and (value < self.yBottom)
166+
if ((last_value > self.y_top) and (value > self.y_top)) or (
167+
(last_value < self.y_bottom) and (value < self.y_bottom)
168168
):
169169
# both points are on the same side out of range: don't draw anything
170170
pass
171171
else:
172-
xintBottom = self._xintercept(
173-
x1, last_value, x2, value, self.yBottom
172+
xint_bottom = self._xintercept(
173+
x1, last_value, x2, value, self.y_bottom
174174
) # get possible new x intercept points
175-
xintTop = self._xintercept(
176-
x1, last_value, x2, value, self.yTop
175+
xint_top = self._xintercept(
176+
x1, last_value, x2, value, self.y_top
177177
) # on the top and bottom of range
178178

179-
if (xintBottom is None) or (
180-
xintTop is None
179+
if (xint_bottom is None) or (
180+
xint_top is None
181181
): # out of range doublecheck
182182
pass
183183
else:
@@ -188,27 +188,27 @@ def update(self):
188188
adj_value = value
189189

190190
if value > last_value: # slope is positive
191-
if xintBottom >= x1: # bottom is clipped
192-
adj_x1 = xintBottom
193-
adj_last_value = self.yBottom # y1
194-
if xintTop <= x2: # top is clipped
195-
adj_x2 = xintTop
196-
adj_value = self.yTop # y2
191+
if xint_bottom >= x1: # bottom is clipped
192+
adj_x1 = xint_bottom
193+
adj_last_value = self.y_bottom # y1
194+
if xint_top <= x2: # top is clipped
195+
adj_x2 = xint_top
196+
adj_value = self.y_top # y2
197197
else: # slope is negative
198-
if xintTop >= x1: # top is clipped
199-
adj_x1 = xintTop
200-
adj_last_value = self.yTop # y1
201-
if xintBottom <= x2: # bottom is clipped
202-
adj_x2 = xintBottom
203-
adj_value = self.yBottom # y2
198+
if xint_top >= x1: # top is clipped
199+
adj_x1 = xint_top
200+
adj_last_value = self.y_top # y1
201+
if xint_bottom <= x2: # bottom is clipped
202+
adj_x2 = xint_bottom
203+
adj_value = self.y_bottom # y2
204204

205205
self._plotLine(
206206
adj_x1,
207207
adj_last_value,
208208
adj_x2,
209209
adj_value,
210-
self.yBottom,
211-
self.yTop,
210+
self.y_bottom,
211+
self.y_top,
212212
)
213213

214214
last_value = value # store value for the next iteration

examples/display_shapes_sparkline_simpletest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@
9898
# mySparkline1 uses a vertical y range between 0 to 10 and will contain a
9999
# maximum of 40 items
100100
mySparkline1 = Sparkline(
101-
width=chartWidth, height=chartHeight, max_items=40, yMin=0, yMax=10, x=0, y=0
101+
width=chartWidth, height=chartHeight, max_items=40, y_min=0, y_max=10, x=0, y=0
102102
)
103103

104104
# Create a group to hold the sparkline and append the sparkline into the

0 commit comments

Comments
 (0)