<s> import copy <EOL> from gruffy import base <EOL> from pgmagick import Color , DrawableFillColor , DrawableFillOpacity , DrawableFont , DrawableGravity , DrawableLine , DrawableList , DrawablePointSize , DrawableRectangle , DrawableScaling , DrawableStrokeAntialias , DrawableStrokeColor , DrawableStrokeOpacity , DrawableStrokeWidth , DrawableText , GravityType , StretchType , StyleType <EOL> class SideBar ( base . Base ) : <EOL> """<STR_LIT>""" <EOL> bar_spacing = None <EOL> def draw ( self ) : <EOL> self . has_left_labels = True <EOL> SideBar . __base__ . draw ( self ) <EOL> if not self . has_gdata : <EOL> return <EOL> self . draw_bars ( ) <EOL> def draw_bars ( self ) : <EOL> self . dl = DrawableList ( ) <EOL> self . bar_spacing = self . bar_spacing or <NUM_LIT> <EOL> self . bars_width = self . graph_height / float ( self . column_count ) <EOL> self . bar_width = self . bars_width * self . bar_spacing / len ( self . norm_data ) <EOL> self . dl . append ( DrawableStrokeOpacity ( <NUM_LIT:0.0> ) ) <EOL> height = [ <NUM_LIT:0> for i in range ( self . column_count ) ] <EOL> length = [ self . graph_left for i in range ( self . column_count ) ] <EOL> padding = ( self . bar_width * ( <NUM_LIT:1> - self . bar_spacing ) ) / <NUM_LIT:2> <EOL> for row_index , data_row in enumerate ( self . norm_data ) : <EOL> for point_index , data_point in enumerate ( data_row [ '<STR_LIT>' ] ) : <EOL> self . dl . append ( DrawableFillColor ( Color ( data_row [ '<STR_LIT>' ] ) ) ) <EOL> if type ( self . transparent ) is float : <EOL> self . dl . append ( DrawableFillOpacity ( self . transparent ) ) <EOL> elif self . transparent is True : <EOL> self . dl . append ( DrawableFillOpacity ( base . DEFAULT_TRANSPARENCY ) ) <EOL> temp1 = self . graph_left + ( self . graph_width - data_point * self . graph_width - height [ point_index ] ) <EOL> temp2 = self . graph_left + self . graph_width - height [ point_index ] <EOL> difference = temp2 - temp1 <EOL> left_x = length [ point_index ] - <NUM_LIT:1> <EOL> left_y = self . graph_top + ( self . bars_width * point_index ) + ( self . bar_width * row_index ) + padding <EOL> right_x = left_x + difference <EOL> right_y = left_y + self . bar_width <EOL> height [ point_index ] += ( data_point * self . graph_width ) <EOL> self . dl . append ( DrawableRectangle ( left_x , left_y , right_x , right_y ) ) <EOL> label_center = self . graph_top + ( self . bars_width * point_index + self . bars_width / <NUM_LIT:2> ) <EOL> self . draw_label ( label_center , point_index ) <EOL> if self . additional_line_values : <EOL> _gdata = self . find_label ( data_row [ '<STR_LIT:label>' ] ) <EOL> self . draw_values ( left_y + self . bar_width / <NUM_LIT:2> , <EOL> _gdata [ '<STR_LIT>' ] [ point_index ] ) <EOL> self . dl . append ( DrawableScaling ( self . scale , self . scale ) ) <EOL> self . base_image . draw ( self . dl ) <EOL> def find_label ( self , label ) : <EOL> for i in self . gdata : <EOL> if i [ '<STR_LIT:label>' ] == label : <EOL> return copy . copy ( i ) <EOL> def draw_line_markers ( self ) : <EOL> if self . hide_line_markers : <EOL> return <EOL> dl = DrawableList ( ) <EOL> dl . append ( DrawableStrokeAntialias ( False ) ) <EOL> dl . append ( DrawableFillColor ( Color ( self . marker_color ) ) ) <EOL> dl . append ( DrawableStrokeWidth ( <NUM_LIT:1> ) ) <EOL> number_of_lines = <NUM_LIT:5> <EOL> increment = self . significant ( float ( self . maximum_value ) / number_of_lines ) <EOL> for index in range ( number_of_lines + <NUM_LIT:1> ) : <EOL> line_diff = ( self . graph_right - self . graph_left ) / number_of_lines <EOL> x = self . graph_right - ( line_diff * index ) - <NUM_LIT:1> <EOL> dl . append ( DrawableLine ( x , self . graph_bottom , x , self . graph_top ) ) <EOL> diff = index - number_of_lines <EOL> marker_label = abs ( diff ) * increment <EOL> if not self . hide_line_numbers : <EOL> dl . append ( DrawableFillColor ( Color ( self . font_color ) ) ) <EOL> font = self . font if self . font else base . DEFAULT_FONT <EOL> dl . append ( DrawableFont ( font , StyleType . NormalStyle , <NUM_LIT> , <EOL> StretchType . NormalStretch ) ) <EOL> dl . append ( DrawableStrokeColor ( Color ( '<STR_LIT>' ) ) ) <EOL> dl . append ( DrawablePointSize ( self . marker_font_size ) ) <EOL> dl . append ( DrawableGravity ( GravityType . NorthWestGravity ) ) <EOL> text_width = self . calculate_width ( self . marker_font_size , <EOL> str ( marker_label ) ) <EOL> x -= text_width / <NUM_LIT:2> <EOL> y = self . graph_bottom + ( base . LABEL_MARGIN * <NUM_LIT> ) <EOL> if type ( marker_label ) is int : <EOL> dl . append ( DrawableText ( x , y , "<STR_LIT>" % marker_label ) ) <EOL> else : <EOL> dl . append ( DrawableText ( x , y , "<STR_LIT>" % marker_label ) ) <EOL> dl . append ( DrawableStrokeAntialias ( True ) ) <EOL> dl . append ( DrawableScaling ( self . scale , self . scale ) ) <EOL> self . base_image . draw ( dl ) <EOL> def draw_label ( self , y_offset , index ) : <EOL> if index in self . labels and index not in self . labels_seen : <EOL> dl = DrawableList ( ) <EOL> dl . append ( DrawableFillColor ( self . font_color ) ) <EOL> font = self . font if self . font else base . DEFAULT_FONT <EOL> dl . append ( DrawableGravity ( GravityType . NorthEastGravity ) ) <EOL> dl . append ( DrawableFont ( font , StyleType . NormalStyle , <NUM_LIT> , <EOL> StretchType . NormalStretch ) ) <EOL> dl . append ( DrawableStrokeColor ( Color ( '<STR_LIT>' ) ) ) <EOL> dl . append ( DrawablePointSize ( self . marker_font_size ) ) <EOL> font_hight = self . calculate_caps_height ( self . marker_font_size ) <EOL> x = self . raw_columns - self . graph_left + base . LABEL_MARGIN <EOL> y = y_offset + font_hight / <NUM_LIT> <EOL> dl . append ( DrawableText ( x , y , self . labels [ index ] ) ) <EOL> self . labels_seen [ index ] = <NUM_LIT:1> <EOL> dl . append ( DrawableScaling ( self . scale , self . scale ) ) <EOL> self . base_image . draw ( dl ) <EOL> def draw_values ( self , y_offset , point ) : <EOL> self . dl . append ( DrawableFillColor ( self . font_color ) ) <EOL> font = self . font if self . font else base . DEFAULT_FONT <EOL> self . dl . append ( DrawableGravity ( GravityType . NorthWestGravity ) ) <EOL> self . dl . append ( DrawableFont ( font , StyleType . ItalicStyle , <NUM_LIT> , <EOL> StretchType . NormalStretch ) ) <EOL> self . dl . append ( DrawableStrokeColor ( Color ( '<STR_LIT>' ) ) ) <EOL> marker_font_size = self . marker_font_size * <NUM_LIT> <EOL> self . dl . append ( DrawablePointSize ( marker_font_size ) ) <EOL> font_hight = self . calculate_caps_height ( marker_font_size ) <EOL> x = self . graph_left + base . LABEL_MARGIN <EOL> y = y_offset + font_hight / <NUM_LIT> <EOL> self . dl . append ( DrawableText ( x , y , "<STR_LIT>" % point ) ) </s>
