20 |
from classification import Classification, ClassGroupSingleton, \ |
from classification import Classification, ClassGroupSingleton, \ |
21 |
ClassGroupRange, ClassGroupProperties |
ClassGroupRange, ClassGroupProperties |
22 |
|
|
23 |
def generate_singletons(_list, ramp): |
def generate_singletons(_list, ramp, fixes=(None, None, None)): |
24 |
"""Generate a new classification consisting solely of singletons. |
"""Generate a new classification consisting solely of singletons. |
25 |
|
|
26 |
The resulting classification will consist of one group for each |
The resulting classification will consist of one group for each |
29 |
_list -- a list of values for each singleton |
_list -- a list of values for each singleton |
30 |
|
|
31 |
ramp -- an object which implements the CustomRamp interface |
ramp -- an object which implements the CustomRamp interface |
32 |
|
|
33 |
|
fixes -- a tuple (lineColor, lineWidth, fillColor) such that |
34 |
|
if any item is not None, the appropriate property will |
35 |
|
be fixed to that item value. |
36 |
""" |
""" |
37 |
|
|
38 |
clazz = Classification() |
clazz = Classification() |
43 |
|
|
44 |
for value in _list: |
for value in _list: |
45 |
prop = ramp.GetProperties(i / maxValue) |
prop = ramp.GetProperties(i / maxValue) |
46 |
|
if fixes[0] is not None: prop.SetLineColor(fixes[0]) |
47 |
|
if fixes[1] is not None: prop.SetLineWidth(fixes[1]) |
48 |
|
if fixes[2] is not None: prop.SetFill(fixes[2]) |
49 |
clazz.AppendGroup(ClassGroupSingleton(value, prop)) |
clazz.AppendGroup(ClassGroupSingleton(value, prop)) |
50 |
i += 1 |
i += 1 |
51 |
|
|
52 |
return clazz |
return clazz |
53 |
|
|
54 |
def generate_uniform_distribution(min, max, numGroups, ramp, intStep = False): |
def generate_uniform_distribution(min, max, numGroups, ramp, intStep = False, |
55 |
|
fixes = (None, None, None)): |
56 |
"""Generate a classification with numGroups range groups |
"""Generate a classification with numGroups range groups |
57 |
each with the same interval. |
each with the same interval. |
58 |
|
|
60 |
Useful if the values are integers but the |
Useful if the values are integers but the |
61 |
number of groups specified doesn't evenly |
number of groups specified doesn't evenly |
62 |
divide (max - min). |
divide (max - min). |
63 |
|
|
64 |
|
fixes -- a tuple (lineColor, lineWidth, fillColor) such that |
65 |
|
if any item is not None, the appropriate property will |
66 |
|
be fixed to that item value. |
67 |
""" |
""" |
68 |
|
|
69 |
clazz = Classification() |
clazz = Classification() |
92 |
else: |
else: |
93 |
_range = Range(("[", cur_min, cur_max, end)) |
_range = Range(("[", cur_min, cur_max, end)) |
94 |
|
|
95 |
|
if fixes[0] is not None: prop.SetLineColor(fixes[0]) |
96 |
|
if fixes[1] is not None: prop.SetLineWidth(fixes[1]) |
97 |
|
if fixes[2] is not None: prop.SetFill(fixes[2]) |
98 |
|
|
99 |
clazz.AppendGroup(ClassGroupRange(_range, prop)) |
clazz.AppendGroup(ClassGroupRange(_range, prop)) |
100 |
|
|
101 |
cur_min = cur_max |
cur_min = cur_max |
102 |
|
|
103 |
return clazz |
return clazz |
104 |
|
|
105 |
def generate_quantiles(_list, percents, ramp, _range): |
def generate_quantiles(_list, percents, ramp, _range, fixes=(None, None, None)): |
106 |
"""Generates a Classification which has groups of ranges that |
"""Generates a Classification which has groups of ranges that |
107 |
represent quantiles of _list at the percentages given in percents. |
represent quantiles of _list at the percentages given in percents. |
108 |
Only the values that fall within _range are considered. |
Only the values that fall within _range are considered. |
122 |
|
|
123 |
_range -- a Range object |
_range -- a Range object |
124 |
|
|
125 |
|
fixes -- a tuple (lineColor, lineWidth, fillColor) such that |
126 |
|
if any item is not None, the appropriate property will |
127 |
|
be fixed to that item value. |
128 |
|
|
129 |
Raises a Value Error if 'percents' has fewer than two items, or |
Raises a Value Error if 'percents' has fewer than two items, or |
130 |
does not cover the entire range. |
does not cover the entire range. |
131 |
""" |
""" |
160 |
else: |
else: |
161 |
max = _list[q] |
max = _list[q] |
162 |
|
|
163 |
|
if fixes[0] is not None: prop.SetLineColor(fixes[0]) |
164 |
|
if fixes[1] is not None: prop.SetLineWidth(fixes[1]) |
165 |
|
if fixes[2] is not None: prop.SetFill(fixes[2]) |
166 |
|
|
167 |
group = ClassGroupRange(Range((start, min, max, end)), prop) |
group = ClassGroupRange(Range((start, min, max, end)), prop) |
168 |
|
|
169 |
group.SetLabel("%s%% - %s%%" % (round(oldp*100, 2), |
group.SetLabel("%s%% - %s%%" % (round(oldp*100, 2), |
420 |
|
|
421 |
newProps = ClassGroupProperties() |
newProps = ClassGroupProperties() |
422 |
|
|
|
color1 = self.prop1.GetLineColor() |
|
|
color2 = self.prop2.GetLineColor() |
|
|
|
|
423 |
self.__SetProperty(self.prop1.GetLineColor(), |
self.__SetProperty(self.prop1.GetLineColor(), |
424 |
self.prop2.GetLineColor(), |
self.prop2.GetLineColor(), |
425 |
index, newProps.SetLineColor) |
index, newProps.SetLineColor) |
429 |
w = (self.prop2.GetLineWidth() - self.prop1.GetLineWidth()) \ |
w = (self.prop2.GetLineWidth() - self.prop1.GetLineWidth()) \ |
430 |
* index \ |
* index \ |
431 |
+ self.prop1.GetLineWidth() |
+ self.prop1.GetLineWidth() |
|
|
|
432 |
newProps.SetLineWidth(int(round(w))) |
newProps.SetLineWidth(int(round(w))) |
433 |
|
|
434 |
return newProps |
return newProps |
469 |
RedRamp = MonochromaticRamp(Color(1, 1, 1), Color(.8, 0, 0)) |
RedRamp = MonochromaticRamp(Color(1, 1, 1), Color(.8, 0, 0)) |
470 |
GreenRamp = MonochromaticRamp(Color(1, 1, 1), Color(0, .8, 0)) |
GreenRamp = MonochromaticRamp(Color(1, 1, 1), Color(0, .8, 0)) |
471 |
BlueRamp = MonochromaticRamp(Color(1, 1, 1), Color(0, 0, .8)) |
BlueRamp = MonochromaticRamp(Color(1, 1, 1), Color(0, 0, .8)) |
472 |
GreenToRedRamp = MonochromaticRamp(Color(1, .8, 1), Color(1, 0, 0)) |
GreenToRedRamp = MonochromaticRamp(Color(0, .8, 0), Color(1, 0, 0)) |
473 |
|
|
474 |
class HotToColdRamp: |
class HotToColdRamp: |
475 |
|
|