[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 pychart_util
16 import color
17 import line_style
18 import chart_object
19 import object_set
20 import types
21 import theme
22 import fill_style_doc
23 from pychart_types import *
24 from scaling import *
25
26 _keys = {
27     "bgcolor" : (color.T, color.white, "The background color."),
28     "line_style": (line_style.T, line_style.default,
29                    pychart_util.line_desc),
30     "line_interval": (NumType, 3,
31                       "The interval between successive stitch lines.")
32     }
33
34 class T(chart_object.T):
35     __doc__ = fill_style_doc.doc
36     keys = _keys
37 ##AUTOMATICALLY GENERATED
38 ##END AUTOMATICALLY GENERATED
39     def __str__(self):
40         s = name_table().lookup(self)
41         if s:
42             return s
43         return "<fillstyle: bg=%s line=%s interval=%s>" % \
44                (self.bgcolor, self.line_style, self.line_interval)
45
46 class Plain(T):
47     """This class just fills the region with solid background color.
48 Attributes line_style and line_interval are ignored."""
49     def draw(self, can, x1, y1, x2, y2):
50         pass
51     
52 class Diag(T):
53     "This class fills the region with diagonal lines."
54
55     def draw(self, can, x1, y1, x2, y2):
56         line_width = self.line_style.width
57         interval = self.line_interval * 1.414
58         x1 -= line_width
59         y1 -= line_width
60         x2 += line_width
61         y2 += line_width
62         len = max(y2 - y1, x2 - x1)
63         curx = x1 - len
64         while curx < x2:
65             can.line(self.line_style, curx, y1, curx+len, y1+len)
66             curx += interval
67             
68 class Rdiag(T):
69     """Fills the region with diagonal lines, but tilted in the opposite
70 direction from fill_style.Diag."""
71     def draw(self, can, x1, y1, x2, y2):    
72         line_width = self.line_style.width
73         interval = self.line_interval * 1.414
74         x1 -= line_width
75         y1 -= line_width
76         x2 += line_width
77         y2 += line_width
78         len = max(y2 - y1, x2 - x1)
79         curx = x1
80         while curx < x2 + len:
81             can.line(self.line_style, curx, y1, curx-len, y1+len)
82             curx += interval
83             
84 class Vert(T):
85     "Fills the region with vertical lines"
86     def draw(self, can, x1, y1, x2, y2):    
87         interval = self.line_interval
88         curx = x1
89         while curx < x2:
90             can.line(self.line_style, curx, y1, curx, y2)
91             curx += interval
92             
93 class Horiz(T):
94     "Fills the region with horizontal lines"
95     def draw(self, can, x1, y1, x2, y2):
96         interval = self.line_interval
97         cury = y1
98         while cury < y2:
99             can.line(self.line_style, x1, cury, x2, cury)            
100             cury += interval
101             
102 class Stitch(T):
103     "Fills the region with horizontal and vertical lines."
104     def draw(self, can, x1, y1, x2, y2):
105         interval = self.line_interval
106         cury = y1
107         while cury < y2:
108             can.line(self.line_style, x1, cury, x2, cury)
109             cury += interval
110         curx = x1
111         while curx < x2:
112             can.line(self.line_style, curx, y1, curx, y2)
113             curx += interval
114
115 class Wave(T):
116     "Fills the region with horizontal wavy lines."
117     def draw(self, can, x1, y1, x2, y2):
118         x1 = xscale(x1)
119         x2 = xscale(x2)
120         y1 = yscale(y1)
121         y2 = yscale(y2)
122         line_width = nscale(self.line_style.width)
123         interval = nscale(self.line_interval)
124         
125         can.set_line_style(self.line_style)        
126         x1 -= line_width
127         x2 += line_width
128         cury = y1
129         half = interval/2.0
130         while cury < y2:
131             curx = x1
132             can.newpath()
133             can.moveto(curx, cury)
134             while curx < x2:
135                 can.lineto(curx + half, cury + half)
136                 can.lineto(curx + interval, cury)
137                 curx += interval
138             can.stroke()
139             cury += interval
140
141 class Vwave(T):
142     """Fills the region with vertical wavy lines."""
143     def draw(self, can, x1, y1, x2, y2):
144         x1 = xscale(x1)
145         x2 = xscale(x2)
146         y1 = yscale(y1)
147         y2 = yscale(y2)
148         line_width = nscale(self.line_style.width)
149         interval = nscale(self.line_interval)
150         
151         can.set_line_style(self.line_style)
152         y1 -= line_width
153         y2 += line_width
154         curx = x1
155         half = interval/2.0
156         while curx < x2:
157             cury = y1
158             can.newpath()
159             can.moveto(curx, cury)
160             while cury < y2:
161                 can.lineto(curx + half, cury + half)
162                 can.lineto(curx, cury + interval)
163                 cury += interval
164             can.stroke()
165             curx += interval        
166
167 class Lines(T):
168     """Fills the region with a series of short line segments."""
169     def draw(self, can, x1, y1, x2, y2):
170         interval = nscale(self.line_interval)
171         cury = y1
172         j = 0
173         while cury < y2:
174             curx = x1
175             if j % 2 == 1:
176                 curx += interval/2.0
177             while curx < x2:
178                 can.line(self.line_style, curx, cury, curx+interval/2.0, cury)
179                 curx += interval * 1.5
180             j += 1
181             cury += interval
182
183 default = Plain()
184
185 color_standards = object_set.T()
186 grayscale_standards = object_set.T()
187
188 def _intern_both(style):
189     global color_standards, grayscale_standards
190     color_standards.add(style)
191     grayscale_standards.add(style)
192     return style
193
194 def _intern_color(style):
195     global color_standards, grayscale_standards    
196     color_standards.add(style)
197     return style
198
199 def _intern_grayscale(style):
200     global color_standards, grayscale_standards    
201     grayscale_standards.add(style)
202     return style
203
204 black = _intern_both(Plain(bgcolor=color.gray_scale(0.0), line_style=None))
205
206 red = _intern_color(Plain(bgcolor=color.red))
207 darkseagreen = _intern_color(Plain(bgcolor=color.darkseagreen))
208 blue = _intern_color(Plain(bgcolor=color.blue))
209 aquamarine1 = _intern_color(Plain(bgcolor=color.aquamarine1))
210 gray70 = _intern_both(Plain(bgcolor=color.gray70, line_style=None))
211 brown = _intern_color(Plain(bgcolor=color.brown))
212 darkorchid = _intern_color(Plain(bgcolor=color.darkorchid))    
213 diag = _intern_both(Diag(line_style=line_style.T(cap_style=2)))
214 green = _intern_color(Plain(bgcolor=color.green))
215 gray50 = _intern_both(Plain(bgcolor=color.gray50, line_style=None))
216 white = _intern_both(Plain(bgcolor=color.gray_scale(1.0), line_style=None))
217 goldenrod = _intern_color(Plain(bgcolor=color.goldenrod))
218 rdiag = _intern_both(Rdiag(line_style=line_style.T(cap_style=2)))
219 vert = _intern_both(Vert(line_interval=1.8))
220
221 gray30 = _intern_both(Plain(bgcolor=color.gray30, line_style=None))
222 gray20 = _intern_both(Plain(bgcolor=color.gray20, line_style=None))
223 gray10 = _intern_both(Plain(bgcolor=color.gray10, line_style=None))
224 diag2 = _intern_both(Diag(line_style=line_style.T(width=3, cap_style=2),
225                       line_interval=6))
226 rdiag2 = _intern_both(Rdiag(line_style=line_style.T(width=3, cap_style=2),
227                         line_interval=6))
228 yellow = _intern_color(Plain(bgcolor=color.yellow))
229 diag3 = _intern_both(Diag(line_style=line_style.T(width=3, color=color.gray50, cap_style=2),
230                       line_interval=6))
231 horiz = _intern_both(Horiz(line_interval=1.8))
232 gray90 = _intern_both(Plain(bgcolor=color.gray90, line_style=None))
233 rdiag3 = _intern_both(Rdiag(line_style=line_style.T(width=3,
234                                                           color=color.gray50,
235                                                           cap_style=2),
236                         line_interval=6))
237
238 wave = _intern_both(Wave(line_style=line_style.T(cap_style=2, join_style=1)))
239 vwave = _intern_both(Vwave(line_style=line_style.T(cap_style=2, join_style=1)))
240 stitch = _intern_both(Stitch(line_style=line_style.T(cap_style=2, join_style=1)))
241 lines = _intern_both(Lines(line_style=line_style.T()))
242
243 diag_fine = _intern_both(Diag(line_style=line_style.T(width=0.75,cap_style=2),
244                               line_interval = 1.5))
245 diag2_fine = _intern_both(Diag(line_style=line_style.T(width=0.75, cap_style=2),
246                                line_interval=1.5))
247 diag3_fine = _intern_both(Diag(line_style=line_style.T(width=0.75,
248                                                        color = color.gray50,
249                                                        cap_style=2),
250                                line_interval=1.5))
251 rdiag_fine = _intern_both(Rdiag(line_style=line_style.T(width=0.75,cap_style=2),
252                               line_interval = 1.5))
253 rdiag2_fine = _intern_both(Rdiag(line_style=line_style.T(width=0.75, cap_style=2),
254                                line_interval=1.5))
255 rdiag3_fine = _intern_both(Rdiag(line_style=line_style.T(width=0.75,
256                                                        color = color.gray50,
257                                                        cap_style=2),
258                                line_interval=1.5))
259
260 horiz_fine = _intern_both(Horiz(line_interval=1.5))
261 vert_fine = _intern_both(Vert(line_interval=1.5))
262
263 #
264 # Fill styles for color charts.
265 #
266
267 standards = None
268 _name_table = None
269
270 def init():
271     global standards, _name_table
272     if theme.use_color:
273         standards = color_standards
274     else:
275         standards = grayscale_standards
276     _name_table = None
277
278 def name_table():
279     global _name_table
280     if not _name_table:
281         _name_table = pychart_util.symbol_lookup_table(globals(), standards)
282     return _name_table
283
284 init()
285 theme.add_reinitialization_hook(init)
286