@@ -522,6 +522,20 @@ def update_graph(self):
522522 spacing = self .SPACING
523523 bar_width = self .BAR_WIDTH
524524
525+ def get_counts (attr_vals , values ):
526+ """This function calculates rectangles' widths.
527+ If all widths are zero then all widths are set to 1."""
528+ if attr_vals == "" :
529+ counts = [conditionaldict [val ] for val in values ]
530+ else :
531+ counts = [conditionaldict [attr_vals + "-" + val ]
532+ for val in values ]
533+ total = sum (counts )
534+ if total == 0 :
535+ counts = [1 ] * len (values )
536+ total = sum (counts )
537+ return total , counts
538+
525539 def draw_data (attr_list , x0_x1 , y0_y1 , side , condition ,
526540 total_attrs , used_attrs , used_vals , attr_vals = "" ):
527541 x0 , x1 = x0_x1
@@ -552,12 +566,7 @@ def draw_data(attr_list, x0_x1, y0_y1, side, condition,
552566 if whole == 0 :
553567 edge = (y1 - y0 ) / float (len (values ) - 1 )
554568
555- if attr_vals == "" :
556- counts = [conditionaldict [val ] for val in values ]
557- else :
558- counts = [conditionaldict [attr_vals + "-" + val ]
559- for val in values ]
560- total = sum (counts )
569+ total , counts = get_counts (attr_vals , values )
561570
562571 # if we are visualizing the third attribute and the first attribute
563572 # has the last value, we have to reverse the order in which the
@@ -643,15 +652,7 @@ def draw_text(side, attr, x0_x1, y0_y1,
643652 # calculate position of first attribute
644653 currpos = 0
645654
646- if attr_vals == "" :
647- counts = [conditionaldict .get (val , 1 ) for val in values ]
648- else :
649- counts = [conditionaldict .get (attr_vals + "-" + val , 1 )
650- for val in values ]
651- total = sum (counts )
652- if total == 0 :
653- counts = [1 ] * len (values )
654- total = sum (counts )
655+ total , counts = get_counts (attr_vals , values )
655656
656657 aligns = [Qt .AlignTop | Qt .AlignHCenter ,
657658 Qt .AlignRight | Qt .AlignVCenter ,
0 commit comments