Changeset 140 for trunk

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

Location:
trunk/pycha
Files:
7 modified

Legend:

Unmodified
Added
Removed
  • trunk/pycha/__init__.py

    r130 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. 
  • trunk/pycha/bar.py

    r112 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. 
     
    1818from pycha.chart import Chart, uniqueIndices 
    1919from pycha.color import hex2rgb 
     20 
    2021 
    2122class BarChart(Chart): 
     
    9697            drawBar(bar) 
    9798        cx.restore() 
     99 
    98100 
    99101class VerticalBarChart(BarChart): 
     
    138140                xval, yval = item 
    139141                y = (((xval - self.minxval) * self.xscale) 
    140                      + self.barMargin  + (i * self.barWidthForSet)) 
     142                     + self.barMargin + (i * self.barWidthForSet)) 
    141143                h = self.barWidthForSet 
    142144                w = abs(yval) * self.yscale 
     
    155157        offset = (self.minxdelta * self.xscale) / 2 
    156158        tmp = self.xticks 
    157         self.xticks = [(1.0 - tick[0], tick[1]) for tick in self.yticks ] 
     159        self.xticks = [(1.0 - tick[0], tick[1]) for tick in self.yticks] 
    158160        self.yticks = [(tick[0] + offset, tick[1]) for tick in tmp] 
    159161 
     
    185187        cx.stroke() 
    186188 
     189 
    187190class Rect(object): 
     191 
    188192    def __init__(self, x, y, w, h, xval, yval, name): 
    189193        self.x, self.y, self.w, self.h = x, y, w, h 
  • 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( 
  • trunk/pycha/color.py

    r96 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. 
     
    1818DEFAULT_COLOR = '#3c581a' 
    1919 
     20 
    2021def clamp(minValue, maxValue, value): 
    2122    """Make sure value is between minValue and maxValue""" 
     
    2526        return maxValue 
    2627    return value 
     28 
    2729 
    2830def hex2rgb(hexstring, digits=2): 
     
    4345    return r / top, g / top, b / top 
    4446 
     47 
    4548def lighten(r, g, b, amount): 
    4649    """Return a lighter version of the color (r, g, b)""" 
     
    4851            clamp(0.0, 1.0, g + amount), 
    4952            clamp(0.0, 1.0, b + amount)) 
     53 
    5054 
    5155def generateColorscheme(masterColor, keys): 
     
    6367                 for i, key in enumerate(keys)]) 
    6468 
     69 
    6570def defaultColorscheme(keys): 
    6671    """Return the default color scheme (derived from a dark green)""" 
    6772    return generateColorscheme(DEFAULT_COLOR, keys) 
     73 
    6874 
    6975def getColorscheme(color, keys): 
     
    7278    """ 
    7379    return generateColorscheme(colorSchemes.get(color, color), keys) 
     80 
    7481 
    7582# default colors for color schemes 
     
    8087    grey='#444444', 
    8188    black='#000000', 
    82     darkcyan='#305755' 
     89    darkcyan='#305755', 
    8390    ) 
  • trunk/pycha/line.py

    r109 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. 
     
    1818from pycha.chart import Chart 
    1919from pycha.color import hex2rgb 
     20 
    2021 
    2122class LineChart(Chart): 
     
    4142    def _renderChart(self, cx): 
    4243        """Renders a line chart""" 
     44 
    4345        def preparePath(storeName): 
    4446            cx.new_path() 
     
    4850                # Go to the (0,0) coordinate to start drawing the area 
    4951                #cx.move_to(self.area.x, self.area.y + self.area.h) 
    50                 cx.move_to(self.area.x, 
    51                            self.area.y + (1.0 - self.area.origin) * self.area.h) 
     52                offset = (1.0 - self.area.origin) * self.area.h 
     53                cx.move_to(self.area.x, self.area.y + offset) 
    5254 
    5355            for point in self.points: 
     
    7981        cx.set_line_width(self.options.stroke.width) 
    8082        if self.options.shouldFill: 
     83 
    8184            def drawLine(storeName): 
    8285                if self.options.stroke.shadow: 
     
    109112        cx.restore() 
    110113 
     114 
    111115class Point(object): 
     116 
    112117    def __init__(self, x, y, xval, yval, name): 
    113118        self.x, self.y = x, y 
  • trunk/pycha/pie.py

    r139 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. 
     
    2222from pycha.chart import Chart, Option 
    2323from pycha.color import hex2rgb 
     24 
    2425 
    2526class PieChart(Chart): 
     
    139140            normalisedAngle = slice.getNormalisedAngle() 
    140141 
    141             labelx = self.centerx + math.sin(normalisedAngle) * (self.radius + 10) 
    142             labely = self.centery - math.cos(normalisedAngle) * (self.radius + 10) 
     142            big_radius = self.radius + 10 
     143            labelx = self.centerx + math.sin(normalisedAngle) * big_radius 
     144            labely = self.centery - math.cos(normalisedAngle) * big_radius 
    143145 
    144146            label = tick[1] 
     
    168170 
    169171class Slice(object): 
     172 
    170173    def __init__(self, name, fraction, xval, yval, angle): 
    171174        self.name = name 
  • trunk/pycha/scatter.py

    r109 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. 
     
    1818from pycha.line import LineChart 
    1919 
     20 
    2021class ScatterplotChart(LineChart): 
    2122 
    2223    def _renderChart(self, cx): 
    2324        """Renders a scatterplot""" 
     25 
    2426        def drawSymbol(point, size=2): 
    2527            ox = point.x * self.area.w + self.area.x 
    2628            oy = point.y * self.area.h + self.area.y 
    27             cx.move_to(ox-size, oy  ) 
    28             cx.line_to(ox+size, oy  ) 
    29             cx.move_to(ox     , oy-size) 
    30             cx.line_to(ox     , oy+size) 
     29            cx.move_to(ox-size, oy) 
     30            cx.line_to(ox+size, oy) 
     31            cx.move_to(ox, oy-size) 
     32            cx.line_to(ox, oy+size) 
    3133 
    3234        def preparePath(storeName, size=2):