Changeset 70

Show
Ignore:
Timestamp:
11/21/07 01:52:55 (4 years ago)
Author:
lgs
Message:

Removed unused whitespace and fixed #3

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/src/chart.py

    r61 r70  
    4242        self.xrange = None 
    4343        self.yrange = None 
    44          
     44 
    4545        self.xticks = [] 
    4646        self.yticks = [] 
     
    8181    def render(self, surface=None, options={}): 
    8282        """Renders the chart with the specified options. 
    83          
     83 
    8484        The optional parameters can be used to render a chart in a different 
    8585        surface with new options. 
     
    8888        if surface: 
    8989            self._initSurface(surface) 
    90          
     90 
    9191        cx = cairo.Context(self.surface) 
    9292        self._renderBackground(cx) 
     
    123123            self.resetFlag = False 
    124124            self.clean() 
    125          
     125 
    126126 
    127127    # update methods 
     
    154154            xdata = [pair[0] for pair in reduce(lambda a,b: a+b, stores)] 
    155155            if self.options.xOriginIsZero: 
    156                 self.minxval = 0.0  
     156                self.minxval = 0.0 
    157157            else: 
    158158                self.minxval = float(min(xdata)) 
    159159            self.maxxval = float(max(xdata)) 
    160160 
    161         self.xrange = self.maxxval - self.minxval         
     161        self.xrange = self.maxxval - self.minxval 
    162162        if self.xrange == 0: 
    163             self.xscale = 1.0  
     163            self.xscale = 1.0 
    164164        else: 
    165165            self.xscale = 1 / self.xrange 
     
    172172            ydata = [pair[1] for pair in reduce(lambda a,b: a+b, stores)] 
    173173            if self.options.yOriginIsZero: 
    174                 self.minyval = 0.0   
     174                self.minyval = 0.0 
    175175            else: 
    176176                self.minyval = float(min(ydata)) 
     
    179179        self.yrange = self.maxyval - self.minyval 
    180180        if self.yrange == 0: 
    181             self.yscale = 1.0  
     181            self.yscale = 1.0 
    182182        else: 
    183183            self.yscale = 1 / self.yrange 
     
    188188    def _updateTicks(self): 
    189189        """Evaluates ticks for x and y axis. 
    190          
     190 
    191191        You should call _updateXY before because that method computes the 
    192192        values of xscale, minxval, yscale, and other attributes needed for 
     
    203203                if tick.label is None: 
    204204                    label = str(tick.v) 
    205                 else:  
     205                else: 
    206206                    label = tick.label 
    207207                pos = self.xscale * (tick.v - self.minxval) 
     
    225225        self.yticks = [] 
    226226        if self.options.axis.y.ticks: 
    227             for tick in self.options.y.ticks: 
     227            for tick in self.options.axis.y.ticks: 
    228228                if not isinstance(tick, Option): 
    229229                    tick = Option(tick) 
    230230                if tick.label is None: 
    231                     label = str(tick.v)   
     231                    label = str(tick.v) 
    232232                else: 
    233233                    label = tick.label 
     
    243243            else: 
    244244                roughSeparation = round(num, prec) 
    245              
     245 
    246246            for i in range(self.options.axis.y.tickCount + 1): 
    247247                yval = self.minyval + (i * roughSeparation) 
     
    249249                if 0.0 <= pos <= 1.0: 
    250250                    self.yticks.append((pos, round(yval, prec))) 
    251              
     251 
    252252    # render methods 
    253253    def _renderBackground(self, cx): 
     
    255255        if self.options.background.hide: 
    256256            return 
    257          
     257 
    258258        cx.save() 
    259259        cx.set_source_rgb(*hex2rgb(self.options.background.color)) 
     
    262262        cx.set_source_rgb(*hex2rgb(self.options.background.lineColor)) 
    263263        cx.set_line_width(self.options.axis.lineWidth) 
    264          
     264 
    265265        self._renderLines(cx) 
    266          
     266 
    267267        cx.restore() 
    268268 
     
    272272        for tick in ticks: 
    273273            self._renderLine(cx, tick, False) 
    274          
     274 
    275275    def _renderLine(self, cx, tick, horiz): 
    276         """Aux function for _renderLines"""  
     276        """Aux function for _renderLines""" 
    277277        x1, x2, y1, y2 = (0, 0, 0, 0) 
    278278        if horiz: 
     
    298298        if self.options.axis.x.hide and self.options.axis.y.hide: 
    299299            return 
    300          
     300 
    301301        cx.save() 
    302302        cx.set_source_rgb(*hex2rgb(self.options.axis.lineColor)) 
    303303        cx.set_line_width(self.options.axis.lineWidth) 
    304          
     304 
    305305        if not self.options.axis.y.hide: 
    306306            if self.yticks: 
     
    308308                    if callable(tick): 
    309309                        return 
    310                      
     310 
    311311                    x = self.area.x 
    312312                    y = self.area.y + tick[0] * self.area.h 
    313                      
     313 
    314314                    cx.new_path() 
    315315                    cx.move_to(x, y) 
     
    317317                    cx.close_path() 
    318318                    cx.stroke() 
    319                      
     319 
    320320                    label =  unicode(tick[1]) 
    321321                    extents = cx.text_extents(label) 
     
    325325                               y + labelHeight / 2.0) 
    326326                    cx.show_text(label) 
    327                      
     327 
    328328                    return label 
    329329                for tick in self.yticks: 
    330330                    drawYLabel(tick) 
    331                  
     331 
    332332            cx.new_path() 
    333333            cx.move_to(self.area.x, self.area.y) 
     
    341341                    if callable(tick): 
    342342                        return 
    343                      
     343 
    344344                    x = self.area.x + tick[0] * self.area.w 
    345345                    y = self.area.y + self.area.h 
    346                      
     346 
    347347                    cx.new_path() 
    348348                    cx.move_to(x, y) 
     
    350350                    cx.close_path() 
    351351                    cx.stroke() 
    352                      
     352 
    353353                    label = unicode(tick[1]) 
    354354                    extents = cx.text_extents(label) 
     
    361361                for tick in self.xticks: 
    362362                    drawXLabel(tick) 
    363              
     363 
    364364            cx.new_path() 
    365365            cx.move_to(self.area.x, self.area.y + self.area.h) 
     
    374374        if self.options.legend.hide: 
    375375            return 
    376          
     376 
    377377        padding = 4 
    378378        bullet = 15 
     
    395395        cx.set_source_rgb(*hex2rgb(self.options.legend.borderColor)) 
    396396        cx.stroke() 
    397          
     397 
    398398        def drawKey(key, x, y, text_height): 
    399399            cx.rectangle(x, y, bullet, bullet) 
     
    405405                       y + bullet / 2.0 + text_height / 2.0) 
    406406            cx.show_text(key) 
    407          
     407 
    408408        cx.set_line_width(1) 
    409409        x = self.options.legend.position.left + padding 
     
    419419    """Return a list with the indexes of the biggest element of arr""" 
    420420    return range(max([len(a) for a in arr])) 
    421              
     421 
    422422class Area(object): 
    423423    """Simple rectangle to hold an area coordinates and dimensions"""