/+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: 2008-05-03 01:40:52 UTC
  • Revision ID: git-v1:4b54ecc4ee7571d59880977ef8dcbf74c4367335
- initial unit tests
- updated dist scripts

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 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
82
82
    @classmethod
83
83
    def float_scale_value(cls, value, range):
84
84
        lower, upper = range
 
85
        assert(upper > lower)
85
86
        max_value = cls.max_value()
86
 
        scaled = (value-lower) * (float(max_value)/(upper-lower))
 
87
        scaled = (value-lower) * (float(max_value) / (upper - lower))
87
88
        return scaled
88
89
 
89
90
    @classmethod
90
91
    def clip_value(cls, value):
91
 
        clipped = max(0, min(value, cls.max_value()))
92
 
        return clipped
 
92
        return max(0, min(value, cls.max_value()))
93
93
 
94
94
    @classmethod
95
95
    def int_scale_value(cls, value, range):
96
 
        scaled = int(round(cls.float_scale_value(value, range)))
97
 
        return scaled
 
96
        return int(round(cls.float_scale_value(value, range)))
98
97
 
99
98
    @classmethod
100
99
    def scale_value(cls, value, range):
151
150
 
152
151
    @classmethod
153
152
    def scale_value(cls, value, range):
154
 
        lower, upper = range
155
 
        if upper > lower:
156
 
            max_value = cls.max_value()
157
 
            scaled = (float(value) - lower) * max_value / upper
158
 
            clipped = max(0, min(scaled, max_value))
159
 
            return clipped
160
 
        else:
161
 
            return lower
162
 
 
163
 
    @classmethod
164
 
    def scale_value(cls, value, range):
165
153
        # use float values instead of integers because we don't need an encode
166
154
        # map index
167
155
        scaled = cls.float_scale_value(value, range)
170
158
 
171
159
 
172
160
class ExtendedData(Data):
 
161
 
173
162
    enc_map = \
174
163
        'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-.'
175
164
 
204
193
 
205
194
 
206
195
class Axis(object):
 
196
 
207
197
    BOTTOM = 'x'
208
198
    TOP = 't'
209
199
    LEFT = 'y'
491
481
        try:
492
482
            lower = min([min(s) for type, s in self.annotated_data()
493
483
                         if type == 'y'])
494
 
            upper = max([max(s) for type, s in self.annotated_data()
 
484
            upper = max([max(s) + 1 for type, s in self.annotated_data()
495
485
                         if type == 'y'])
496
486
            return (lower, upper)
497
487
        except ValueError:
549
539
        if not issubclass(data_class, Data):
550
540
            raise UnknownDataTypeException()
551
541
        if self.auto_scale:
 
542
            print data_class
552
543
            data = self.scaled_data(data_class, self.x_range, self.y_range)
553
544
        else:
554
545
            data = self.data
919
910
#    chart.set_bar_spacing(0)
920
911
    chart.add_data(sine_data)
921
912
    chart.add_data(random_data)
922
 
    chart.set_zero_line(1, .5)
 
913
#    chart.set_zero_line(1, .5)
923
914
#    chart.add_data(random_data2)
924
915
#    chart.set_line_style(0, thickness=5)
925
916
#    chart.set_line_style(1, thickness=2, line_segment=10, blank_segment=5)