@@ -766,11 +766,15 @@ class MultiRangeBar(Bar, VariableMixin):
766766 ]
767767 '''
768768
769- def __init__ (self , name , ** kwargs ):
769+ def __init__ (self , name , markers , ** kwargs ):
770770 VariableMixin .__init__ (self , name )
771771 Bar .__init__ (self , ** kwargs )
772+ self .markers = [
773+ string_or_lambda (marker )
774+ for marker in markers
775+ ]
772776
773- def get_ranges (self , progress , data ):
777+ def get_values (self , progress , data ):
774778 return data ['variables' ][self .name ] or []
775779
776780 def __call__ (self , progress , data , width ):
@@ -779,22 +783,22 @@ def __call__(self, progress, data, width):
779783 left = converters .to_unicode (self .left (progress , data , width ))
780784 right = converters .to_unicode (self .right (progress , data , width ))
781785 width -= progress .custom_len (left ) + progress .custom_len (right )
782- ranges = self .get_ranges (progress , data )
786+ values = self .get_values (progress , data )
783787
784- items_total = sum ([ count for symbol , count in ranges ] )
785- if width and items_total :
788+ values_sum = sum (values )
789+ if width and values_sum :
786790 middle = ''
787- items_accumulated = 0
791+ values_accumulated = 0
788792 width_accumulated = 0
789- for item_symbol , item_count in ranges :
790- item_marker = string_or_lambda (item_symbol )
791- item_marker = converters .to_unicode (item_marker (progress , data , width ))
792- assert utils .len_color (item_marker ) == 1
793+ for marker , value in zip (self .markers , values ):
794+ marker = converters .to_unicode (marker (progress , data , width ))
795+ assert utils .len_color (marker ) == 1
793796
794- items_accumulated += item_count
795- item_width = int (items_accumulated / items_total * width ) - width_accumulated
797+ values_accumulated += value
798+ item_width = int (values_accumulated / values_sum * width ) - width_accumulated
796799 width_accumulated += item_width
797- middle += item_width * item_marker
800+ #print(marker, value, values_accumulated, values_sum, item_width, width_accumulated)
801+ middle += item_width * marker
798802 else :
799803 fill = converters .to_unicode (self .fill (progress , data , width ))
800804 assert utils .len_color (fill ) == 1
@@ -804,15 +808,11 @@ def __call__(self, progress, data, width):
804808
805809
806810class MultiProgressBar (MultiRangeBar ):
807- def __init__ (self , name , progress_symbols = " ▁▂▃▄▅▆▇█" , ** kwargs ):
808- MultiRangeBar .__init__ (self , name = name , ** kwargs )
809- self .progress_symbols = progress_symbols
810-
811- def get_ranges (self , progress , data ):
812- ranges = [
813- [symbol , 0 ]
814- for symbol in self .progress_symbols
815- ]
811+ def __init__ (self , name , markers = " ▁▂▃▄▅▆▇█" , ** kwargs ):
812+ MultiRangeBar .__init__ (self , name = name , markers = list (reversed (markers )), ** kwargs )
813+
814+ def get_values (self , progress , data ):
815+ ranges = [0 ] * len (self .markers )
816816 for progress in data ['variables' ][self .name ] or []:
817817 if not isinstance (progress , (int , float )):
818818 # Progress is (value, max)
@@ -822,7 +822,7 @@ def get_ranges(self, progress, data):
822822 raise ValueError ('Range value needs to be in the range [0..1], got %s' % progress )
823823
824824 range = int (progress * (len (ranges ) - 1 ))
825- ranges [range ][ 1 ] += 1
825+ ranges [range ] += 1
826826
827827 if self .fill_left :
828828 ranges = list (reversed (ranges ))
0 commit comments