Skip to content

Commit 965fda7

Browse files
committed
Linted and reformatted per pre-commit
1 parent 69ec0d6 commit 965fda7

File tree

1 file changed

+27
-17
lines changed

1 file changed

+27
-17
lines changed

displayio_cartesian.py

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ def __init__(
319319
self._circle_palette = None
320320
self.plot_line_point = None
321321

322-
self._fill_area = False
322+
self._fill_area = fill_area
323323

324324
@staticmethod
325325
def _get_font_height(font, scale: int) -> Tuple[int, int]:
@@ -595,7 +595,6 @@ def update_pointer(self, x: int, y: int) -> None:
595595
:param int x: ``x`` coordinate in the local plane
596596
:param int y: ``y`` coordinate in the local plane
597597
:return: None
598-
rtype: None
599598
"""
600599
self._add_point(x, y)
601600
if not self._pointer:
@@ -609,6 +608,7 @@ def update_pointer(self, x: int, y: int) -> None:
609608

610609
@property
611610
def fill_area(self) -> bool:
611+
"""Whether the area under the graph (integral) should be shaded"""
612612
return self._fill_area
613613

614614
@fill_area.setter
@@ -640,42 +640,52 @@ def add_plot_line(self, x: int, y: int) -> None:
640640

641641
delta_x = self.plot_line_point[-2][0] - self.plot_line_point[-1][0]
642642
delta_y = self.plot_line_point[-2][1] - self.plot_line_point[-1][1]
643-
delta_y_product = self.plot_line_point[-1][1] * self.plot_line_point[-2][1]
643+
delta_y_product = (
644+
self.plot_line_point[-1][1] * self.plot_line_point[-2][1]
645+
)
644646

645647
if delta_x == 0:
646648
return
647649

648-
slope = delta_y/delta_x
649-
above_x_axis = False if slope > 0 else True
650+
slope = delta_y / delta_x
650651

651652
if delta_y_product < 0:
652-
# TODO: Area needs to be split into two triangles
653-
654-
c = self.plot_line_point[-1][1]
655-
zero_point_x = (-1 * c)/slope
653+
# TODO: Area needs to be split into two triangles
654+
655+
intercept = self.plot_line_point[-1][1]
656+
zero_point_x = (-1 * intercept) / slope
656657

657658
self._draw_area_under(self.plot_line_point[-2], (zero_point_x, 0))
658659
self._draw_area_under((zero_point_x, 0), self.plot_line_point[-1])
659660

660661
else:
661662

662-
point_to_check = self.plot_line_point[-1] if self.plot_line_point[-1][1] != 0 else self.plot_line_point[-2]
663-
above_x_axis = point_to_check[1] > 0
663+
point_to_check = (
664+
self.plot_line_point[-1]
665+
if self.plot_line_point[-1][1] != 0
666+
else self.plot_line_point[-2]
667+
)
664668

665-
self._draw_area_under(self.plot_line_point[-2], self.plot_line_point[-1])
669+
self._draw_area_under(
670+
self.plot_line_point[-2], self.plot_line_point[-1]
671+
)
666672

667-
def _draw_area_under(self, xy0: Tuple[float, float], xy1: Tuple[float, float]) -> None:
673+
def _draw_area_under(
674+
self, xy0: Tuple[float, float], xy1: Tuple[float, float]
675+
) -> None:
668676

669677
_, plot_y_zero = self._calc_local_xy(0, 0)
670678

671679
delta_x = self.plot_line_point[-2][0] - self.plot_line_point[-1][0]
672680
delta_y = self.plot_line_point[-2][1] - self.plot_line_point[-1][1]
673-
slope = delta_y/delta_x
681+
slope = delta_y / delta_x
674682

675-
for pixel_x in range(xy0[0], xy1[0]+1):
683+
for pixel_x in range(xy0[0], xy1[0] + 1):
676684
if pixel_x != xy1[0]:
677-
pixel_y = round(slope*(pixel_x-xy1[0]) + xy1[1])
678-
bitmaptools.draw_line(self._plot_bitmap, pixel_x, pixel_y, pixel_x, plot_y_zero, 1)
685+
pixel_y = round(slope * (pixel_x - xy1[0]) + xy1[1])
686+
bitmaptools.draw_line(
687+
self._plot_bitmap, pixel_x, pixel_y, pixel_x, plot_y_zero, 1
688+
)
679689

680690
def clear_plot_lines(self, palette_index=5):
681691
"""clear_plot_lines function.

0 commit comments

Comments
 (0)