2 #@+node:@file charting/shapes.py
4 # gantt widgets can have the different shapes in this modules.
7 # the first item of the returned shape list, has to be a patch, that defines,
8 # the connection points
15 #@+node:<< Copyright >>
16 ############################################################################
17 # Copyright (C) 2005, 2006, 2007, 2008 by Reithinger GmbH
20 # This file is part of faces.
22 # faces is free software; you can redistribute it and/or modify
23 # it under the terms of the GNU General Public License as published by
24 # the Free Software Foundation; either version 2 of the License, or
25 # (at your option) any later version.
27 # faces is distributed in the hope that it will be useful,
28 # but WITHOUT ANY WARRANTY; without even the implied warranty of
29 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30 # GNU General Public License for more details.
32 # You should have received a copy of the GNU General Public License
33 # along with this program; if not, write to the
34 # Free Software Foundation, Inc.,
35 # 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
36 ############################################################################
38 #@-node:<< Copyright >>
50 __all__
= ("bar", "brace", "combibar", "diamond", "circle", "wedge", "house")
55 def bar(props
, name
, complete
=0):
56 kwargs
= make_properties(props
, name
)
57 bar
= Polygon(((LEFT
, BOTTOM
),
64 (HCENTER
, BOTTOM
)), **kwargs
)
66 kwargs
= make_properties(props
, "%s.complete" % name
)
68 complete
= Rectangle((LEFT
, BOTTOM
+ VSEP
* FACTOR
/ 4),
69 (RIGHT
- LEFT
) * complete
,
72 return (bar
, complete
)
77 def brace(props
, name
):
78 kwargs
= make_properties(props
, name
)
80 return (Polygon([(LEFT
, TOP
),
83 (RIGHT
- HALF
* HSEP
, BOTTOM
+ HALF
* VSEP
),
84 (LEFT
+ HALF
* HSEP
, BOTTOM
+ HALF
* VSEP
),
85 (LEFT
, BOTTOM
)], **kwargs
),)
88 def combibar(props
, name
, left
, right
, complete
):
89 left
= left(props
, name
+ ".start", VCENTER
, LEFT
)
90 right
= right(props
, name
+ ".end", VCENTER
, RIGHT
)
92 half_height
= props(name
+ ".bar.height") * VSEP
/ 2
93 top
= VCENTER
+ half_height
94 bottom
= VCENTER
- half_height
97 x
, y
= float(vert
[0]), float(vert
[1])
98 return x
< LEFT
.get() or y
> top
.get() or y
< bottom
.get()
100 def right_vert(vert
):
101 x
, y
= float(vert
[0]), float(vert
[1])
102 return x
> RIGHT
.get() or y
> top
.get() or y
< bottom
.get()
104 outline_verts
= filter(left_vert
, left
[0].get_verts())\
105 + [(HCENTER
, top
), (HCENTER
, bottom
)] \
106 + filter(right_vert
, right
[0].get_verts())
108 outline
= Polygon(outline_verts
)
109 outline
.set_visible(False)
111 kwargs
= make_properties(props
, name
+ ".bar")
112 bar
= Polygon([(LEFT
, top
), (RIGHT
, top
),
113 (RIGHT
, bottom
), (LEFT
, bottom
)], **kwargs
)
115 #only take the visible part of the symbols
116 sleft
= left
[int(len(left
) > 1)]
117 sright
= right
[int(len(right
) > 1)]
120 kwargs
= make_properties(props
, name
+ ".complete")
121 half_height
= props(name
+ ".complete.height") * VSEP
/ 2
122 top
= VCENTER
+ half_height
123 bottom
= VCENTER
- half_height
124 right
= LEFT
+ (RIGHT
- LEFT
) * complete
/ 100
125 complete
= Polygon([(LEFT
, top
), (right
, top
),
126 (right
, bottom
), (LEFT
, bottom
)], **kwargs
)
128 return (outline
, bar
, complete
, sleft
, sright
)
130 return (outline
, bar
, sleft
, sright
)
133 def diamond(props
, name
="", vc
=None, hc
=None):
135 A diamond symbol, that can be be used as an argument,
136 for a widgets set_shape method or for a combined shape
141 if name
: name
= ".%s" % name
144 kwargs
= make_properties(props
, "diamond" + name
)
145 mag
= props("diamond" + name
+ ".magnification")
146 HALF
= mag
* FACTOR
/ 2
147 return (Polygon([(hc
- HALF
* HSEP
, vc
),
148 (hc
, vc
- HALF
* VSEP
),
149 (hc
+ HALF
* HSEP
, vc
),
150 (hc
, vc
+ HALF
* VSEP
)], **kwargs
),)
153 def circle(props
, name
="", vc
=None, hc
=None):
154 if name
: name
= ".%s" % name
157 kwargs
= make_properties(props
, "circle" + name
)
158 mag
= props("circle" + name
+ ".magnification")
160 HALF
= mag
* FACTOR
/ 2
162 shape
= (Polygon([(hc
- HALF
* HSEP
, vc
),
163 (hc
, vc
- HALF
* VSEP
),
164 (hc
+ HALF
* HSEP
, vc
),
165 (hc
, vc
+ HALF
* VSEP
)]),
166 Circle((hc
, vc
), HALF
*VSEP
, **kwargs
))
167 shape
[0].set_visible(False)
171 def wedge(props
, name
="", vc
=None, hc
=None):
172 if name
: name
= ".%s" % name
175 kwargs
= make_properties(props
, "wedge" + name
)
176 mag
= props("wedge" + name
+ ".magnification")
178 HALF
= mag
* FACTOR
/ 2
180 if props("wedge" + name
+ ".up", True):
181 base
= VCENTER
- HALF
* VSEP
182 head
= VCENTER
+ HALF
* VSEP
184 base
= VCENTER
+ HALF
* VSEP
185 head
= VCENTER
- HALF
* VSEP
187 return (Polygon([(hc
- HALF
* HSEP
, base
),
189 (hc
+ HALF
* HSEP
, base
),
190 (hc
+ HALF
* HSEP
/ 2, vc
),
192 (hc
- HALF
* HSEP
/ 2, vc
)], **kwargs
),)
195 def house(props
, name
="", vc
=None, hc
=None):
196 if name
: name
= ".%s" % name
199 kwargs
= make_properties(props
, "house" + name
)
200 mag
= props("house" + name
+ ".magnification")
202 HALF
= mag
* FACTOR
/ 2
204 if props("house" + name
+ ".up", True):
205 base
= VCENTER
- HALF
* VSEP
206 head
= VCENTER
+ HALF
* VSEP
208 base
= VCENTER
+ HALF
* VSEP
209 head
= VCENTER
- HALF
* VSEP
211 return (Polygon([(hc
- HALF
* HSEP
, base
),
213 (hc
+ HALF
* HSEP
, base
),
214 (hc
+ HALF
* HSEP
, vc
),
216 (hc
- HALF
* HSEP
, vc
)], **kwargs
),)
220 symbols
= ("diamond", "circle", "wedge", "house")
222 #@-node:@file charting/shapes.py