Changeset 76 for trunk

Show
Ignore:
Timestamp:
03/20/08 05:52:06 (4 years ago)
Author:
lgs
Message:

Make bar charts more robust by allowing datasets with just one point. Patch by jae_AT_zhar.net that fixes #9

Location:
trunk
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • trunk/src/bar.py

    r73 r76  
    3232        stores = self._getDatasetsValues() 
    3333        uniqx = uniqueIndices(stores) 
    34         xdelta = min([abs(uniqx[j] - uniqx[j-1]) for j in range(1, len(uniqx))]) 
    3534 
    3635        barWidth = 0 
     
    4342            self.barMargin = (1.0 - self.options.barWidthFillFraction) / 2 
    4443        else: 
     44            xdelta = min([abs(uniqx[j] - uniqx[j-1]) 
     45                          for j in range(1, len(uniqx))]) 
    4546            self.xscale = 1.0 / (self.xrange + 1) 
    4647            barWidth = xdelta * self.xscale * self.options.barWidthFillFraction 
  • trunk/tests/bar.py

    r73 r76  
    4040        self.assertEqual(ch.bars, []) 
    4141        self.assertEqual(ch.minxdelta, 0) 
     42 
     43    def test_updateChart(self): 
     44        surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, 500, 500) 
     45        # An evil dataset with just one point. See bug #9 
     46        dataset = ( 
     47            ('dataset1', ([0, 0],)), 
     48        ) 
     49        ch = pycha.bar.BarChart(surface) 
     50        ch.addDataset(dataset) 
     51        ch._updateXY() 
     52        ch._updateChart() 
     53 
     54        self.assertEqual(ch.xscale, 1.0) 
     55        self.assertEqual(ch.minxval, 0) 
     56        self.assertAlmostEqual(ch.barWidthForSet, 0.75, 4) 
     57        self.assertAlmostEqual(ch.barMargin, 0.125, 4) 
    4258 
    4359class VerticalBarTests(unittest.TestCase):