|
92 | 92 | ##########################################
|
93 | 93 |
|
94 | 94 | # Baseline size of the sparkline chart, in pixels.
|
95 |
| -chartWidth = display.width - 50 |
96 |
| -chartHeight = display.height - 50 |
| 95 | +chart_width = display.width - 50 |
| 96 | +chart_height = display.height - 50 |
97 | 97 |
|
98 | 98 | font = terminalio.FONT
|
99 | 99 |
|
100 |
| -lineColor = 0xFFFFFF |
| 100 | +line_color = 0xFFFFFF |
101 | 101 |
|
102 | 102 | # Setup the first bitmap and sparkline
|
103 | 103 | # This sparkline has no background bitmap
|
104 | 104 | # mySparkline1 uses a vertical y range between 0 to 10 and will contain a
|
105 | 105 | # maximum of 40 items
|
106 |
| -mySparkline1 = Sparkline( |
107 |
| - width=chartWidth, |
108 |
| - height=chartHeight, |
| 106 | +sparkline1 = Sparkline( |
| 107 | + width=chart_width, |
| 108 | + height=chart_height, |
109 | 109 | max_items=40,
|
110 |
| - yMin=0, |
111 |
| - yMax=10, |
| 110 | + y_min=0, |
| 111 | + y_max=10, |
112 | 112 | x=40,
|
113 | 113 | y=30,
|
114 |
| - color=lineColor, |
| 114 | + color=line_color, |
115 | 115 | )
|
116 | 116 |
|
117 | 117 | # Label the y-axis range
|
118 | 118 |
|
119 |
| -textXOffset = -10 |
120 |
| -textLabel1a = label.Label( |
121 |
| - font=font, text=str(mySparkline1.yTop), color=lineColor |
| 119 | +text_xoffset = -10 |
| 120 | +text_label1a = label.Label( |
| 121 | + font=font, text=str(sparkline1.y_top), color=line_color |
122 | 122 | ) # yTop label
|
123 |
| -textLabel1a.anchor_point = (1, 0.5) # set the anchorpoint at right-center |
124 |
| -textLabel1a.anchored_position = ( |
125 |
| - mySparkline1.x + textXOffset, |
126 |
| - mySparkline1.y, |
| 123 | +text_label1a.anchor_point = (1, 0.5) # set the anchorpoint at right-center |
| 124 | +text_label1a.anchored_position = ( |
| 125 | + sparkline1.x + text_xoffset, |
| 126 | + sparkline1.y, |
127 | 127 | ) # set the text anchored position to the upper right of the graph
|
128 | 128 |
|
129 |
| -textLabel1b = label.Label( |
130 |
| - font=font, text=str(mySparkline1.yBottom), color=lineColor |
| 129 | +text_label1b = label.Label( |
| 130 | + font=font, text=str(sparkline1.y_bottom), color=line_color |
131 | 131 | ) # yTop label
|
132 |
| -textLabel1b.anchor_point = (1, 0.5) # set the anchorpoint at right-center |
133 |
| -textLabel1b.anchored_position = ( |
134 |
| - mySparkline1.x + textXOffset, |
135 |
| - mySparkline1.y + chartHeight, |
| 132 | +text_label1b.anchor_point = (1, 0.5) # set the anchorpoint at right-center |
| 133 | +text_label1b.anchored_position = ( |
| 134 | + sparkline1.x + text_xoffset, |
| 135 | + sparkline1.y + chart_height, |
136 | 136 | ) # set the text anchored position to the upper right of the graph
|
137 | 137 |
|
138 | 138 |
|
139 |
| -boundingRectangle = Rect( |
140 |
| - mySparkline1.x, mySparkline1.y, chartWidth + 1, chartHeight + 1, outline=lineColor |
| 139 | +bounding_rectangle = Rect( |
| 140 | + sparkline1.x, sparkline1.y, chart_width + 1, chart_height + 1, outline=line_color |
141 | 141 | )
|
142 | 142 |
|
143 | 143 |
|
144 | 144 | # Create a group to hold the sparkline, text, rectangle and tickmarks
|
145 |
| -# append them into the group (myGroup) |
| 145 | +# append them into the group (my_group) |
146 | 146 | #
|
147 | 147 | # Note: In cases where display elements will overlap, then the order the
|
148 | 148 | # elements are added to the group will set which is on top. Latter elements
|
149 | 149 | # are displayed on top of former elemtns.
|
150 | 150 |
|
151 |
| -myGroup = displayio.Group(max_size=20) |
| 151 | +my_group = displayio.Group(max_size=20) |
152 | 152 |
|
153 |
| -myGroup.append(mySparkline1) |
154 |
| -myGroup.append(textLabel1a) |
155 |
| -myGroup.append(textLabel1b) |
156 |
| -myGroup.append(boundingRectangle) |
| 153 | +my_group.append(sparkline1) |
| 154 | +my_group.append(text_label1a) |
| 155 | +my_group.append(text_label1b) |
| 156 | +my_group.append(bounding_rectangle) |
157 | 157 |
|
158 |
| -totalTicks = 10 |
| 158 | +total_ticks = 10 |
159 | 159 |
|
160 |
| -for i in range(totalTicks + 1): |
161 |
| - xStart = mySparkline1.x - 5 |
162 |
| - xEnd = mySparkline1.x |
163 |
| - yBoth = mySparkline1.y + i * int(round(chartHeight / (totalTicks))) |
164 |
| - myGroup.append(Line(xStart, yBoth, xEnd, yBoth, color=lineColor)) |
165 |
| -myGroup.append( |
| 160 | +for i in range(total_ticks + 1): |
| 161 | + x_start = sparkline1.x - 5 |
| 162 | + x_end = sparkline1.x |
| 163 | + y_both = sparkline1.y + i * int(round(chart_height / (total_ticks))) |
| 164 | + my_group.append(Line(x_start, y_both, x_end, y_both, color=line_color)) |
| 165 | +my_group.append( |
166 | 166 | Line(
|
167 |
| - xStart, |
168 |
| - mySparkline1.y + chartHeight, |
169 |
| - xEnd, |
170 |
| - mySparkline1.y + chartHeight, |
171 |
| - color=lineColor, |
| 167 | + x_start, |
| 168 | + sparkline1.y + chart_height, |
| 169 | + x_end, |
| 170 | + sparkline1.y + chart_height, |
| 171 | + color=line_color, |
172 | 172 | )
|
173 | 173 | )
|
174 | 174 |
|
175 |
| -# Set the display to show myGroup that contains the sparkline and other graphics |
176 |
| -display.show(myGroup) |
| 175 | +# Set the display to show my_group that contains the sparkline and other graphics |
| 176 | +display.show(my_group) |
177 | 177 |
|
178 | 178 | # Start the main loop
|
179 | 179 | while True:
|
|
185 | 185 | # add_value: add a new value to a sparkline
|
186 | 186 | # Note: The y-range for mySparkline1 is set to 0 to 10, so all these random
|
187 | 187 | # values (between 0 and 10) will fit within the visible range of this sparkline
|
188 |
| - mySparkline1.add_value(random.uniform(0, 10)) |
| 188 | + sparkline1.add_value(random.uniform(0, 10)) |
189 | 189 |
|
190 | 190 | # Turn on auto_refresh for the display
|
191 | 191 | display.auto_refresh = True
|
|
0 commit comments