/+junk/pygooglechart-py3k

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/%2Bjunk/pygooglechart-py3k

« back to all changes in this revision

Viewing changes to pygooglechart.py

  • Committer: gak
  • Date: 2009-03-15 08:30:28 UTC
  • Revision ID: git-v1:33085bb9ee79265f2d97b0024c1b3bf33db09836
 - Version bump to 0.3.0
 - Fixed GPL date
 - Fixed line 80 overruns

Show diffs side-by-side

added added

removed removed

Lines of Context:
3
3
 
4
4
http://pygooglechart.slowchop.com/
5
5
 
6
 
Copyright 2007-2008 Gerald Kaszuba
 
6
Copyright 2007-2009 Gerald Kaszuba
7
7
 
8
8
This program is free software: you can redistribute it and/or modify
9
9
it under the terms of the GNU General Public License as published by
33
33
# Helper variables and functions
34
34
# -----------------------------------------------------------------------------
35
35
 
36
 
__version__ = '0.2.2'
 
36
__version__ = '0.3.0'
37
37
__author__ = 'Gerald Kaszuba'
38
38
 
39
39
reo_colour = re.compile('^([A-Fa-f0-9]{2,2}){3,4}$')
85
85
class UnknownChartType(PyGoogleChartException):
86
86
    pass
87
87
 
 
88
class UnknownCountryCodeException(PyGoogleChartException):
 
89
    pass
88
90
 
89
91
# Data Classes
90
92
# -----------------------------------------------------------------------------
954
956
        Chart.__init__(self, *args, **kwargs)
955
957
        self.geo_area = 'world'
956
958
        self.codes = []
957
 
 
 
959
        self.__areas = ('africa', 'asia', 'europe', 'middle_east',
 
960
            'south_america', 'usa', 'world')
 
961
        self.__ccodes = (
 
962
            'AD', 'AE', 'AF', 'AG', 'AI', 'AL', 'AM', 'AN', 'AO', 'AQ', 'AR',
 
963
            'AS', 'AT', 'AU', 'AW', 'AX', 'AZ', 'BA', 'BB', 'BD', 'BE', 'BF',
 
964
            'BG', 'BH', 'BI', 'BJ', 'BL', 'BM', 'BN', 'BO', 'BR', 'BS', 'BT',
 
965
            'BV', 'BW', 'BY', 'BZ', 'CA', 'CC', 'CD', 'CF', 'CG', 'CH', 'CI',
 
966
            'CK', 'CL', 'CM', 'CN', 'CO', 'CR', 'CU', 'CV', 'CX', 'CY', 'CZ',
 
967
            'DE', 'DJ', 'DK', 'DM', 'DO', 'DZ', 'EC', 'EE', 'EG', 'EH', 'ER',
 
968
            'ES', 'ET', 'FI', 'FJ', 'FK', 'FM', 'FO', 'FR', 'GA', 'GB', 'GD',
 
969
            'GE', 'GF', 'GG', 'GH', 'GI', 'GL', 'GM', 'GN', 'GP', 'GQ', 'GR',
 
970
            'GS', 'GT', 'GU', 'GW', 'GY', 'HK', 'HM', 'HN', 'HR', 'HT', 'HU',
 
971
            'ID', 'IE', 'IL', 'IM', 'IN', 'IO', 'IQ', 'IR', 'IS', 'IT', 'JE',
 
972
            'JM', 'JO', 'JP', 'KE', 'KG', 'KH', 'KI', 'KM', 'KN', 'KP', 'KR',
 
973
            'KW', 'KY', 'KZ', 'LA', 'LB', 'LC', 'LI', 'LK', 'LR', 'LS', 'LT',
 
974
            'LU', 'LV', 'LY', 'MA', 'MC', 'MD', 'ME', 'MF', 'MG', 'MH', 'MK',
 
975
            'ML', 'MM', 'MN', 'MO', 'MP', 'MQ', 'MR', 'MS', 'MT', 'MU', 'MV',
 
976
            'MW', 'MX', 'MY', 'MZ', 'NA', 'NC', 'NE', 'NF', 'NG', 'NI', 'NL',
 
977
            'NO', 'NP', 'NR', 'NU', 'NZ', 'OM', 'PA', 'PE', 'PF', 'PG', 'PH',
 
978
            'PK', 'PL', 'PM', 'PN', 'PR', 'PS', 'PT', 'PW', 'PY', 'QA', 'RE',
 
979
            'RO', 'RS', 'RU', 'RW', 'SA', 'SB', 'SC', 'SD', 'SE', 'SG', 'SH',
 
980
            'SI', 'SJ', 'SK', 'SL', 'SM', 'SN', 'SO', 'SR', 'ST', 'SV', 'SY',
 
981
            'SZ', 'TC', 'TD', 'TF', 'TG', 'TH', 'TJ', 'TK', 'TL', 'TM', 'TN',
 
982
            'TO', 'TR', 'TT', 'TV', 'TW', 'TZ', 'UA', 'UG', 'UM', 'US', 'UY',
 
983
            'UZ', 'VA', 'VC', 'VE', 'VG', 'VI', 'VN', 'VU', 'WF', 'WS', 'YE',
 
984
            'YT', 'ZA', 'ZM', 'ZW')
 
985
        
958
986
    def type_to_url(self):
959
987
        return 'cht=t'
960
988
 
961
989
    def set_codes(self, codes):
962
 
        self.codes = codes
 
990
        '''Set the country code map for the data.
 
991
        Codes given in a list.
 
992
 
 
993
        i.e. DE - Germany
 
994
             AT - Austria
 
995
             US - United States
 
996
        '''
 
997
 
 
998
        codemap = ''
 
999
        
 
1000
        for cc in codes:
 
1001
            cc = cc.upper()
 
1002
            if cc in self.__ccodes:
 
1003
                codemap += cc
 
1004
            else:
 
1005
                raise UnknownCountryCodeException(cc)
 
1006
            
 
1007
        self.codes = codemap
 
1008
 
 
1009
    def set_geo_area(self, area):
 
1010
        '''Sets the geo area for the map.
 
1011
 
 
1012
        * africa
 
1013
        * asia
 
1014
        * europe
 
1015
        * middle_east
 
1016
        * south_america
 
1017
        * usa
 
1018
        * world
 
1019
        '''
 
1020
        
 
1021
        if area in self.__areas:
 
1022
            self.geo_area = area
 
1023
        else:
 
1024
            raise UnknownChartType('Unknown chart type for maps: %s' %area)
963
1025
 
964
1026
    def get_url_bits(self, data_class=None):
965
1027
        url_bits = Chart.get_url_bits(self, data_class=data_class)
968
1030
            url_bits.append('chld=%s' % ''.join(self.codes))
969
1031
        return url_bits
970
1032
 
 
1033
    def add_data_dict(self, datadict):
 
1034
        '''Sets the data and country codes via a dictionary.
 
1035
 
 
1036
        i.e. {'DE': 50, 'GB': 30, 'AT': 70}
 
1037
        '''
 
1038
 
 
1039
        self.set_codes(datadict.keys())
 
1040
        self.add_data(datadict.values())
 
1041
 
971
1042
 
972
1043
class GoogleOMeterChart(PieChart):
973
1044
    """Inheriting from PieChart because of similar labeling"""