Skip to content

Commit e05033d

Browse files
committed
# UPDATE: adding nudge parameter, update docs, and function [√]
1 parent 636b449 commit e05033d

File tree

1 file changed

+20
-3
lines changed

1 file changed

+20
-3
lines changed

adafruit_displayio_layout/widgets/cartesian.py

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,13 @@ class Cartesian(Widget):
6666
:param int pointer_radius: pointer radius in pixels defaults to 1
6767
:param int pointer_color: pointer color. Defaults to white (0xFFFFFF)
6868
69+
:param bool subticks: inclusion of subticks in the plot area. Default to False
70+
71+
:param int nudge_x: movement in pixels in the x direction to move the origin.
72+
Defaults to 0
73+
:param int nudge_y: movement in pixels in the y direction to move the origin.
74+
Defaults to 0
75+
6976
7077
**Quickstart: Importing and using Cartesian**
7178
@@ -110,7 +117,10 @@ class Cartesian(Widget):
110117
The `cartesian` widget has some options for controlling its position, visible appearance,
111118
and scale through a collection of input variables:
112119
113-
- **position**: ``x``, ``y`` or ``anchor_point`` and ``anchored_position``
120+
- **position**: ``x``, ``y``, ``anchor_point``, ``anchored_position`` and
121+
`nudge_x`, `nudge_y`. Nudge parameters are used to account for the float and int
122+
conversions required to display different ranges and values. Conversion are required
123+
as displays work in integers and not floats
114124
115125
- **size**: ``width`` and ``height``
116126
@@ -168,6 +178,8 @@ def __init__(
168178
pointer_radius: int = 1,
169179
pointer_color: int = 0xFFFFFF,
170180
subticks: bool = False,
181+
nudge_x: int = 0,
182+
nudge_y: int = 0,
171183
**kwargs,
172184
) -> None:
173185

@@ -286,6 +298,9 @@ def __init__(
286298
y=0,
287299
)
288300

301+
self._nudge_x = nudge_x
302+
self._nudge_y = nudge_y
303+
289304
self._draw_axes()
290305
self._draw_ticks()
291306

@@ -476,8 +491,10 @@ def update_line(self, x: int, y: int) -> None:
476491
:return: None
477492
rtype: None
478493
"""
479-
local_x = int((x - self._xrange[0]) * self._factorx)
480-
local_y = int((self._yrange[0] - y) * self._factory) + self.height
494+
local_x = int((x - self._xrange[0]) * self._factorx) + self._nudge_x
495+
local_y = (
496+
int((self._yrange[0] - y) * self._factory) + self.height + self._nudge_y
497+
)
481498
if x < self._xrange[1] and y < self._yrange[1]:
482499
if local_x > 0 or local_y < 100:
483500
if self._update_line:

0 commit comments

Comments
 (0)