Changeset 80

Show
Ignore:
Timestamp:
03/21/08 13:14:50 (4 years ago)
Author:
lgs
Message:

Support for chart titles. Based on a patch by jae_AT_zhar.net. See #6

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/src/chart.py

    r79 r80  
    9393        self._renderChart(cx) 
    9494        self._renderAxis(cx) 
     95        self._renderTitle(cx) 
    9596        self._renderLegend(cx) 
    9697 
     
    369370 
    370371        cx.restore() 
     372 
     373    def _renderTitle(self, cx): 
     374        if self.options.title: 
     375            # get previous font information 
     376            oldFace = cx.get_font_face() 
     377            oldMatrix = cx.get_font_matrix() 
     378             
     379            cx.select_font_face(self.options.titleFont, 
     380                                cairo.FONT_SLANT_NORMAL, 
     381                                cairo.FONT_WEIGHT_BOLD) 
     382            cx.set_font_size(self.options.titleFontSize)  
     383 
     384            title = unicode(self.options.title) 
     385            extents = cx.text_extents(title) 
     386            titleWidth = extents[2]  
     387 
     388            x = self.area.x + self.area.w / 2.0 - titleWidth / 2.0  
     389            y = cx.font_extents()[0] # font ascent  
     390 
     391            cx.move_to(x, y) 
     392            cx.show_text(title) 
     393             
     394            # restore font state 
     395            cx.set_font_face(oldFace) 
     396            cx.set_font_matrix(oldMatrix) 
    371397 
    372398    def _renderLegend(self, cx): 
     
    498524    pieRadius=0.4, 
    499525    colorScheme=DEFAULT_COLOR, 
     526    title=None, 
     527    titleFont='Tahoma', 
     528    titleFontSize=12, 
    500529)