Skip to content

Commit 40d317a

Browse files
committed
adding logging fill feature
1 parent a8eeaea commit 40d317a

File tree

5 files changed

+107
-1
lines changed

5 files changed

+107
-1
lines changed

circuitpython_uplot/ulogging.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626

2727

2828
# pylint: disable=too-many-arguments, invalid-name, no-self-use, too-few-public-methods
29-
# pylint: disable=too-many-locals, too-many-branches, protected-access
29+
# pylint: disable=too-many-locals, too-many-branches, protected-access, unnecessary-list-index-lookup
3030
class ulogging:
3131
"""
3232
Class to log data
@@ -42,6 +42,7 @@ def __init__(
4242
line_color: int = 0xFFFFFF,
4343
ticksx: Union[np.array, list] = np.array([0, 10, 30, 50, 70, 90]),
4444
ticksy: Union[np.array, list] = np.array([0, 10, 30, 50, 70, 90]),
45+
fill: bool = False,
4546
) -> None:
4647
"""
4748
@@ -53,6 +54,7 @@ def __init__(
5354
:param int|None line_color: line color. Defaults to None
5455
:param np.array|list ticksx: X axis ticks values
5556
:param np.array|list ticksy: Y axis ticks values
57+
:param bool fill: enable the filling of the plot. Defaults to ``False``
5658
5759
"""
5860
self.points = []
@@ -101,6 +103,17 @@ def __init__(
101103
ynorm[index + 1],
102104
plot._index_colorused,
103105
)
106+
if fill:
107+
for index, _ in enumerate(xnorm):
108+
draw_line(
109+
plot._plotbitmap,
110+
xnorm[index],
111+
ynorm[index],
112+
xnorm[index],
113+
plot._newymin,
114+
plot._index_colorused,
115+
)
116+
104117
if plot._showticks:
105118
if plot._loggingfirst:
106119
self._draw_ticks(plot)

docs/examples.rst

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,3 +168,13 @@ Logging example
168168
.. literalinclude:: ../examples/uplot_ulogging.py
169169
:caption: examples/uplot_ulogging.py
170170
:linenos:
171+
172+
Logging Fill Example
173+
---------------------------
174+
175+
Logging fill example
176+
177+
.. literalinclude:: ../examples/uplot_logging_fill.py
178+
:caption: examples/uplot_logging_fill.py
179+
:linenos:
180+
.. image:: ../docs/uplot_ex22.jpg

docs/uplot_ex22.jpg

18.9 KB
Loading

docs/uplot_ex22.jpg.license

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
SPDX-FileCopyrightText: 2023 Jose David M.
2+
3+
SPDX-License-Identifier: MIT

examples/uplot_logging_fill.py

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
# SPDX-FileCopyrightText: Copyright (c) Jose D. Montoya
2+
#
3+
# SPDX-License-Identifier: MIT
4+
5+
import displayio
6+
import board
7+
from circuitpython_uplot.uplot import Uplot, color
8+
from circuitpython_uplot.ulogging import ulogging
9+
10+
# Setting up the display
11+
display = board.DISPLAY
12+
13+
group = displayio.Group()
14+
15+
16+
palette = displayio.Palette(1)
17+
palette[0] = 0x000000
18+
19+
plot_1 = Uplot(
20+
0,
21+
0,
22+
150,
23+
60,
24+
padding=1,
25+
show_box=True,
26+
box_color=color.BLACK,
27+
background_color=color.TEAL,
28+
scale=2,
29+
)
30+
31+
plot_1.tick_params(
32+
tickx_height=4, ticky_height=4, show_ticks=True, tickcolor=color.BLACK
33+
)
34+
35+
plot_2 = Uplot(
36+
0,
37+
150,
38+
300,
39+
120,
40+
padding=1,
41+
show_box=True,
42+
box_color=color.BLACK,
43+
background_color=color.YELLOW,
44+
scale=1,
45+
)
46+
47+
plot_2.tick_params(
48+
tickx_height=4, ticky_height=4, show_ticks=True, tickcolor=color.BLACK
49+
)
50+
51+
x = [10, 20, 30, 40, 50]
52+
temp_y = [26, 25, 24, 23, 28]
53+
54+
ulogging(
55+
plot_1,
56+
x,
57+
temp_y,
58+
rangex=[0, 200],
59+
rangey=[0, 50],
60+
line_color=color.BLACK,
61+
ticksx=[10, 50, 80, 100],
62+
ticksy=[15, 30, 45, 60],
63+
fill=True,
64+
)
65+
ulogging(
66+
plot_2,
67+
x,
68+
temp_y,
69+
rangex=[0, 200],
70+
rangey=[0, 50],
71+
line_color=color.BLACK,
72+
ticksx=[10, 50, 80, 100],
73+
ticksy=[15, 30, 45, 60],
74+
fill=True,
75+
)
76+
77+
group.append(plot_1)
78+
group.append(plot_2)
79+
80+
display.show(group)

0 commit comments

Comments
 (0)