[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 tick_mark
16 import line_style
17 import pychart_util
18 import chart_object
19 import fill_style
20 import types
21 import error_bar_doc
22 import object_set
23 from pychart_types import *
24
25 __doc__ = """Pychart offers several styles of error bars. Some of them
26 only displays the min/max confidence interval, while others can display
27 quartiles in addition to min/max.""" 
28
29 class T(chart_object.T):
30     keys = {}
31 ##AUTOMATICALLY GENERATED
32
33 ##END AUTOMATICALLY GENERATED
34     pass
35
36 # Two horizontal lines at min & max locations.
37 class error_bar1(T):
38     __doc__ = error_bar_doc.doc_1
39     keys = {"tic_len" : (UnitType, 10, "Length of the horizontal bars"),
40             "line_style": (line_style.T, line_style.default, "")
41             }
42 ##AUTOMATICALLY GENERATED
43
44 ##END AUTOMATICALLY GENERATED
45     def draw(self, can, loc, min, max, qmin = None, qmax = None):
46         x = loc[0]
47         y = min
48         can.line(self.line_style, x-self.tic_len/2.0, y, x+self.tic_len/2.0, y)
49         y = max
50         can.line(self.line_style, x-self.tic_len/2.0, y, x+self.tic_len/2.0, y)
51
52 class error_bar2(T):
53     __doc__ = error_bar_doc.doc_2
54     keys = {"tic_len" : (UnitType, 3,
55                         "The length of the horizontal bars"),
56             "hline_style": (line_style.T, line_style.default,
57                            "The style of the horizontal bars."),
58             "vline_style": (line_style.T, None,
59                            "The style of the vertical bar.")
60              }
61
62 ##AUTOMATICALLY GENERATED
63
64 ##END AUTOMATICALLY GENERATED
65     def draw(self, can, loc, min, max, qmin = None, qmax = None):
66         vline_style = self.vline_style
67         if not vline_style:
68             vline_style = self.hline_style
69         x = loc[0]
70         y1 = min
71         can.line(self.hline_style, x-self.tic_len/2.0, y1, x+self.tic_len/2.0, y1)
72         y2 = max
73         can.line(self.hline_style, x-self.tic_len/2.0, y2, x+self.tic_len/2.0, y2)
74         can.line(vline_style, x, y1, x, y2)
75
76 class error_bar3(T):
77     # Tufte style
78     __doc__ = "This style is endorsed by the Tufte's books. " \
79               + error_bar_doc.doc_3
80     keys = { "line_style": (line_style.T, line_style.default, "")
81              }
82
83 ##AUTOMATICALLY GENERATED
84
85 ##END AUTOMATICALLY GENERATED
86     def draw(self, can, loc, min, max, qmin, qmax):
87         x = loc[0]
88         can.line(self.line_style, x, min, x, qmin)
89         can.line(self.line_style, x, qmax, x, max)
90
91 class error_bar4(T):
92     __doc__ = error_bar_doc.doc_4
93     keys = { "line_style": (line_style.T, line_style.default, ""),
94              "fill_style": (fill_style.T, fill_style.gray70, ""),
95              "box_width": (UnitType, 4, ""),
96              "tic_len": (UnitType, 4, "")
97              }
98 ##AUTOMATICALLY GENERATED
99
100 ##END AUTOMATICALLY GENERATED
101     def draw(self, can, loc, min, max, qmin, qmax):
102         x = loc[0]
103         style = self.line_style
104         y1 = min
105         can.line(style, x-self.tic_len/2.0, y1, x+self.tic_len/2.0, y1)
106         y2 = max
107         can.line(style, x-self.tic_len/2.0, y2, x+self.tic_len/2.0, y2)
108         can.line(style, x, y1, x, y2)
109
110         can.rectangle(style, self.fill_style,
111                       x-self.box_width/2.0, qmin,
112                       x+self.box_width/2.0, qmax)
113
114 # vertical line
115 class error_bar5(T):
116     __doc__ = error_bar_doc.doc_5
117     keys = { "line_style": (line_style.T, line_style.default, "")
118              }
119 ##AUTOMATICALLY GENERATED
120
121 ##END AUTOMATICALLY GENERATED
122     def draw(self, can, loc, min, max, qmin = None, qmax = None):
123         x = loc[0]
124         y = loc[1]
125
126         min = (min - y) *1 + y
127         max = (max - y) *1+ y
128         can.line(self.line_style, x, min, x, max)
129
130 # a box
131 class error_bar6(T):
132     __doc__ = error_bar_doc.doc_6
133     keys = { "line_style": (line_style.T, line_style.default, ""),
134              "fill_style": (fill_style.T, fill_style.gray70, ""),
135              "center_line_style": (line_style.T, line_style.T(width=0.5), ""),
136              "box_width": (UnitType, 4, ""),
137              }
138 ##AUTOMATICALLY GENERATED
139
140 ##END AUTOMATICALLY GENERATED
141     def draw(self, can, loc, min, max, qmin = None, qmax = None):
142         x = loc[0]
143         y = loc[1]
144
145         can.rectangle(self.line_style, self.fill_style,
146                       x - self.box_width / 2.0, min,
147                       x + self.box_width / 2.0, max)
148         can.line(self.center_line_style,
149                  x - self.box_width/2.0, (min+max)/2.0,
150                  x + self.box_width/2.0, (min+max)/2.0)
151
152 bar1 = error_bar1()
153 bar2 = error_bar2()
154 bar3 = error_bar3()
155 bar4 = error_bar4()
156 bar5 = error_bar5()
157 bar6 = error_bar6()
158
159 standards = object_set.T(bar1, bar2, bar3, bar4, bar5, bar6)
160