/+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 07:41:13 UTC
  • Revision ID: git-v1:76610bda260bfbf489d5e7efddca4313cc1bafd4
 - Fixed line endings to UNIX
 - Fixed Hashbangs
 - Added GPL headers

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-2009 Gerald Kaszuba
 
6
Copyright 2007-2008 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.3.0'
 
36
__version__ = '0.2.2'
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
90
88
 
91
89
# Data Classes
92
90
# -----------------------------------------------------------------------------
956
954
        Chart.__init__(self, *args, **kwargs)
957
955
        self.geo_area = 'world'
958
956
        self.codes = []
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
 
        
 
957
 
986
958
    def type_to_url(self):
987
959
        return 'cht=t'
988
960
 
989
961
    def set_codes(self, 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)
 
962
        self.codes = codes
1025
963
 
1026
964
    def get_url_bits(self, data_class=None):
1027
965
        url_bits = Chart.get_url_bits(self, data_class=data_class)
1030
968
            url_bits.append('chld=%s' % ''.join(self.codes))
1031
969
        return url_bits
1032
970
 
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
 
 
1042
971
 
1043
972
class GoogleOMeterChart(PieChart):
1044
973
    """Inheriting from PieChart because of similar labeling"""