@@ -319,7 +319,7 @@ def __init__(
319
319
self ._circle_palette = None
320
320
self .plot_line_point = None
321
321
322
- self ._fill_area = False
322
+ self ._fill_area = fill_area
323
323
324
324
@staticmethod
325
325
def _get_font_height (font , scale : int ) -> Tuple [int , int ]:
@@ -595,7 +595,6 @@ def update_pointer(self, x: int, y: int) -> None:
595
595
:param int x: ``x`` coordinate in the local plane
596
596
:param int y: ``y`` coordinate in the local plane
597
597
:return: None
598
- rtype: None
599
598
"""
600
599
self ._add_point (x , y )
601
600
if not self ._pointer :
@@ -609,6 +608,7 @@ def update_pointer(self, x: int, y: int) -> None:
609
608
610
609
@property
611
610
def fill_area (self ) -> bool :
611
+ """Whether the area under the graph (integral) should be shaded"""
612
612
return self ._fill_area
613
613
614
614
@fill_area .setter
@@ -640,42 +640,52 @@ def add_plot_line(self, x: int, y: int) -> None:
640
640
641
641
delta_x = self .plot_line_point [- 2 ][0 ] - self .plot_line_point [- 1 ][0 ]
642
642
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
+ )
644
646
645
647
if delta_x == 0 :
646
648
return
647
649
648
- slope = delta_y / delta_x
649
- above_x_axis = False if slope > 0 else True
650
+ slope = delta_y / delta_x
650
651
651
652
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
656
657
657
658
self ._draw_area_under (self .plot_line_point [- 2 ], (zero_point_x , 0 ))
658
659
self ._draw_area_under ((zero_point_x , 0 ), self .plot_line_point [- 1 ])
659
660
660
661
else :
661
662
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
+ )
664
668
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
+ )
666
672
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 :
668
676
669
677
_ , plot_y_zero = self ._calc_local_xy (0 , 0 )
670
678
671
679
delta_x = self .plot_line_point [- 2 ][0 ] - self .plot_line_point [- 1 ][0 ]
672
680
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
674
682
675
- for pixel_x in range (xy0 [0 ], xy1 [0 ]+ 1 ):
683
+ for pixel_x in range (xy0 [0 ], xy1 [0 ] + 1 ):
676
684
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
+ )
679
689
680
690
def clear_plot_lines (self , palette_index = 5 ):
681
691
"""clear_plot_lines function.
0 commit comments