[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 line_style
16 import pychart_util
17 import chart_object
18 import fill_style
19 import legend
20 import range_plot_doc
21 from pychart_types import *
22 from types import *
23 from scaling import *
24
25
26 class T(chart_object.T):
27     __doc__ = range_plot_doc.doc
28     keys = {
29         "data" : (AnyType, None, pychart_util.data_desc),
30         "label": (StringType, "???", pychart_util.label_desc),
31         "xcol" : (IntType, 0, pychart_util.xcol_desc),
32         "min_col": (IntType, 1,
33                    "The lower bound of the sweep is extracted from "
34                    + "this column of data."),
35         "max_col": (IntType, 2, 
36                    "The upper bound of the sweep is extracted from "
37                    + "this column of data."),
38         "line_style": (line_style.T, line_style.default,
39                       "The style of the boundary line."),
40         "fill_style": (fill_style.T, fill_style.default,
41                       ""),
42         }
43     
44 ##AUTOMATICALLY GENERATED
45
46 ##END AUTOMATICALLY GENERATED
47
48     def check_integrity(self):
49         self.type_check()
50     def get_data_range(self, which):
51         if which == 'X':
52             return pychart_util.get_data_range(self.data, self.xcol)
53         else:
54             ymax = (pychart_util.get_data_range(self.data, self.max_col))[1]
55             ymin = (pychart_util.get_data_range(self.data, self.min_col))[0]
56             return (ymin, ymax)
57     def get_legend_entry(self):
58         if self.label:
59             return legend.Entry(line_style=self.line_style,
60                                 fill_style=self.fill_style,
61                                 label=self.label)
62         return None
63
64     def draw(self, ar, can):
65         
66         prevPair = None
67
68         xmin=999999
69         xmax=-999999
70         ymin=999999
71         ymax=-999999
72
73         # Draw the boundary in a single stroke.
74         can.gsave()
75         can.newpath()
76         for pair in self.data:
77             x = pair[self.xcol]
78             y = pychart_util.get_sample_val(pair, self.max_col)
79             if y == None:
80                 continue
81             
82             xmin = min(xmin, ar.x_pos(x))
83             xmax = max(xmax, ar.x_pos(x))
84             ymin = min(ymin, ar.y_pos(y))
85             ymax = max(ymax, ar.y_pos(y))
86             if prevPair != None:
87                 can.lineto(xscale(ar.x_pos(x)), yscale(ar.y_pos(y)))
88             else:
89                 can.moveto(xscale(ar.x_pos(x)), yscale(ar.y_pos(y)))
90             prevPair = pair
91
92         for i in range(len(self.data)-1, -1, -1):
93             pair = self.data[i]
94             x = pair[self.xcol]
95             y = pychart_util.get_sample_val(pair, self.min_col)
96             if None in (x, y):
97                 continue
98
99             xmin = min(xmin, ar.x_pos(x))
100             xmax = max(xmax, ar.x_pos(x))
101             ymin = min(ymin, ar.y_pos(y))
102             ymax = max(ymax, ar.y_pos(y))
103             can.lineto(xscale(ar.x_pos(x)), yscale(ar.y_pos(y)))
104         can.closepath()
105
106         # create a clip region, and fill it.
107         can.clip_sub()
108         can.fill_with_pattern(self.fill_style, xmin, ymin, xmax, ymax)
109         can.grestore()
110
111         if self.line_style: 
112             # draw the boundary.
113             prevPair = None
114             can.newpath()
115             can.set_line_style(self.line_style)
116             for pair in self.data:
117                 x = pair[self.xcol]
118                 y = pychart_util.get_sample_val(pair, self.min_col)
119                 if None in (x, y):
120                     continue
121
122                 if prevPair != None:
123                     can.lineto(xscale(ar.x_pos(x)), yscale(ar.y_pos(y)))
124                 else:
125                     can.moveto(xscale(ar.x_pos(x)), yscale(ar.y_pos(y)))
126                 prevPair = pair
127             can.stroke()
128
129             prevPair = None
130             can.newpath()
131             can.set_line_style(self.line_style)
132             for pair in self.data:
133                 x = pair[self.xcol]
134                 y = pychart_util.get_sample_val(pair, self.max_col)
135                 if y == None:
136                     continue
137
138                 if prevPair != None:
139                     can.lineto(xscale(ar.x_pos(x)), yscale(ar.y_pos(y)))
140                 else:
141                     can.moveto(xscale(ar.x_pos(x)), yscale(ar.y_pos(y)))
142                 prevPair = pair
143             can.stroke()
144
145