Changeset 109 for trunk/src/bar.py
- Timestamp:
- 10/27/08 16:49:58 (4 years ago)
- Files:
-
- 1 modified
-
trunk/src/bar.py (modified) (10 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/bar.py
r97 r109 17 17 18 18 from pycha.chart import Chart, uniqueIndices 19 from pycha.color import hex2rgb , clamp19 from pycha.color import hex2rgb 20 20 21 21 class BarChart(Chart): … … 28 28 self.barMargin = 0.0 29 29 30 def _updateXY(self): 31 super(BarChart, self)._updateXY() 32 # each dataset is centered around a line segment. that's why we 33 # need n + 1 divisions on the x axis 34 self.xscale = 1 / (self.xrange + 1.0) 35 30 36 def _updateChart(self): 31 37 """Evaluates measures for vertical bars""" … … 36 42 if len(uniqx) == 1: 37 43 xdelta = 1.0 38 self.xscale = 1.039 self.minxval = uniqx[0]40 44 barWidth = 1.0 * self.options.barWidthFillFraction 41 45 self.barWidthForSet = barWidth / len(stores) … … 44 48 xdelta = min([abs(uniqx[j] - uniqx[j-1]) 45 49 for j in range(1, len(uniqx))]) 46 self.xscale = 1.0 / (self.xrange + 1)47 50 barWidth = xdelta * self.xscale * self.options.barWidthFillFraction 48 51 self.barWidthForSet = barWidth / len(stores) … … 57 60 58 61 def drawBar(bar): 59 cx.set_line_width(self.options.stroke.width) 62 stroke_width = self.options.stroke.width 63 ux, uy = cx.device_to_user_distance(stroke_width, stroke_width) 64 if ux < uy: 65 ux = uy 66 cx.set_line_width(ux) 60 67 61 68 # gather bar proportions … … 74 81 cx.fill() 75 82 76 if self.options.shouldFill :83 if self.options.shouldFill or (not self.options.stroke.hide): 77 84 cx.rectangle(x, y, w, h) 78 cx.set_source_rgb(*self.options.colorScheme[bar.name])79 cx.fill_preserve()80 85 81 if not self.options.stroke.hide: 82 cx.set_source_rgb(*hex2rgb(self.options.stroke.color)) 83 cx.stroke() 86 if self.options.shouldFill: 87 cx.set_source_rgb(*self.options.colorScheme[bar.name]) 88 cx.fill_preserve() 89 90 if not self.options.stroke.hide: 91 cx.set_source_rgb(*hex2rgb(self.options.stroke.color)) 92 cx.stroke() 84 93 85 94 cx.save() … … 93 102 """Evaluates measures for vertical bars""" 94 103 super(VerticalBarChart, self)._updateChart() 95 96 104 for i, (name, store) in enumerate(self.datasets): 97 105 for item in store: 98 106 xval, yval = item 99 107 x = (((xval - self.minxval) * self.xscale) 100 + (i * self.barWidthForSet) + self.barMargin)108 + self.barMargin + (i * self.barWidthForSet)) 101 109 w = self.barWidthForSet 102 h = (yval - self.minyval) * self.yscale 103 y = 1.0 - h 110 h = abs(yval) * self.yscale 111 if yval > 0: 112 y = (1.0 - h) - self.area.origin 113 else: 114 y = 1 - self.area.origin 104 115 rect = Rect(x, y, w, h, xval, yval, name) 105 116 … … 127 138 xval, yval = item 128 139 y = (((xval - self.minxval) * self.xscale) 129 + (i * self.barWidthForSet) + self.barMargin) 130 x = 0.0 140 + self.barMargin + (i * self.barWidthForSet)) 131 141 h = self.barWidthForSet 132 w = (yval - self.minyval) * self.yscale 142 w = abs(yval) * self.yscale 143 if yval > 0: 144 x = self.area.origin 145 else: 146 x = self.area.origin - w 133 147 rect = Rect(x, y, w, h, xval, yval, name) 134 148 … … 153 167 return (x, y-2, w+2, h+4) 154 168 169 def _renderXAxis(self, cx): 170 """Draws the horizontal line representing the X axis""" 171 cx.new_path() 172 cx.move_to(self.area.x, self.area.y + self.area.h) 173 cx.line_to(self.area.x + self.area.w, self.area.y + self.area.h) 174 cx.close_path() 175 cx.stroke() 176 177 def _renderYAxis(self, cx): 178 # draws the vertical line representing the Y axis 179 cx.new_path() 180 cx.move_to(self.area.x + self.area.origin * self.area.w, 181 self.area.y) 182 cx.line_to(self.area.x + self.area.origin * self.area.w, 183 self.area.y + self.area.h) 184 cx.close_path() 185 cx.stroke() 155 186 156 187 class Rect(object): … … 161 192 162 193 def __str__(self): 163 return "<pycha.bar.Rect@(%.2f, %.2f) %.2fx%.2f>" % (self.x, self.y, 164 self.w, self.h) 194 return ("<pycha.bar.Rect@(%.2f, %.2f) %.2fx%.2f (%.2f, %.2f) %s>" 195 % (self.x, self.y, self.w, self.h, self.xval, self.yval, 196 self.name))
