Skip to content

Commit d1cfec3

Browse files
committed
adding annotations
1 parent 9196b56 commit d1cfec3

File tree

3 files changed

+90
-34
lines changed

3 files changed

+90
-34
lines changed

circuitpython_uplot/scatter.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,13 @@ class scatter:
2424
Main class to display different graphics
2525
"""
2626

27-
def __init__(self, plot, x, y, radius=3):
27+
def __init__(self, plot, x: any, y: any, radius: int = 3) -> None:
2828
"""
2929
30-
:param plot: Plot Object for the scatter to be drawn
30+
:param plot: Plot object for the scatter to be drawn
3131
:param x: x points coordinates
3232
:param y: y points coordinates
33-
:param radius: circle radius
33+
:param int radius: circle radius
3434
3535
"""
3636
plot._drawbox()

circuitpython_uplot/uplot.py

Lines changed: 86 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,12 @@
2121
2222
"""
2323

24+
try:
25+
from typing import Union
26+
from typing_extensions import Literal
27+
except ImportError:
28+
pass
29+
2430
import displayio
2531
from bitmaptools import draw_line
2632
from vectorio import Circle
@@ -36,10 +42,25 @@
3642

3743
class Uplot(displayio.Group):
3844
"""
39-
Main class to display different graphics
45+
Canvas Class to add different elements to the screen.
46+
The origin point set by ``x`` and ``y`` properties
47+
48+
:param int x: origin x coordinate
49+
:param int y: origin y coordinate
50+
:param int width: plot box width in pixels
51+
:param int height: plot box height in pixels
52+
:param int padding: padding for the plot box in all directions
53+
4054
"""
4155

42-
def __init__(self, x=0, y=0, width=None, height=None, padding=15):
56+
def __init__(
57+
self,
58+
x: int = 0,
59+
y: int = 0,
60+
width: int = 100,
61+
height: int = 100,
62+
padding: int = 15,
63+
) -> None:
4364
super().__init__(x=x, y=y, scale=1)
4465
np.set_printoptions(threshold=200)
4566

@@ -73,17 +94,24 @@ def __init__(self, x=0, y=0, width=None, height=None, padding=15):
7394
)
7495
)
7596

76-
def axs_params(self, axstype="box"):
97+
def axs_params(self, axstype: Literal["box", "cartesian", "line"] = "box") -> None:
7798
"""
7899
Setting up axs visibility
79100
80-
:param axs: argument with the kind of axs you selected
81-
:return: none
101+
:param axstype: argument with the kind of axs you selected
102+
:return: None
82103
83104
"""
84105
self._axesparams = axstype
85106

86107
def _drawbox(self):
108+
"""
109+
Draw the plot box
110+
111+
:return: None
112+
113+
"""
114+
87115
if self._axesparams == "cartesian":
88116
draw_box = [True, True, False, False]
89117
elif self._axesparams == "line":
@@ -129,40 +157,52 @@ def _drawbox(self):
129157
1,
130158
)
131159

132-
def draw_circle(self, radius=5, x=100, y=100):
160+
def draw_circle(self, radius: int = 5, x: int = 100, y: int = 100) -> None:
133161
"""
134162
Draw a circle in the plot area
135-
:param radius: circle radius
136-
:param x: circles center x coordinate position in pixels, Defaults to 100.
137-
:param y: circles center y coordinate position in pixels. Defaults to 100.
163+
164+
:param int radius: circle radius
165+
:param int x: circles center x coordinate position in pixels, Defaults to 100.
166+
:param int y: circles center y coordinate position in pixels. Defaults to 100.
167+
138168
:return: None
169+
139170
"""
140171
palette = displayio.Palette(1)
141172
palette[0] = 0xFFFFFF
142173
self.append(Circle(pixel_shader=palette, radius=radius, x=x, y=y))
143174

