Skip to content

Commit 011c9b3

Browse files
committed
adding ubar text
1 parent 1aea14f commit 011c9b3

File tree

3 files changed

+40
-2
lines changed

3 files changed

+40
-2
lines changed

circuitpython_uplot/ubar.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,11 @@ def __init__(
6464
color_index=plot._index_colorused,
6565
)
6666
)
67+
plot.show_text(
68+
str(y[i]),
69+
xstart + (i * self._graphx) + self._graphx // 2,
70+
plot._newymin,
71+
)
6772
xstart = xstart + bar_space
6873
plot._index_colorused = plot._index_colorused + 1
6974
else:
@@ -79,6 +84,11 @@ def __init__(
7984
)
8085
xstart = xstart + bar_space
8186
plot._index_colorused = plot._index_colorused + 1
87+
plot.show_text(
88+
str(y[i]),
89+
xstart + (i * self._graphx) - bar_space + self._graphx // 2,
90+
plot._newymin,
91+
)
8292

8393
def _draw_rectangle(
8494
self, plot: Uplot, x: int, y: int, width: int, height: int, color: int

circuitpython_uplot/uplot.py

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,16 @@
2222
"""
2323

2424
try:
25-
from typing import Union
25+
from typing import Union, Tuple
2626
from typing_extensions import Literal
2727
except ImportError:
2828
pass
2929

3030
import displayio
31+
import terminalio
3132
from bitmaptools import draw_line
3233
from vectorio import Circle
34+
from adafruit_display_text import bitmap_label
3335
from ulab import numpy as np
3436

3537

@@ -142,6 +144,7 @@ def axs_params(self, axstype: Literal["box", "cartesian", "line"] = "box") -> No
142144
Setting up axs visibility
143145
144146
:param axstype: argument with the kind of axs you selected
147+
145148
:return: None
146149
147150
"""
@@ -231,6 +234,7 @@ def transform(
231234
:param int|float newrangemin: minimum of the new range
232235
:param int|float newrangemax: maximum of the new range
233236
:param int|float value: value to be converted
237+
234238
:return int|float: converted value
235239
236240
"""
@@ -246,6 +250,7 @@ def _draw_ticks(self, x: int, y: int) -> None:
246250
247251
:param int x: x coord
248252
:param int y: y coord
253+
249254
:return:None
250255
251256
"""
@@ -338,6 +343,7 @@ def tick_params(
338343
:param int tickheight: tick height in pixels
339344
:param int tickcolor: tick color in hex
340345
:param bool tickgrid: defines if the grid is to be shown
346+
341347
:return: None
342348
343349
"""
@@ -350,7 +356,9 @@ def tick_params(
350356
def _draw_gridx(self, ticks_data: list[int]) -> None:
351357
"""
352358
Draws the plot grid
359+
353360
:param list[int] ticks_data: ticks data information
361+
354362
:return: None
355363
356364
"""
@@ -370,7 +378,9 @@ def _draw_gridx(self, ticks_data: list[int]) -> None:
370378
def _draw_gridy(self, ticks_data: list[int]) -> None:
371379
"""
372380
Draws plot grid in the y axs
381+
373382
:param list[int] ticks_data: ticks data information
383+
374384
:return: None
375385
376386
"""
@@ -396,3 +406,21 @@ def update_plot(self) -> None:
396406
"""
397407

398408
self._drawbox()
409+
410+
def show_text(
411+
self, text: str, x: int, y: int, anchorpoint: Tuple = (0.5, 0.0)
412+
) -> None:
413+
"""
414+
415+
Show desired text in the scree
416+
:param str text: text to be displayed
417+
:param int x: x coordinate
418+
:param int y: y coordinate
419+
:param Tuple anchorpoint: Display_text anchor point. Defaults to (0.5, 0.0)
420+
:return: None
421+
"""
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)

docs/conf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
# Uncomment the below if you use native CircuitPython modules such as
2626
# digitalio, micropython and busio. List the modules you use. Without it, the
2727
# autodoc module docs will fail to generate with a warning.
28-
autodoc_mock_imports = ["displayio", "bitmaptools", "vectorio", "ulab"]
28+
autodoc_mock_imports = ["displayio", "bitmaptools", "vectorio", "ulab", "terminalio"]
2929

3030
autodoc_preserve_defaults = True
3131

0 commit comments

Comments
 (0)