Changeset 140 for trunk/pycha/chart.py

Show
Ignore:
Timestamp:
02/03/09 16:08:23 (3 years ago)
Author:
lgs
Message:

Change the copyright range and make all code pep8 compatible

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/pycha/chart.py

    r138 r140  
    1 # Copyright (c) 2007-2008 by Lorenzo Gil Sanchez <lorenzo.gil.sanchez@gmail.com> 
     1# Copyright(c) 2007-2009 by Lorenzo Gil Sanchez <lorenzo.gil.sanchez@gmail.com> 
    22# 
    33# This file is part of PyCha. 
     
    2424                         DEFAULT_COLOR) 
    2525 
     26 
    2627class Chart(object): 
    2728 
     
    132133            self.clean() 
    133134 
    134  
    135     # update methods 
    136135    def _update(self, options={}): 
    137136        """Update all the information needed to render the chart""" 
     
    154153            self.minxval, self.maxxval = self.options.axis.x.range 
    155154        else: 
    156             xdata = [pair[0] for pair in reduce(lambda a,b: a+b, stores)] 
     155            xdata = [pair[0] for pair in reduce(lambda a, b: a+b, stores)] 
    157156            self.minxval = float(min(xdata)) 
    158157            self.maxxval = float(max(xdata)) 
     
    170169            self.minyval, self.maxyval = self.options.axis.y.range 
    171170        else: 
    172             ydata = [pair[1] for pair in reduce(lambda a,b: a+b, stores)] 
     171            ydata = [pair[1] for pair in reduce(lambda a, b: a+b, stores)] 
    173172            self.minyval = float(min(ydata)) 
    174173            self.maxyval = float(max(ydata)) 
     
    228227            roughSeparation = self.xrange / self.options.axis.x.tickCount 
    229228            i = j = 0 
    230             while i  < len(uniqx) and j < self.options.axis.x.tickCount: 
     229            while i < len(uniqx) and j < self.options.axis.x.tickCount: 
    231230                if (uniqx[i] - self.minxval) >= (j * roughSeparation): 
    232231                    pos = self.xscale * (uniqx[i] - self.minxval) 
     
    264263                    self.yticks.append((pos, round(yval, prec))) 
    265264 
    266     # render methods 
    267265    def _renderBackground(self, cx): 
    268266        """Renders the background area of the chart""" 
     
    330328        cx.stroke() 
    331329 
    332         label =  unicode(tick[1]) 
     330        label = unicode(tick[1]) 
    333331        extents = cx.text_extents(label) 
    334332        labelWidth = extents[2] 
     
    387385 
    388386    def _getTickSize(self, cx, ticks, rotate): 
    389         tickExtents = [cx.text_extents(unicode(tick[1]))[2:4] for tick in ticks] 
     387        tickExtents = [cx.text_extents(unicode(tick[1]))[2:4] 
     388                       for tick in ticks] 
    390389        tickWidth = tickHeight = 0.0 
    391390        if tickExtents: 
     
    399398                cosRadians = math.cos(radians) 
    400399                maxHeight = maxWidth * sinRadians + maxHeight * cosRadians 
    401                 maxWidth =  maxWidth * cosRadians + maxHeight * sinRadians 
     400                maxWidth = maxWidth * cosRadians + maxHeight * sinRadians 
    402401            tickWidth += maxWidth 
    403402            tickHeight += maxHeight 
    404403        return tickWidth, tickHeight 
    405404 
    406     def _renderAxisLabel(self, cx, tickWidth, tickHeight, label, x, y, vertical=False): 
     405    def _renderAxisLabel(self, cx, tickWidth, tickHeight, label, x, y, 
     406                         vertical=False): 
    407407        cx.new_path() 
    408408        cx.select_font_face(self.options.axis.labelFont, 
     
    570570        cx.restore() 
    571571 
     572 
    572573def uniqueIndices(arr): 
    573574    """Return a list with the indexes of the biggest element of arr""" 
    574575    return range(max([len(a) for a in arr])) 
    575576 
     577 
    576578class Area(object): 
    577579    """Simple rectangle to hold an area coordinates and dimensions""" 
     580 
    578581    def __init__(self, x, y, w, h, origin=0.0): 
    579582        self.x, self.y, self.w, self.h = x, y, w, h 
     
    584587        return  msg % (self.x, self.y, self.w, self.h, self.origin) 
    585588 
     589 
    586590class Option(dict): 
    587591    """Useful dict that allow attribute-like access to its keys""" 
     592 
    588593    def __getattr__(self, name): 
    589594        if name in self.keys(): 
     
    595600        """Recursive merge with other Option or dict object""" 
    596601        for key, value in other.items(): 
    597             if self.has_key(key): 
     602            if key in self: 
    598603                if isinstance(self[key], Option): 
    599604                    self[key].merge(other[key]) 
    600605                else: 
    601606                    self[key] = other[key] 
     607 
    602608 
    603609DEFAULT_OPTIONS = Option(