1 # A CSplit is a Clock-shaped split: the children are grouped in a circle.
2 # The numbering is a little different from a real clock: the 12 o'clock
3 # position is called 0, not 12. This is a little easier since Python
4 # usually counts from zero. (BTW, there needn't be exactly 12 children.)
7 from math
import pi
, sin
, cos
8 from Split
import Split
12 def getminsize(self
, m
, (width
, height
)):
13 # Since things look best if the children are spaced evenly
14 # along the circle (and often all children have the same
15 # size anyway) we compute the max child size and assume
16 # this is each child's size.
17 for child
in self
.children
:
18 wi
, he
= child
.getminsize(m
, (0, 0))
19 width
= max(width
, wi
)
20 height
= max(height
, he
)
21 # In approximation, the diameter of the circle we need is
22 # (diameter of box) * (#children) / pi.
23 # We approximate pi by 3 (so we slightly overestimate
24 # our minimal size requirements -- not so bad).
25 # Because the boxes stick out of the circle we add the
26 # box size to each dimension.
27 # Because we really deal with ellipses, do everything
28 # separate in each dimension.
29 n
= len(self
.children
)
30 return width
+ (width
*n
+ 2)/3, height
+ (height
*n
+ 2)/3
35 def setbounds(self
, bounds
):
37 # Place the children. This involves some math.
38 # Compute center positions for children as if they were
39 # ellipses with a diameter about 1/N times the
40 # circumference of the big ellipse.
41 # (There is some rounding involved to make it look
42 # reasonable for small and large N alike.)
43 # XXX One day Python will have automatic conversions...
44 n
= len(self
.children
)
47 (left
, top
), (right
, bottom
) = bounds
48 width
, height
= right
-left
, bottom
-top
49 child_width
, child_height
= width
*3/(n
+4), height
*3/(n
+4)
50 half_width
, half_height
= \
51 float(width
-child_width
)/2.0, \
52 float(height
-child_height
)/2.0
53 center_h
, center_v
= center
= (left
+right
)/2, (top
+bottom
)/2
54 fch
, fcv
= float(center_h
), float(center_v
)
57 child
= self
.children
[i
]
60 fch
+ half_width
*sin(fi
*alpha
), \
61 fcv
- half_height
*cos(fi
*alpha
)
63 int(fh
) - child_width
/2, \
64 int(fv
) - child_height
/2
68 child
.setbounds(((left
, top
), (right
, bottom
)))