Sections
Timeline
View Tickets
New Ticket
Sub-Sections
Download
Unified Diff
Zip Archive
Metanav
Preferences
About Trac
Links
Slowchop Studios
Gerald Kaszuba
Advertisement

Changeset 45

Show
Ignore:
Timestamp:
23/08/08 06:46:04 (3 months ago)
Author:
gak
Message:
  • Bug fixed when automatic scaling is on and None values are in a data set (#5) (Alec Thomas)
Location:
trunk
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • trunk/pygooglechart.py

    r44 r45  
    499499            return ExtendedData 
    500500 
     501    def _filter_none(self, data): 
     502        return [r for r in data if r is not None] 
     503 
    501504    def data_x_range(self): 
    502505        """Return a 2-tuple giving the minimum and maximum x-axis 
     
    504507        """ 
    505508        try: 
    506             lower = min([min(s) for type, s in self.annotated_data() 
     509            lower = min([min(self._filter_none(s)) 
     510                         for type, s in self.annotated_data() 
    507511                         if type == 'x']) 
    508             upper = max([max(s) for type, s in self.annotated_data() 
     512            upper = max([max(self._filter_none(s)) 
     513                         for type, s in self.annotated_data() 
    509514                         if type == 'x']) 
    510515            return (lower, upper) 
     
    517522        """ 
    518523        try: 
    519             lower = min([min(s) for type, s in self.annotated_data() 
     524            lower = min([min(self._filter_none(s)) 
     525                         for type, s in self.annotated_data() 
    520526                         if type == 'y']) 
    521             upper = max([max(s) + 1 for type, s in self.annotated_data() 
     527            upper = max([max(self._filter_none(s)) + 1 
     528                         for type, s in self.annotated_data() 
    522529                         if type == 'y']) 
    523530            return (lower, upper) 
     
    563570            elif type == 'marker-size': 
    564571                scale_range = (0, max(dataset)) 
    565             scaled_data.append([data_class.scale_value(v, scale_range) 
    566                                 for v in dataset]) 
     572            scaled_dataset = [] 
     573            for v in dataset: 
     574                if v is None: 
     575                    scaled_dataset.append(None) 
     576                else: 
     577                    scaled_dataset.append( 
     578                        data_class.scale_value(v, scale_range)) 
     579            scaled_data.append(scaled_dataset) 
    567580        return scaled_data 
    568581 
  • trunk/test/test.py

    r44 r45  
    3333 
    3434    def assertChartURL(self, url, query): 
    35         return url.endswith(query) 
     35        self.assertTrue(url.endswith(query)) 
    3636 
    3737 
     
    9999 
    100100 
    101 class TestChartQR(TestBase): 
     101class TestLineChart(TestBase): 
     102 
     103    def test_none_data(self): 
     104        chart = gc.SimpleLineChart(300, 100) 
     105        chart.add_data([1, 2, 3, None, 5]) 
     106        self.assertChartURL(chart.get_url(), \ 
     107            '?cht=lc&chs=300x100&chd=e:KrVVgA__1V') 
     108 
     109class TestQRChart(TestBase): 
    102110 
    103111    def assertQRImage(self, chart, text):