Skip to content

Commit 64b75e1

Browse files
authored
Merge pull request #84 from jposada202020/updating_cartesian_widget
Updating cartesian widget
2 parents c7f30ee + a84c96c commit 64b75e1

File tree

2 files changed

+31
-105
lines changed

2 files changed

+31
-105
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,67 +1,3 @@
11
# SPDX-FileCopyrightText: 2021 Kevin Matocha, Tim C, Jose David M
22
#
33
# SPDX-License-Identifier: MIT
4-
5-
"""
6-
`adafruit_displayio_layout.widgets`
7-
=======================
8-
"""
9-
10-
try:
11-
import vectorio
12-
except ImportError:
13-
pass
14-
15-
try:
16-
import bitmaptools
17-
except ImportError:
18-
pass
19-
20-
21-
# pylint: disable=invalid-name, too-many-arguments
22-
def rectangle_helper(
23-
x0: int,
24-
y0: int,
25-
height: int,
26-
width: int,
27-
bitmap,
28-
color_index: int,
29-
palette,
30-
bitmaptool: bool = True,
31-
) -> None:
32-
"""rectangle_helper function
33-
Draws a rectangle to the bitmap given using ``bitmapstools.bitmap`` or
34-
``vectorio.rectangle`` functions
35-
36-
:param int x0: rectangle lower corner x position
37-
:param int y0: rectangle lower corner y position
38-
39-
:param int width: rectangle upper corner x position
40-
:param int height: rectangle upper corner y position
41-
42-
:param int color_index: palette color index to be used
43-
:param palette: palette object to be used to draw the rectangle
44-
45-
:param bitmap: bitmap for the rectangle to be drawn
46-
:param bool bitmaptool: uses :py:func:`~bitmaptools.draw_line` to draw the rectanlge.
47-
when `False` uses :py:func:`~vectorio.Rectangle`
48-
49-
:return: None
50-
:rtype: None
51-
52-
┌───────────────────────┐
53-
│ │
54-
│ │
55-
(x0,y0) └───────────────────────┘
56-
57-
"""
58-
if bitmaptool:
59-
bitmaptools.fill_region(bitmap, x0, y0, x0 + width, y0 + height, color_index)
60-
else:
61-
rect = vectorio.Rectangle(width, height)
62-
vectorio.VectorShape(
63-
shape=rect,
64-
pixel_shader=palette,
65-
x=x0,
66-
y=y0,
67-
)

adafruit_displayio_layout/widgets/cartesian.py

+31-41
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
from adafruit_display_text import bitmap_label
3030
import vectorio
3131
from adafruit_displayio_layout.widgets.widget import Widget
32-
from adafruit_displayio_layout.widgets import rectangle_helper
3332

3433
try:
3534
import bitmaptools
@@ -138,7 +137,7 @@ class Cartesian(Widget):
138137
139138
- **range**: ``xrange`` and ``yrange`` This is the range in absolute units.
140139
For example, when using (20-90), the X axis will start at 20 finishing at 90.
141-
However the height of the graph is given by the height parameter. The scale
140+
However, the height of the graph is given by the height parameter. The scale
142141
is handled internal to provide a 1:1 experience when you update the graph.
143142
144143
@@ -269,14 +268,14 @@ def __init__(
269268
self._screen_palette[5] = self._background_color
270269

271270
self._corner_bitmap = displayio.Bitmap(10, 10, 5)
272-
rectangle_helper(
271+
272+
bitmaptools.fill_region(
273+
self._corner_bitmap,
273274
0,
274275
0,
275276
self._axes_line_thickness,
276277
self._axes_line_thickness,
277-
self._corner_bitmap,
278278
2,
279-
self._screen_palette,
280279
)
281280

282281
self._corner_tilegrid = displayio.TileGrid(
@@ -336,28 +335,23 @@ def _get_font_height(font, scale: int) -> Tuple[int, int]:
336335
return font_width, font_height
337336

338337
def _draw_axes(self) -> None:
339-
# Draw x axes line
340-
rectangle_helper(
338+
339+
bitmaptools.fill_region(
340+
self._axesx_bitmap,
341341
0,
342342
0,
343-
self._axes_line_thickness,
344343
self.width,
345-
self._axesx_bitmap,
344+
self._axes_line_thickness,
346345
2,
347-
self._screen_palette,
348-
True,
349346
)
350347

351-
# Draw y axes line
352-
rectangle_helper(
348+
bitmaptools.fill_region(
349+
self._axesy_bitmap,
353350
self._axesy_width - self._axes_line_thickness,
354351
0,
352+
self._axesy_width,
355353
self.height,
356-
self._axes_line_thickness,
357-
self._axesy_bitmap,
358354
2,
359-
self._screen_palette,
360-
True,
361355
)
362356

363357
def _draw_ticks(self) -> None:
@@ -382,30 +376,28 @@ def _draw_ticks(self) -> None:
382376
+ 1,
383377
)
384378
self.append(tick_text)
385-
rectangle_helper(
379+
380+
bitmaptools.fill_region(
381+
self._axesx_bitmap,
386382
text_dist,
387383
self._axes_line_thickness,
388-
self._tick_line_height,
389-
self._tick_line_thickness,
390-
self._axesx_bitmap,
384+
text_dist + self._tick_line_thickness,
385+
self._axes_line_thickness + self._tick_line_height,
391386
1,
392-
self._screen_palette,
393-
True,
394387
)
395388

396389
if self._subticks:
397390
if i in subticks:
398391
# calc subtick_line_height; force min lineheigt to 1.
399392
subtick_line_height = max(1, self._tick_line_height // 2)
400-
rectangle_helper(
393+
394+
bitmaptools.fill_region(
395+
self._axesx_bitmap,
401396
text_dist,
402397
self._axes_line_thickness,
403-
subtick_line_height,
398+
text_dist + 1,
399+
self._axes_line_thickness + subtick_line_height,
404400
1,
405-
self._axesx_bitmap,
406-
1,
407-
self._screen_palette,
408-
True,
409401
)
410402

411403
# Y axes ticks
@@ -425,34 +417,32 @@ def _draw_ticks(self) -> None:
425417
y=0 + self.height - text_dist,
426418
)
427419
self.append(tick_text)
428-
rectangle_helper(
420+
421+
bitmaptools.fill_region(
422+
self._axesy_bitmap,
429423
self._axesy_width
430424
- self._axes_line_thickness
431425
- self._tick_line_height
432426
- 1,
433427
text_dist,
434-
self._tick_line_thickness,
435-
self._tick_line_height,
436-
self._axesy_bitmap,
428+
self._axesy_width - self._axes_line_thickness - 1,
429+
text_dist + self._tick_line_thickness,
437430
1,
438-
self._screen_palette,
439-
True,
440431
)
441432

442433
if self._subticks:
443434
if i in subticks:
444-
rectangle_helper(
435+
436+
bitmaptools.fill_region(
437+
self._axesy_bitmap,
445438
self._axesy_width
446439
- self._axes_line_thickness
447440
- self._tick_line_height // 2
448441
- 1,
449442
text_dist,
443+
self._axesy_width - self._axes_line_thickness - 1,
444+
text_dist + 1,
450445
1,
451-
self._tick_line_height // 2,
452-
self._axesy_bitmap,
453-
1,
454-
self._screen_palette,
455-
True,
456446
)
457447

458448
def _draw_pointers(self, x: int, y: int) -> None:

0 commit comments

Comments
 (0)