Changeset 176
- Timestamp:
- 03/22/09 03:38:17 (3 years ago)
- Location:
- trunk
- Files:
-
- 3 modified
-
pycha/bar.py (modified) (1 diff)
-
pycha/stackedbar.py (modified) (1 diff)
-
tests/bar.py (modified) (13 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/pycha/bar.py
r169 r176 40 40 uniqx = uniqueIndices(stores) 41 41 42 barWidth = 043 42 if len(uniqx) == 1: 44 xdelta = 1.0 45 barWidth = 1.0 * self.options.barWidthFillFraction 46 self.barWidthForSet = barWidth / len(stores) 47 self.barMargin = (1.0 - self.options.barWidthFillFraction) / 2 43 self.minxdelta = 1.0 48 44 else: 49 xdelta = min([abs(uniqx[j] - uniqx[j-1])50 for j in range(1, len(uniqx))])51 barWidth = xdelta * self.xscale * self.options.barWidthFillFraction 52 self.barWidthForSet = barWidth / len(stores)53 self.barMargin = (xdelta * self.xscale54 * (1.0 - self.options.barWidthFillFraction) / 2)55 56 self.minxdelta = xdelta 45 self.minxdelta = min([abs(uniqx[j] - uniqx[j-1]) 46 for j in range(1, len(uniqx))]) 47 48 k = self.minxdelta * self.xscale 49 barWidth = k * self.options.barWidthFillFraction 50 self.barWidthForSet = barWidth / len(stores) 51 self.barMargin = k * (1.0 - self.options.barWidthFillFraction) / 2 52 57 53 self.bars = [] 58 54 -
trunk/pycha/stackedbar.py
r164 r176 53 53 uniqx = uniqueIndices(stores) 54 54 55 barWidth = 056 55 if len(uniqx) == 1: 57 xdelta = 1.0 58 self.barWidth = 1.0 * self.options.barWidthFillFraction 59 self.barMargin = (1.0 - self.options.barWidthFillFraction) / 2 56 self.minxdelta = 1.0 60 57 else: 61 xdelta = min([abs(uniqx[j] - uniqx[j-1]) 62 for j in range(1, len(uniqx))]) 63 self.barWidth = (xdelta * self.xscale 64 * self.options.barWidthFillFraction) 65 self.barMargin = (xdelta * self.xscale 66 * (1.0 - self.options.barWidthFillFraction) / 2) 58 self.minxdelta = min([abs(uniqx[j] - uniqx[j-1]) 59 for j in range(1, len(uniqx))]) 67 60 68 self.minxdelta = xdelta 61 k = self.minxdelta * self.xscale 62 self.barWidth = k * self.options.barWidthFillFraction 63 self.barMargin = k * (1.0 - self.options.barWidthFillFraction) / 2 64 69 65 self.bars = [] 70 66 -
trunk/tests/bar.py
r112 r176 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. … … 22 22 import pycha.bar 23 23 24 24 25 class RectTests(unittest.TestCase): 25 26 … … 34 35 self.assertEqual(r.name, 'test') 35 36 37 36 38 class BarTests(unittest.TestCase): 37 39 … … 45 47 # An evil dataset with just one point. See bug #9 46 48 dataset = ( 47 ('dataset1', ([0, 0], )),49 ('dataset1', ([0, 0], )), 48 50 ) 49 51 ch = pycha.bar.BarChart(surface) … … 54 56 self.assertEqual(ch.xscale, 1.0) 55 57 self.assertEqual(ch.minxval, 0) 58 self.assertEqual(ch.minxdelta, 1.0) 56 59 self.assertAlmostEqual(ch.barWidthForSet, 0.75, 4) 57 60 self.assertAlmostEqual(ch.barMargin, 0.125, 4) 61 62 def test_customRangeWithOnePoint(self): 63 """Weird results with a custom range and just one point. See bug #20""" 64 surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, 500, 500) 65 66 dataset = ( 67 ('dataset1', ([0, 1], )), 68 ) 69 options = { 70 'axis': { 71 'x': { 72 'range': (0.0, 4.0), 73 }, 74 }, 75 } 76 ch = pycha.bar.BarChart(surface, options) 77 ch.addDataset(dataset) 78 ch._updateXY() 79 ch._updateChart() 80 81 self.assertEqual(ch.xscale, 0.2) 82 self.assertEqual(ch.minxval, 0) 83 self.assertEqual(ch.minxdelta, 1.0) 84 self.assertAlmostEqual(ch.barWidthForSet, 0.15, 2) 85 self.assertAlmostEqual(ch.barMargin, 0.025, 3) 86 58 87 59 88 class VerticalBarTests(unittest.TestCase): … … 132 161 R(0.03125, 0.625, 0.1875, 0.375, 0, -3, 'dataset1'), 133 162 R(0.28125, 0.625, 0.1875, 0.125, 1, -1, 'dataset1'), 134 R(0.53125, 0.250, 0.1875, 0.375, 2, 3, 'dataset1'),135 R(0.78125, 0.000, 0.1875, 0.625, 3, 5, 'dataset1'),163 R(0.53125, 0.250, 0.1875, 0.375, 2, 3, 'dataset1'), 164 R(0.78125, 0.000, 0.1875, 0.625, 3, 5, 'dataset1'), 136 165 ) 137 166 … … 165 194 (1.0, 0.0), (0.9, 0.4), (0.8, 0.8), (0.7, 1.2), (0.6, 1.6), 166 195 (0.5, 2.0), (0.4, 2.4), (0.3, 2.8), (0.2, 3.2), (0.1, 3.6), 167 (0.0, 4.0) 196 (0.0, 4.0), 168 197 ] 169 198 for i in range(len(yticks)): … … 189 218 (1.0, -2.0), (0.9, -1.5), (0.8, -1.0), (0.7, -0.5), (0.6, 0.0), 190 219 (0.5, 0.5), (0.4, 1.0), (0.3, 1.5), (0.2, 2.0), (0.1, 2.5), 191 (0.0, 3.0) 220 (0.0, 3.0), 192 221 ] 193 222 for i in range(len(yticks)): … … 199 228 shadow = ch._getShadowRectangle(10, 20, 400, 300) 200 229 self.assertEqual(shadow, (8, 18, 404, 302)) 230 201 231 202 232 class HorizontalBarTests(unittest.TestCase): … … 295 325 (0.0, 0.0), (0.1, 0.4), (0.2, 0.8), (0.3, 1.2), (0.4, 1.6), 296 326 (0.5, 2.0), (0.6, 2.4), (0.7, 2.8), (0.8, 3.2), (0.9, 3.6), 297 (1.0, 4.0) 327 (1.0, 4.0), 298 328 ] 299 329 for i in range(len(xticks)): … … 319 349 (0.0, -2.0), (0.1, -1.5), (0.2, -1.0), (0.3, -0.5), (0.4, 0.0), 320 350 (0.5, 0.5), (0.6, 1.0), (0.7, 1.5), (0.8, 2.0), (0.9, 2.5), 321 (1.0, 3.0) 351 (1.0, 3.0), 322 352 ] 323 353 for i in range(len(xticks)): … … 334 364 shadow = ch._getShadowRectangle(10, 20, 400, 300) 335 365 self.assertEqual(shadow, (10, 18, 402, 304)) 366 336 367 337 368 def test_suite(): … … 345 376 if __name__ == '__main__': 346 377 unittest.main(defaultTest='test_suite') 347
