|
4 | 4 | # See the bottom for a code example using the `sparkline` Class.
|
5 | 5 |
|
6 | 6 | # # 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 |
| 8 | +# using `add_value` are plotted. |
8 | 9 | #
|
9 |
| -# The `sparkline` class creates an element suitable for adding to the display using `display.show(mySparkline)` |
10 |
| -# or adding to a `displayio.Group` to be displayed. |
| 10 | +# The `sparkline` class creates an element suitable for adding to the display |
| 11 | +# using `display.show(mySparkline)` or adding to a `displayio.Group` to be displayed. |
11 | 12 | #
|
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. |
| 13 | +# When creating the sparkline, identify the number of `max_items` that will be |
| 14 | +# included in the graph. |
| 15 | +# When additional elements are added to the sparkline and the number of items |
| 16 | +# has exceeded max_items, any excess values are removed from the left of the |
| 17 | +# graph, and new values are added to the right. |
15 | 18 |
|
16 | 19 |
|
17 | 20 | # The following is an example that shows the
|
|
23 | 26 | # add new values to sparkline `add_value`
|
24 | 27 | # update the sparklines `update`
|
25 | 28 |
|
| 29 | +import random |
| 30 | +import time |
26 | 31 | import board
|
27 | 32 | import displayio
|
28 | 33 | import terminalio
|
29 |
| -import random |
30 |
| -import time |
31 | 34 | from adafruit_display_shapes.sparkline import Sparkline
|
32 | 35 | from adafruit_ili9341 import ILI9341
|
33 | 36 | from adafruit_display_text import label
|
|
75 | 78 | display_bus,
|
76 | 79 | width=DISPLAY_WIDTH,
|
77 | 80 | height=DISPLAY_HEIGHT,
|
78 |
| - rotation=180, # The rotation can be adjusted to match your configuration. |
| 81 | + rotation=180, # The rotation can be adjusted to match your configuration. |
79 | 82 | auto_refresh=True,
|
80 | 83 | native_frames_per_second=90,
|
81 | 84 | )
|
|
124 | 127 |
|
125 | 128 |
|
126 | 129 | # Setup the second bitmap and sparkline
|
127 |
| -# mySparkline2 uses a vertical y range between 0 to 1, and will contain a maximum of 10 items |
| 130 | +# mySparkline2 uses a vertical y range between 0 to 1, and will contain a |
| 131 | +# maximum of 10 items |
128 | 132 | #
|
129 | 133 | palette2 = displayio.Palette(1) # color palette used for bitmap2 (one color)
|
130 | 134 | palette2[0] = 0x0000FF
|
|
147 | 151 |
|
148 | 152 | # Setup the third bitmap and third sparkline
|
149 | 153 | # mySparkline3 contains a maximum of 10 items
|
150 |
| -# since yMin and yMax are not specified, mySparkline3 uses autoranging for both the top and bottom of the y-axis. |
151 |
| -# Note1: Any unspecified edge limit (yMin or yMax) will autorange that edge based on the data in the list. |
152 |
| -# Note2: You can read back the value of the y-axis limits by using mySparkline3.yBottom or mySparkline3.yTop |
| 154 | +# since yMin and yMax are not specified, mySparkline3 uses autoranging for both |
| 155 | +# the top and bottom of the y-axis. |
| 156 | +# Note1: Any unspecified edge limit (yMin or yMax) will autorange that edge based |
| 157 | +# on the data in the list. |
| 158 | +# Note2: You can read back the value of the y-axis limits by using |
| 159 | +# mySparkline3.yBottom or mySparkline3.yTop |
153 | 160 |
|
154 | 161 |
|
155 | 162 | palette3 = displayio.Palette(1) # color palette used for bitmap (one color)
|
|
187 | 194 | 120 + mySparkline3.height,
|
188 | 195 | ) # set the text anchored position to the upper right of the graph
|
189 | 196 |
|
190 |
| - |
191 | 197 | # Create a group to hold the three bitmap TileGrids and the three sparklines and
|
192 | 198 | # append them into the group (myGroup)
|
193 | 199 | #
|
194 |
| -# Note: In cases where display elements will overlap, then the order the elements are added to the |
195 |
| -# group will set which is on top. Latter elements are displayed on top of former elemtns. |
| 200 | +# Note: In cases where display elements will overlap, then the order the elements |
| 201 | +# are added to the group will set which is on top. Latter elements are displayed |
| 202 | +# on top of former elemtns. |
196 | 203 | myGroup = displayio.Group(max_size=20)
|
197 | 204 |
|
198 | 205 | myGroup.append(mySparkline1)
|
|
207 | 214 | myGroup.append(textLabel3a)
|
208 | 215 | myGroup.append(textLabel3b)
|
209 | 216 |
|
210 |
| -# Set the display to show myGroup that contains all the bitmap TileGrids and sparklines |
| 217 | +# Set the display to show myGroup that contains all the bitmap TileGrids and |
| 218 | +# sparklines |
211 | 219 | display.show(myGroup)
|
212 | 220 |
|
213 | 221 | i = 0 # This is a counter for changing the random values for mySparkline3
|
|
227 | 235 | # Note: For mySparkline2, the y-axis range is set from 0 to 1.
|
228 | 236 | # With the random values set between -1 and +2, the values will sometimes
|
229 | 237 | # be out of the y-range. This example shows how the fixed y-range (0 to 1)
|
230 |
| - # will "clip" values (it will not display them) that are above or below the y-range. |
| 238 | + # will "clip" values (it will not display them) that are above or below the |
| 239 | + # y-range. |
231 | 240 | mySparkline2.add_value(random.uniform(-1, 2))
|
232 | 241 |
|
233 | 242 | # mySparkline3 is set autoranging for the top and bottom of the Y-axis
|
|
0 commit comments