144175
@staticmethod
145-
def normalize(oldrangemin, oldrangemax, newrangemin, newrangemax, value):
176+
def normalize(
177+
oldrangemin: Union[float, int],
178+
oldrangemax: Union[float, int],
179+
newrangemin: Union[float, int],
180+
newrangemax: Union[float, int],
181+
value: Union[float, int],
182+
) -> Union[float, int]:
146183
"""
147184
This function converts the original value into a new defined value in the new range
148-
:param oldrangemin: minimum of the original range
149-
:param oldrangemax: maximum of the original range
150-
:param newrangemin: minimum of the new range
151-
:param newrangemax: maximum of the new range
152-
:param value: value to be converted
153-
:return: converted value
185+
186+
:param int|float oldrangemin: minimum of the original range
187+
:param int|float oldrangemax: maximum of the original range
188+
:param int|float newrangemin: minimum of the new range
189+
:param int|float newrangemax: maximum of the new range
190+
:param int|float value: value to be converted
191+
:return int|float: converted value
192+
154193
"""
194+
155195
return (
156196
((value - oldrangemin) * (newrangemax - newrangemin))
157197
/ (oldrangemax - oldrangemin)
158198
) + newrangemin
159199

160-
def draw_plot(self, x, y):
200+
def draw_plot(self, x: int, y: int) -> None:
161201
"""
162202
Function to draw the plot
163203
164-
:param x: data for x points
165-
:param y: data for y points
204+
:param int x: data for x points
205+
:param int y: data for y points
166206
:return: None
167207
168208
"""
@@ -195,13 +235,16 @@ def draw_plot(self, x, y):
195235
if self._showticks:
196236
self._draw_ticks(x, y)
197237

198-
def _draw_ticks(self, x, y):
238+
def _draw_ticks(self, x: int, y: int) -> None:
199239
"""
200240
Draw ticks in the plot area
201241
202-
:return:
242+
:param int x: x coord
243+
:param int y: y coord
244+
:return:None
203245
204246
"""
247+
205248
ticks = np.array([10, 30, 50, 70, 90])
206249
subticks = np.array([20, 40, 60, 80])
207250
ticksxnorm = np.array(self.normalize(0, 100, np.min(x), np.max(x), ticks))
@@ -276,13 +319,15 @@ def _draw_ticks(self, x, y):
276319
self._draw_gridx(ticksxrenorm)
277320
self._draw_gridy(ticksyrenorm)
278321

279-
def tick_params(self, tickheight=8, tickcolor=0xFFFFFF, tickgrid=False):
322+
def tick_params(
323+
self, tickheight: int = 8, tickcolor: int = 0xFFFFFF, tickgrid: bool = False
324+
) -> None:
280325
"""
281326
Function to set ticks parameters
282327
283-
:param tickheight:
284-
:param tickcolor:
285-
328+
:param int tickheight: tick height in pixels
329+
:param int tickcolor: tick color in hex
330+
:param bool tickgrid: defines if the grid is to be shown
286331
:return: None
287332
288333
"""
@@ -292,10 +337,10 @@ def tick_params(self, tickheight=8, tickcolor=0xFFFFFF, tickgrid=False):
292337
self._plot_palette[2] = tickcolor
293338
self._tickgrid = tickgrid
294339

295-
def _draw_gridx(self, ticks_data):
340+
def _draw_gridx(self, ticks_data: list[int]) -> None:
296341
"""
297-
draw plot grid
298-
342+
Draws the plot grid
343+
:param list[int] ticks_data: ticks data information
299344
:return: None
300345
301346
"""
@@ -314,10 +359,10 @@ def _draw_gridx(self, ticks_data):
314359
)
315360
start = start - grid_espace - line_lenght
316361

317-
def _draw_gridy(self, ticks_data):
362+
def _draw_gridy(self, ticks_data: list[int]) -> None:
318363
"""
319-
draw plot grid
320-
364+
Draws plot grid in the y axs
365+
:param list[int] ticks_data: ticks data information
321366
:return: None
322367
323368
"""
@@ -335,3 +380,13 @@ def _draw_gridy(self, ticks_data):
335380
2,
336381
)
337382
start = start + grid_espace + line_lenght
383+
384+
def update_plot(self) -> None:
385+
"""
386+
Function to update graph
387+
388+
:return: None
389+
390+
"""
391+
392+
self._drawbox()

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@
44
# SPDX-License-Identifier: MIT
55

66
Adafruit-Blinka
7+
typing-extensions~=4.0

0 commit comments

Comments
 (0)