5 |
# This program is free software under the GPL (>=v2) |
# This program is free software under the GPL (>=v2) |
6 |
# Read the file COPYING coming with Thuban for details. |
# Read the file COPYING coming with Thuban for details. |
7 |
|
|
8 |
|
""" |
9 |
|
ClassGenerator |
10 |
|
""" |
11 |
|
|
12 |
|
__version__ = "$Revision$" |
13 |
|
# $Source$ |
14 |
|
# $Id$ |
15 |
|
|
16 |
import operator |
import operator |
17 |
|
|
18 |
from color import Color |
from color import Color |
36 |
generated because the stepping values must |
generated because the stepping values must |
37 |
be precalculated to ramp between prop1 and prop2. |
be precalculated to ramp between prop1 and prop2. |
38 |
|
|
39 |
prop1 -- initial group property values |
ramp -- an object which implements the CustomRamp interface |
|
|
|
|
prop2 -- final group property values |
|
40 |
""" |
""" |
41 |
|
|
42 |
clazz = Classification() |
clazz = Classification() |
68 |
|
|
69 |
return clazz |
return clazz |
70 |
|
|
71 |
def GenUnifromDistribution(self, min, max, numGroups, |
def GenUniformDistribution(self, min, max, numGroups, |
72 |
ramp, intStep = False): |
ramp, intStep = False): |
73 |
"""Generate a classification with numGroups range groups |
"""Generate a classification with numGroups range groups |
74 |
each with the same interval. |
each with the same interval. |
103 |
|
|
104 |
# this check guards against rounding issues |
# this check guards against rounding issues |
105 |
if cur_min != cur_max: |
if cur_min != cur_max: |
106 |
range = Range("[" + str(float(cur_min)) + ";" + |
range = Range(("[", cur_min, cur_max, end)) |
|
str(float(cur_max)) + end) |
|
107 |
clazz.AppendGroup(ClassGroupRange(range, None, prop)) |
clazz.AppendGroup(ClassGroupRange(range, None, prop)) |
108 |
|
|
109 |
cur_min = cur_max |
cur_min = cur_max |
146 |
|
|
147 |
ramp.SetNumGroups(numGroups) |
ramp.SetNumGroups(numGroups) |
148 |
|
|
149 |
min = _list[quantiles[1]] |
start, min, endMax, right = _range.GetRange() |
150 |
start = "[" |
|
151 |
oldp = 0 |
oldp = 0 |
152 |
|
i = 1 |
153 |
|
end = "]" |
154 |
|
|
155 |
for (q, p), prop in zip(quantiles[3], ramp): |
for (q, p), prop in zip(quantiles[3], ramp): |
156 |
max = _list[q] |
if i == numGroups: |
157 |
group = ClassGroupRange(Range(start + str(min) + ";" + |
max = endMax |
158 |
str(max) + "]"), |
end = right |
159 |
|
else: |
160 |
|
max = _list[q] |
161 |
|
|
162 |
|
group = ClassGroupRange(Range((start, min, max, end)), |
163 |
None, prop) |
None, prop) |
164 |
|
|
165 |
group.SetLabel("%s%% - %s%%" % (round(oldp*100, 2), |
group.SetLabel("%s%% - %s%%" % (round(oldp*100, 2), |
168 |
start = "]" |
start = "]" |
169 |
min = max |
min = max |
170 |
clazz.AppendGroup(group) |
clazz.AppendGroup(group) |
171 |
|
i += 1 |
172 |
|
|
173 |
return (adjusted, clazz) |
return (adjusted, clazz) |
174 |
|
|