Changeset 140 for trunk/pycha/chart.py
- Timestamp:
- 02/03/09 16:08:23 (3 years ago)
- Files:
-
- 1 modified
-
trunk/pycha/chart.py (modified) (13 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/pycha/chart.py
r138 r140 1 # Copyright (c) 2007-2008by Lorenzo Gil Sanchez <lorenzo.gil.sanchez@gmail.com>1 # Copyright(c) 2007-2009 by Lorenzo Gil Sanchez <lorenzo.gil.sanchez@gmail.com> 2 2 # 3 3 # This file is part of PyCha. … … 24 24 DEFAULT_COLOR) 25 25 26 26 27 class Chart(object): 27 28 … … 132 133 self.clean() 133 134 134 135 # update methods136 135 def _update(self, options={}): 137 136 """Update all the information needed to render the chart""" … … 154 153 self.minxval, self.maxxval = self.options.axis.x.range 155 154 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)] 157 156 self.minxval = float(min(xdata)) 158 157 self.maxxval = float(max(xdata)) … … 170 169 self.minyval, self.maxyval = self.options.axis.y.range 171 170 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)] 173 172 self.minyval = float(min(ydata)) 174 173 self.maxyval = float(max(ydata)) … … 228 227 roughSeparation = self.xrange / self.options.axis.x.tickCount 229 228 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: 231 230 if (uniqx[i] - self.minxval) >= (j * roughSeparation): 232 231 pos = self.xscale * (uniqx[i] - self.minxval) … … 264 263 self.yticks.append((pos, round(yval, prec))) 265 264 266 # render methods267 265 def _renderBackground(self, cx): 268 266 """Renders the background area of the chart""" … … 330 328 cx.stroke() 331 329 332 label = unicode(tick[1])330 label = unicode(tick[1]) 333 331 extents = cx.text_extents(label) 334 332 labelWidth = extents[2] … … 387 385 388 386 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] 390 389 tickWidth = tickHeight = 0.0 391 390 if tickExtents: … … 399 398 cosRadians = math.cos(radians) 400 399 maxHeight = maxWidth * sinRadians + maxHeight * cosRadians 401 maxWidth = maxWidth * cosRadians + maxHeight * sinRadians400 maxWidth = maxWidth * cosRadians + maxHeight * sinRadians 402 401 tickWidth += maxWidth 403 402 tickHeight += maxHeight 404 403 return tickWidth, tickHeight 405 404 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): 407 407 cx.new_path() 408 408 cx.select_font_face(self.options.axis.labelFont, … … 570 570 cx.restore() 571 571 572 572 573 def uniqueIndices(arr): 573 574 """Return a list with the indexes of the biggest element of arr""" 574 575 return range(max([len(a) for a in arr])) 575 576 577 576 578 class Area(object): 577 579 """Simple rectangle to hold an area coordinates and dimensions""" 580 578 581 def __init__(self, x, y, w, h, origin=0.0): 579 582 self.x, self.y, self.w, self.h = x, y, w, h … … 584 587 return msg % (self.x, self.y, self.w, self.h, self.origin) 585 588 589 586 590 class Option(dict): 587 591 """Useful dict that allow attribute-like access to its keys""" 592 588 593 def __getattr__(self, name): 589 594 if name in self.keys(): … … 595 600 """Recursive merge with other Option or dict object""" 596 601 for key, value in other.items(): 597 if self.has_key(key):602 if key in self: 598 603 if isinstance(self[key], Option): 599 604 self[key].merge(other[key]) 600 605 else: 601 606 self[key] = other[key] 607 602 608 603 609 DEFAULT_OPTIONS = Option(
