Changeset 139

Show
Ignore:
Timestamp:
01/31/09 03:07:13 (3 years ago)
Author:
lgs
Message:

Index the ticks by xval and not name. This fixes a broken example

Location:
trunk
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • trunk/pycha/pie.py

    r110 r139  
    6060        self.xticks = [] 
    6161        if self.options.axis.x.ticks: 
    62             lookup = dict([(slice.name, slice) for slice in self.slices]) 
     62            lookup = dict([(slice.xval, slice) for slice in self.slices]) 
    6363            for tick in self.options.axis.x.ticks: 
    6464                if not isinstance(tick, Option): 
    6565                    tick = Option(tick) 
    66                 slice = lookup[tick.v] 
     66                slice = lookup.get(tick.v, None) 
    6767                label = tick.label or str(tick.v) 
    68                 if slice: 
     68                if slice is not None: 
    6969                    label += ' (%.1f%%)' % (slice.fraction * 100) 
    7070                    self.xticks.append((tick.v, label)) 
     
    7272            for slice in self.slices: 
    7373                label = '%s (%.1f%%)' % (slice.name, slice.fraction * 100) 
    74                 self.xticks.append((slice.name, label)) 
     74                self.xticks.append((slice.xval, label)) 
    7575 
    7676    def _renderBackground(self, cx): 
     
    130130 
    131131        self.xlabels = [] 
    132         lookup = dict([(slice.name, slice) for slice in self.slices]) 
     132        lookup = dict([(slice.xval, slice) for slice in self.slices]) 
    133133 
    134134        cx.set_source_rgb(*hex2rgb(self.options.axis.labelColor)) 
  • trunk/tests/pie.py

    r112 r139  
    120120        ch._updateChart() 
    121121        ch._updateTicks() 
    122         self.assertEqual(ch.xticks, [('dataset1', 'dataset1 (10.0%)'), 
    123                                      ('dataset2', 'dataset2 (20.0%)'), 
    124                                      ('dataset3', 'dataset3 (70.0%)')]) 
     122        self.assertEqual(ch.xticks, [(0, 'dataset1 (10.0%)'), 
     123                                     (1, 'dataset2 (20.0%)'), 
     124                                     (2, 'dataset3 (70.0%)')]) 
     125 
     126        ticks = [{'v': 0, 'label': 'First dataset'}, 
     127                 {'v': 1, 'label': 'Second dataset'}, 
     128                 {'v': 2, 'label': 'Third dataset'}] 
     129        opt = {'axis': {'x': {'ticks': ticks},},} 
     130        ch = pycha.pie.PieChart(surface, opt) 
     131        ch.addDataset(dataset) 
     132        ch._updateXY() 
     133        ch._updateChart() 
     134        ch._updateTicks() 
     135        self.assertEqual(ch.xticks, [(0, 'First dataset (10.0%)'), 
     136                                     (1, 'Second dataset (20.0%)'), 
     137                                     (2, 'Third dataset (70.0%)')]) 
    125138 
    126139