@@ -420,6 +420,29 @@ def DisplayLineGraph(self, x: int, y: int, width: int, height: int,
420420
421421 self .DisplayPILImage (graph_image , x , y )
422422
423+ def DrawRadialDecoration (self , draw : ImageDraw , angle : float , radius : float , width : float , color : Tuple [int , int , int ] = (0 , 0 , 0 )):
424+ i_cos = math .cos (angle * math .pi / 180 )
425+ i_sin = math .sin (angle * math .pi / 180 )
426+ x_f = (i_cos * (radius - width / 2 )) + radius
427+ if math .modf (x_f ) == 0.5 :
428+ if i_cos > 0 :
429+ x_f = math .floor (x_f )
430+ else :
431+ x_f = math .ceil (x_f )
432+ else :
433+ x_f = math .floor (x_f + 0.5 )
434+
435+ y_f = (i_sin * (radius - width / 2 )) + radius
436+ if math .modf (y_f ) == 0.5 :
437+ if i_sin > 0 :
438+ y_f = math .floor (y_f )
439+ else :
440+ y_f = math .ceil (y_f )
441+ else :
442+ y_f = math .floor (y_f + 0.5 )
443+ draw .ellipse ([x_f - width / 2 , y_f - width / 2 , x_f + width / 2 , y_f - 1 + width / 2 - 1 ], outline = color , fill = color , width = 1 )
444+
445+
423446 def DisplayRadialProgressBar (self , xc : int , yc : int , radius : int , bar_width : int ,
424447 min_value : int = 0 ,
425448 max_value : int = 100 ,
@@ -438,7 +461,10 @@ def DisplayRadialProgressBar(self, xc: int, yc: int, radius: int, bar_width: int
438461 background_color : Tuple [int , int , int ] = (255 , 255 , 255 ),
439462 background_image : str = None ,
440463 custom_bbox : Tuple [int , int , int , int ] = (0 , 0 , 0 , 0 ),
441- text_offset : Tuple [int , int ] = (0 ,0 )):
464+ text_offset : Tuple [int , int ] = (0 ,0 ),
465+ bar_background_color : Tuple [int , int , int ] = (0 , 0 , 0 ),
466+ draw_bar_background : bool = False ,
467+ bar_decoration : str = "" ):
442468 # Generate a radial progress bar and display it
443469 # Provide the background image path to display progress bar with transparent background
444470
@@ -451,6 +477,9 @@ def DisplayRadialProgressBar(self, xc: int, yc: int, radius: int, bar_width: int
451477 if isinstance (font_color , str ):
452478 font_color = tuple (map (int , font_color .split (', ' )))
453479
480+ if isinstance (bar_background_color , str ):
481+ bar_background_color = tuple (map (int , bar_background_color .split (', ' )))
482+
454483 if angle_start % 361 == angle_end % 361 :
455484 if clockwise :
456485 angle_start += 0.1
@@ -502,6 +531,23 @@ def DisplayRadialProgressBar(self, xc: int, yc: int, radius: int, bar_width: int
502531 ecart = 360 - angle_start + angle_end
503532 else :
504533 ecart = angle_end - angle_start
534+
535+ # draw bar background
536+ if draw_bar_background :
537+ if angle_end < angle_start :
538+ angleE = angle_start + ecart
539+ angleS = angle_start
540+ else :
541+ angleS = angle_start
542+ angleE = angle_start + ecart
543+ draw .arc ([0 , 0 , diameter - 1 , diameter - 1 ], angleS , angleE , fill = bar_background_color , width = bar_width )
544+
545+ # draw bar decoration
546+ if bar_decoration == "Ellipse" :
547+ self .DrawRadialDecoration (draw = draw , angle = angle_end , radius = radius , width = bar_width , color = bar_background_color )
548+ self .DrawRadialDecoration (draw = draw , angle = angle_start , radius = radius , width = bar_width , color = bar_color )
549+ self .DrawRadialDecoration (draw = draw , angle = angle_start + pct * ecart , radius = radius , width = bar_width , color = bar_color )
550+
505551 #
506552 # solid bar case
507553 if angle_sep == 0 :
@@ -535,6 +581,25 @@ def DisplayRadialProgressBar(self, xc: int, yc: int, radius: int, bar_width: int
535581 ecart = angle_start - angle_end
536582 else :
537583 ecart = 360 - angle_end + angle_start
584+
585+ # draw bar background
586+ if draw_bar_background :
587+ if angle_end < angle_start :
588+ angleE = angle_start
589+ angleS = angle_start - ecart
590+ else :
591+ angleS = angle_start - ecart
592+ angleE = angle_start
593+ draw .arc ([0 , 0 , diameter - 1 , diameter - 1 ], angleS , angleE , fill = bar_background_color , width = bar_width )
594+
595+
596+ # draw bar decoration
597+ if bar_decoration == "Ellipse" :
598+ self .DrawRadialDecoration (draw = draw , angle = angle_end , radius = radius , width = bar_width , color = bar_background_color )
599+ self .DrawRadialDecoration (draw = draw , angle = angle_start , radius = radius , width = bar_width , color = bar_color )
600+ self .DrawRadialDecoration (draw = draw , angle = angle_start - pct * ecart , radius = radius , width = bar_width , color = bar_color )
601+
602+ #
538603 # solid bar case
539604 if angle_sep == 0 :
540605 if angle_end < angle_start :
0 commit comments