[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 color
16 import line_style
17 import fill_style
18 import chart_object
19 import object_set
20 import pychart_util
21 import tick_mark_doc
22 from pychart_types import *
23
24 _keys = {
25     "line_style": (line_style.T, line_style.default, "The line style of the tick mark."),
26     "fill_style": (fill_style.T, fill_style.white, "The fill style."),
27     "size": (UnitType, 5, "Size of the tick mark."),
28     }
29
30 class T(chart_object.T):
31     __doc__ = tick_mark_doc.doc
32     keys = _keys
33 ##AUTOMATICALLY GENERATED
34
35 ##END AUTOMATICALLY GENERATED
36     
37     def predraw_check(self):
38         if not hasattr(self, "type_checked"):
39             self.type_check()
40         self.type_checked = 1
41
42 class Circle(T):
43     """Draws a circle. """
44     def draw(self, can, x, y):
45         self.predraw_check()
46         can.ellipsis(self.line_style, self.fill_style, x, y,
47                         self.size/2.0, 1)
48         
49 class Square(T):
50     """Draws a square."""
51     def draw(self, can, x, y):
52         self.predraw_check()
53         # move to the bottom-left corner
54         x = x - self.size/2.0
55         y = y - self.size/2.0
56         can.rectangle(self.line_style, self.fill_style,
57                          x, y, x+self.size, y+self.size)
58
59 class Triangle(T):
60     """Draws a triangle pointing up."""
61     def draw(self, can, x, y):
62         self.predraw_check()
63         can.polygon(self.line_style, self.fill_style,
64                        ((x-self.size/1.6, y-self.size/2.0),
65                         (x+self.size/1.6, y-self.size/2.0),
66                         (x, y+self.size/2.0)))
67 class DownTriangle(T):
68     """Draws a triangle pointing down."""
69     def draw(self, can, x, y):
70         self.predraw_check()
71         can.polygon(self.line_style, self.fill_style,
72                        ((x, y-self.size/2.0),
73                         (x-self.size/1.6, y+self.size/2.0),
74                         (x+self.size/1.6, y+self.size/2.0)))
75
76
77 class X(T):
78     """Draw a "X"-shaped tick mark. Attribute "fill-style" is ignored."""
79     keys = pychart_util.union_dict(T.keys,
80                          {"line_style": (line_style.T,
81                                          line_style.T(width=0.7),
82                                          "The line style of the tick mark")})
83     def draw(self, can, x, y):
84         self.predraw_check()
85         # move to the bottom-left corner
86         x = x - self.size/2.0
87         y = y - self.size/2.0
88         can.line(self.line_style, x, y, x+self.size, y+self.size)
89         can.line(self.line_style, x+self.size, y, x, y+self.size)
90         
91 class Plus(T):
92     """Draw a "+"-shaped tick mark. Attribute "fill-style" is ignored."""
93     keys = pychart_util.union_dict(T.keys,
94                          {"line_style": (line_style.T, 
95                                         line_style.T(width=1),
96                                          "The line style of the tick mark.")})
97     def draw(self, can, x, y):
98         self.predraw_check()
99         # move to the bottom-left corner
100         can.line(self.line_style, x-self.size/1.4, y, x+self.size/1.4, y)
101         can.line(self.line_style, x, y-self.size/1.4, x, y+self.size/1.4)
102         
103 class Diamond(T):
104     """Draw a square rotated at 45 degrees."""
105     def draw(self, can, x, y):
106         self.predraw_check()
107         # move to the bottom-left corner
108         can.polygon(self.line_style, self.fill_style,
109                    ((x-self.size/1.4, y), (x, y+self.size/1.4),
110                     (x+self.size/1.4, y), (x, y-self.size/1.4)))
111
112 class Star(T):
113     """Draw a "*". Attribute "fill-style" is ignored."""
114     keys = pychart_util.union_dict(T.keys,
115                          {"line_style": (line_style.T,
116                                         line_style.T(width=1),
117                                          "The line style of the tick mark.")})
118     def draw(self, can, x, y):
119         self.predraw_check()
120         # move to the bottom-left corner
121         midx = x
122         midy = y
123         d_len = self.size / 2.0
124         r_len = self.size * 1.414 / 2.0
125         can.line(self.line_style, x-d_len, y-d_len, x+d_len, y+d_len)
126         can.line(self.line_style, x+d_len, y-d_len, x-d_len, y+d_len) 
127         can.line(self.line_style, midx, y-r_len, midx, y+r_len)
128         can.line(self.line_style, x-r_len, midy, x+r_len, midy)
129         
130 class Null(T):
131     """This tickmark doesn't draw anything. All the attributes are ignored."""
132     def __init__ (self):
133         self.line_style = None
134         self.fill_style = None
135         self.size = -1
136     def draw(self, can, x, y):
137         pass
138     
139 standards = object_set.T()
140 def _intern(style):
141     standards.add(style)
142     return style
143      
144 square = _intern(Square())
145 square3 = _intern(Square(size=3))
146 square5 = square
147 x = _intern(X())
148 x3 = _intern(X(size=3))
149 x5 = x
150 star = _intern(Star())
151 star3 = _intern(Star(size=3))
152 star5 = star
153 plus = _intern(Plus())
154 plus3 = _intern(Plus(size=3))
155 plus5 = plus
156 dia = _intern(Diamond())
157 dia3 = _intern(Diamond(size=3))
158 dia5 = dia
159 tri = _intern(Triangle())
160 tri3 = _intern(Triangle(size=3))
161 tri5 = tri
162 dtri = _intern(DownTriangle())
163 dtri3 = _intern(DownTriangle(size=3))
164 dtri5 = dtri
165 circle1 = _intern(Circle(size=1))
166 circle2 = _intern(Circle(size=3))
167 circle3 = _intern(Circle(size=5))
168 blacksquare = _intern(Square(fill_style=fill_style.black))
169 blacksquare3 = _intern(Square(size=3, fill_style=fill_style.black))
170 blackdia = _intern(Diamond(fill_style=fill_style.black))
171 blackdia3 = _intern(Diamond(size=3, fill_style=fill_style.black))
172 blacktri = _intern(Triangle(fill_style=fill_style.black))
173 blacktri3 = _intern(Triangle(size=3, fill_style=fill_style.black))
174 blackdtri = _intern(DownTriangle(fill_style=fill_style.black))
175 blackdtri3 = _intern(DownTriangle(size=3, fill_style=fill_style.black))
176 blackcircle1 = _intern(Circle(size=1, fill_style=fill_style.black))
177 blackcircle3 = _intern(Circle(size=3, fill_style=fill_style.black))
178 gray70square = _intern(Square(fill_style=fill_style.gray70))
179 gray70square3 = _intern(Square(size=3, fill_style=fill_style.gray70))
180 gray70dia = _intern(Diamond(fill_style=fill_style.gray70))
181 gray70dia3 = _intern(Diamond(size=3, fill_style=fill_style.gray70))
182 gray70tri = _intern(Triangle(fill_style=fill_style.gray70))
183 gray70tri3 = _intern(Triangle(size=3, fill_style=fill_style.gray70))
184 gray70dtri = _intern(DownTriangle(fill_style=fill_style.gray70))
185 gray70dtri3 = _intern(DownTriangle(size=3, fill_style=fill_style.gray70))
186 gray70circle1 = _intern(Circle(size=1, fill_style=fill_style.gray70))
187 gray70circle3 = _intern(Circle(size=3, fill_style=fill_style.gray70))
188 default = _intern(Null())
189