[MERGE] Remove the embedded pychart library, and use the online version
[odoo/odoo.git] /
1 # -*- coding: utf-8 -*-
2 #
3 # Copyright (C) 2000-2005 by Yasushi Saito (yasushi.saito@gmail.com)
4
5 # Jockey is free software; you can redistribute it and/or modify it
6 # under the terms of the GNU General Public License as published by the
7 # Free Software Foundation; either version 2, or (at your option) any
8 # later version.
9 #
10 # Jockey is distributed in the hope that it will be useful, but WITHOUT
11 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 # FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
13 # for more details.
14 #
15 import coord
16 import math
17
18 class T(coord.T):
19     def get_canvas_pos(self, size, val, min, max):
20         if val <= 0:
21             return 0
22         xminl = math.log(min)
23         xmaxl = math.log(max)
24         vl = math.log(val)
25         return size * (vl-xminl) / float(xmaxl-xminl)
26     def get_tics(self, min, max, interval):
27         "Generate the list of places for drawing tick marks."
28         v = []
29         if min <= 0:
30             raise Exception, "Min value (%s) < 0 in a log coordinate." % min
31         x = min
32         while x <= max:
33             v.append(x)
34             x = x * interval
35         return v
36     def get_min_max(self, dmin, dmax, interval):
37         interval = interval or 10
38         dmin = max(0, dmin) # we can't have a negative value with a log scale.
39         v = 1.0
40         while v > dmin:
41             v = v / interval
42         dmin = v
43         v = 1.0
44         while v < dmax:
45             v = v * interval
46         dmax = v
47
48         return dmin, dmax, interval
49