Skip to content

Commit 51c4fd2

Browse files
committed
logging logic improvement
1 parent 5f39933 commit 51c4fd2

File tree

4 files changed

+41
-23
lines changed

4 files changed

+41
-23
lines changed

circuitpython_uplot/logging.py

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ def __init__(
6363
self.points = []
6464
self.ticksx = np.array(ticksx)
6565
self.ticksy = np.array(ticksy)
66+
self._fill = fill
6667
if tick_pos:
6768
self._tickposx = plot._tickheightx
6869
self._tickposy = plot._tickheighty
@@ -82,42 +83,40 @@ def __init__(
8283
if limits is not None:
8384
self._limits = np.array(
8485
plot.transform(
85-
self.ymin, self.ymax, plot._newymin, plot._newymax, np.array(limits)
86+
self.ymin,
87+
self.ymax,
88+
plot._newymin,
89+
plot._newymax,
90+
np.array(limits),
8691
),
8792
dtype=np.int16,
8893
)
8994
plot._plot_palette[9] = limits_color
9095
else:
9196
self._limits = None
9297

93-
self.draw_points(plot, x, y, fill)
94-
95-
if plot._showticks:
96-
if plot._loggingfirst:
97-
self._draw_ticks(plot)
98-
plot._loggingfirst = False
99-
plot._showticks = False
98+
self.draw_points(plot, x, y)
10099

101100
def _draw_ticks(self, plot) -> None:
102101
"""
103102
Draw ticks in the plot area
104103
105104
"""
106105

107-
ticksxnorm = np.array(
106+
self._ticksxnorm = np.array(
108107
plot.transform(
109108
self.xmin, self.xmax, plot._newxmin, plot._newxmax, self.ticksx
110109
),
111110
dtype=np.int16,
112111
)
113-
ticksynorm = np.array(
112+
self._ticksynorm = np.array(
114113
plot.transform(
115114
self.ymin, self.ymax, plot._newymin, plot._newymax, self.ticksy
116115
),
117116
dtype=np.int16,
118117
)
119118

120-
for i, tick in enumerate(ticksxnorm):
119+
for i, tick in enumerate(self._ticksxnorm):
121120
draw_line(
122121
plot._plotbitmap,
123122
tick,
@@ -128,7 +127,7 @@ def _draw_ticks(self, plot) -> None:
128127
)
129128
if plot._showtext:
130129
plot.show_text(f"{self.ticksx[i]:.0f}", tick, plot._newymin, (0.5, 0.0))
131-
for i, tick in enumerate(ticksynorm):
130+
for i, tick in enumerate(self._ticksynorm):
132131
draw_line(
133132
plot._plotbitmap,
134133
plot._newxmin - self._tickposy,
@@ -155,7 +154,7 @@ def clear_plot(plot) -> None:
155154
0,
156155
)
157156

158-
def draw_points(self, plot: Plot, x: list, y: list, fill: bool = False) -> None:
157+
def draw_points(self, plot: Plot, x: list, y: list) -> None:
159158
"""
160159
Draws points in the plot
161160
:param Plot plot: plot object provided
@@ -164,12 +163,22 @@ def draw_points(self, plot: Plot, x: list, y: list, fill: bool = False) -> None:
164163
:param bool fill: parameter to fill the plot graphic. Defaults to False
165164
:return: None
166165
"""
166+
167167
self.clear_plot(plot)
168168
if self._limits:
169169
self._draw_limit_lines(plot)
170-
self.draw_new_lines(plot, x, y, fill)
170+
self.draw_new_lines(plot, x, y)
171+
if plot._showticks:
172+
if plot._loggingfirst:
173+
self._draw_ticks(plot)
174+
plot._loggingfirst = False
175+
plot._showticks = False
176+
177+
if plot._tickgrid:
178+
plot._draw_gridx(self._ticksxnorm)
179+
plot._draw_gridy(self._ticksynorm)
171180

172-
def draw_new_lines(self, plot: Plot, x: list, y: list, fill: bool = False) -> None:
181+
def draw_new_lines(self, plot: Plot, x: list, y: list) -> None:
173182
"""
174183
Draw the plot lines
175184
:param Plot plot: plot object provided
@@ -204,7 +213,8 @@ def draw_new_lines(self, plot: Plot, x: list, y: list, fill: bool = False) -> No
204213
ynorm[index + 1],
205214
self._line_index,
206215
)
207-
if fill:
216+
217+
if self._fill:
208218
for index, _ in enumerate(xnorm):
209219
draw_line(
210220
plot._plotbitmap,

examples/logging_animation.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@
1414

1515
# Drawing the graph
1616
my_plot = Plot(
17-
140,
18-
60,
19-
200,
20-
200,
21-
padding=25,
17+
5,
18+
5,
19+
480,
20+
300,
21+
padding=20,
2222
show_box=True,
2323
box_color=color.WHITE,
2424
)
@@ -29,6 +29,7 @@
2929
ticky_height=4,
3030
show_ticks=True,
3131
tickcolor=color.TEAL,
32+
tickgrid=True,
3233
showtext=True,
3334
)
3435

@@ -75,6 +76,7 @@
7576
line_color=color.BLUE,
7677
ticksx=[25, 50, 75, 100, 125, 150, 175, 200],
7778
ticksy=[25, 50, 75, 100],
79+
fill=False,
7880
)
7981

8082
# Showing the loggraph

examples/logging_fill.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#
33
# SPDX-License-Identifier: MIT
44

5+
import time
56
import displayio
67
import board
78
from circuitpython_uplot.plot import Plot, color
@@ -12,7 +13,6 @@
1213

1314
group = displayio.Group()
1415

15-
1616
palette = displayio.Palette(1)
1717
palette[0] = 0x000000
1818

@@ -78,3 +78,5 @@
7878
group.append(plot_2)
7979

8080
display.root_group = group
81+
82+
time.sleep(10)

examples/logging.py renamed to examples/logging_simple_test.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,15 @@
22
#
33
# SPDX-License-Identifier: MIT
44

5+
import time
56
import displayio
67
import terminalio
78
import board
89
from adafruit_display_text import label
910
from circuitpython_uplot.plot import Plot, color
1011
from circuitpython_uplot.logging import Logging
1112

13+
1214
# Setting up the display
1315
display = board.DISPLAY
1416

@@ -59,7 +61,7 @@
5961
g.append(plot_1)
6062

6163
display.root_group = g
62-
display.refresh()
64+
6365

6466
dist = 3
6567

@@ -75,3 +77,5 @@
7577
)
7678

7779
text_temperature.text = "{}C".format(temp_y[dist])
80+
81+
time.sleep(5)

0 commit comments

Comments
 (0)