Skip to content

Commit e8243db

Browse files
committed
changing imports to save memory
1 parent 011c9b3 commit e8243db

File tree

1 file changed

+26
-13
lines changed

1 file changed

+26
-13
lines changed

circuitpython_uplot/uplot.py

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
import terminalio
3232
from bitmaptools import draw_line
3333
from vectorio import Circle
34-
from adafruit_display_text import bitmap_label
3534
from ulab import numpy as np
3635

3736

@@ -41,6 +40,9 @@
4140

4241
# pylint: disable=too-many-arguments, too-many-instance-attributes, too-many-locals
4342
# pylint: disable=too-many-statements
43+
# pylint: disable=unused-import, import-outside-toplevel, undefined-variable
44+
45+
4446
class Uplot(displayio.Group):
4547
"""
4648
Canvas Class to add different elements to the screen.
@@ -99,6 +101,8 @@ def __init__(
99101

100102
self._cartesianfirst = True
101103

104+
self._showtext = False
105+
102106
self._tickheight = 8
103107
self._tickcolor = 0xFFFFFF
104108
self._showticks = False
@@ -296,9 +300,10 @@ def _draw_ticks(self, x: int, y: int) -> None:
296300
self._newymin - self._tickheight,
297301
2,
298302
)
299-
self.show_text(
300-
"{:.2f}".format(ticksxnorm[i]), tick, self._newymin, (0.5, 0.0)
301-
)
303+
if self._showtext:
304+
self.show_text(
305+
"{:.2f}".format(ticksxnorm[i]), tick, self._newymin, (0.5, 0.0)
306+
)
302307
for i, tick in enumerate(ticksyrenorm):
303308
draw_line(
304309
self._plotbitmap,
@@ -308,9 +313,10 @@ def _draw_ticks(self, x: int, y: int) -> None:
308313
tick,
309314
2,
310315
)
311-
self.show_text(
312-
"{:.2f}".format(ticksynorm[i]), self._newxmin, tick, (1.0, 0.5)
313-
)
316+
if self._showtext:
317+
self.show_text(
318+
"{:.2f}".format(ticksynorm[i]), self._newxmin, tick, (1.0, 0.5)
319+
)
314320
for tick in subticksxrenorm:
315321
draw_line(
316322
self._plotbitmap,
@@ -335,7 +341,11 @@ def _draw_ticks(self, x: int, y: int) -> None:
335341
self._draw_gridy(ticksyrenorm)
336342

337343
def tick_params(
338-
self, tickheight: int = 8, tickcolor: int = 0xFFFFFF, tickgrid: bool = False
344+
self,
345+
tickheight: int = 8,
346+
tickcolor: int = 0xFFFFFF,
347+
tickgrid: bool = False,
348+
showtext: bool = False,
339349
) -> None:
340350
"""
341351
Function to set ticks parameters
@@ -352,6 +362,9 @@ def tick_params(
352362
self._tickheight = tickheight
353363
self._plot_palette[2] = tickcolor
354364
self._tickgrid = tickgrid
365+
self._showtext = showtext
366+
if self._showtext:
367+
from adafruit_display_text import bitmap_label
355368

356369
def _draw_gridx(self, ticks_data: list[int]) -> None:
357370
"""
@@ -419,8 +432,8 @@ def show_text(
419432
:param Tuple anchorpoint: Display_text anchor point. Defaults to (0.5, 0.0)
420433
:return: None
421434
"""
422-
423-
text_toplot = bitmap_label.Label(terminalio.FONT, text=text, x=x, y=y)
424-
text_toplot.anchor_point = anchorpoint
425-
text_toplot.anchored_position = (x, y)
426-
self.append(text_toplot)
435+
if self._showtext:
436+
text_toplot = bitmap_label.Label(terminalio.FONT, text=text, x=x, y=y)
437+
text_toplot.anchor_point = anchorpoint
438+
text_toplot.anchored_position = (x, y)
439+
self.append(text_toplot)

0 commit comments

Comments
 (0)