Changeset 99

Show
Ignore:
Timestamp:
09/12/08 11:56:59 (4 years ago)
Author:
lgs
Message:

Refactor _renderAxis by using two auxiliar methods: _renderYAxis and _renderXAxis. Patch by Nicolas

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/src/chart.py

    r98 r99  
    413413        cx.show_text(label) 
    414414 
     415    def _renderYAxis(self, cx): 
     416        """Draws the vertical line represeting the Y axis""" 
     417        cx.new_path() 
     418        cx.move_to(self.area.x, self.area.y) 
     419        cx.line_to(self.area.x, self.area.y + self.area.h) 
     420        cx.close_path() 
     421        cx.stroke() 
     422 
     423    def _renderXAxis(self, cx): 
     424        """Draws the horizontal line representing the X axis""" 
     425        cx.new_path() 
     426        cx.move_to(self.area.x, self.area.y + self.area.h) 
     427        cx.line_to(self.area.x + self.area.w, self.area.y + self.area.h) 
     428        cx.close_path() 
     429        cx.stroke() 
     430 
    415431    def _renderAxis(self, cx): 
    416432        """Renders axis""" 
     
    430446                cx.save() 
    431447                rotate = self.options.axis.y.rotate 
    432                 tickWidth, tickHeight = self._getTickSize(cx, self.yticks, rotate) 
     448                tickWidth, tickHeight = self._getTickSize(cx, self.yticks, 
     449                                                          rotate) 
    433450                label = unicode(self.options.axis.y.label) 
    434451                x = self.area.x - tickWidth - 4.0 
    435452                y = self.area.y + 0.5 * self.area.h 
    436                 self._renderAxisLabel(cx, tickWidth, tickHeight, label, x, y, True) 
     453                self._renderAxisLabel(cx, tickWidth, tickHeight, label, x, y, 
     454                                      True) 
    437455                cx.restore() 
    438456 
    439             # draws the vertical line representing the Y axis 
    440             cx.new_path() 
    441             cx.move_to(self.area.x, self.area.y) 
    442             cx.line_to(self.area.x, self.area.y + self.area.h) 
    443             cx.close_path() 
    444             cx.stroke() 
     457            self._renderYAxis(cx) 
    445458 
    446459        if not self.options.axis.x.hide: 
     
    453466                cx.save() 
    454467                rotate = self.options.axis.x.rotate 
    455                 tickWidth, tickHeight = self._getTickSize(cx, self.xticks, rotate) 
     468                tickWidth, tickHeight = self._getTickSize(cx, self.xticks, 
     469                                                          rotate) 
    456470                label = unicode(self.options.axis.x.label) 
    457471                x = self.area.x + self.area.w / 2.0 
    458472                y = self.area.y + self.area.h + tickHeight + 4.0 
    459                 self._renderAxisLabel(cx, tickWidth, tickHeight, label, x, y, False) 
     473                self._renderAxisLabel(cx, tickWidth, tickHeight, label, x, y, 
     474                                      False) 
    460475                cx.restore() 
    461476 
    462             # draws the horizontal line representing the X axis 
    463             cx.new_path() 
    464             cx.move_to(self.area.x, self.area.y + self.area.h) 
    465             cx.line_to(self.area.x + self.area.w, self.area.y + self.area.h) 
    466             cx.close_path() 
    467             cx.stroke() 
     477            self._renderXAxis(cx) 
    468478 
    469479        cx.restore()