26 |
The resulting classification will consist of one group for each |
The resulting classification will consist of one group for each |
27 |
item in _list whose properties ramp between 'prop1' and 'prop2'. |
item in _list whose properties ramp between 'prop1' and 'prop2'. |
28 |
|
|
29 |
_list -- any object that implements the iterator interface |
_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 |
""" |
""" |
35 |
|
|
36 |
i = 0 |
i = 0 |
37 |
maxValue = float(len(_list) - 1) |
maxValue = float(len(_list) - 1) |
38 |
|
if maxValue < 1: maxValue = 1 |
39 |
|
|
40 |
for value in _list: |
for value in _list: |
41 |
prop = ramp.GetProperties(i / maxValue) |
prop = ramp.GetProperties(i / maxValue) |
42 |
clazz.AppendGroup(ClassGroupSingleton(value, prop)) |
clazz.AppendGroup(ClassGroupSingleton(value, prop)) |
60 |
|
|
61 |
end = "[" |
end = "[" |
62 |
maxValue = float(numGroups - 1) |
maxValue = float(numGroups - 1) |
63 |
|
if maxValue < 1: maxValue = 1 |
64 |
|
|
65 |
for i in range(1, numGroups + 1): |
for i in range(1, numGroups + 1): |
66 |
|
|
67 |
prop = ramp.GetProperties(float(i-1) / maxValue) |
prop = ramp.GetProperties(float(i-1) / maxValue) |
68 |
|
|
69 |
if intStep: |
if intStep: |
70 |
cur_max = min + int(round((i * (max - min + 1)) / maxValue)) |
cur_max = min + int(round((i * (max - min + 1)) / float(numGroups))) |
71 |
else: |
else: |
72 |
cur_max = min + (i * (max - min)) / maxValue |
cur_max = min + (i * (max - min)) / float(numGroups) |
73 |
|
|
74 |
if i == numGroups: |
if i == numGroups: |
75 |
cur_max = max |
cur_max = max |
129 |
end = "]" |
end = "]" |
130 |
|
|
131 |
maxValue = float(numGroups - 1) |
maxValue = float(numGroups - 1) |
132 |
|
if maxValue < 1: maxValue = 1 |
133 |
for (q, p) in quantiles[3]: |
for (q, p) in quantiles[3]: |
134 |
|
|
135 |
prop = ramp.GetProperties(float(i-1) / maxValue) |
prop = ramp.GetProperties(float(i-1) / maxValue) |
194 |
end = "]" |
end = "]" |
195 |
|
|
196 |
maxValue = float(numGroups - 1) |
maxValue = float(numGroups - 1) |
197 |
|
if maxValue < 1: maxValue = 1 |
198 |
for (q, p) in quantiles[3][1:]: |
for (q, p) in quantiles[3][1:]: |
199 |
prop = ramp.GetProperties(float(i-1) / maxValue) |
prop = ramp.GetProperties(float(i-1) / maxValue) |
200 |
|
|
377 |
class CustomRamp: |
class CustomRamp: |
378 |
|
|
379 |
def __init__(self, prop1, prop2): |
def __init__(self, prop1, prop2): |
380 |
|
"""Create a ramp between prop1 and prop2.""" |
381 |
self.prop1 = prop1 |
self.prop1 = prop1 |
382 |
self.prop2 = prop2 |
self.prop2 = prop2 |
383 |
|
|
384 |
def GetRamp(self): |
def GetRamp(self): |
385 |
|
"""Return this ramp.""" |
386 |
return self |
return self |
387 |
|
|
388 |
def GetProperties(self, index): |
def GetProperties(self, index): |
398 |
|
|
399 |
newProps = ClassGroupProperties() |
newProps = ClassGroupProperties() |
400 |
|
|
401 |
color1 = self.prop1.GetLineColor() |
self.__SetProperty(self.prop1.GetLineColor(), |
402 |
color2 = self.prop2.GetLineColor() |
self.prop2.GetLineColor(), |
403 |
|
index, newProps.SetLineColor) |
404 |
self.__SetProperty(color1, color2, index, newProps.SetLineColor) |
self.__SetProperty(self.prop1.GetFill(), self.prop2.GetFill(), |
405 |
self.__SetProperty(color1, color2, index, newProps.SetFill) |
index, newProps.SetFill) |
406 |
|
|
407 |
w = (self.prop2.GetLineWidth() - self.prop1.GetLineWidth()) \ |
w = (self.prop2.GetLineWidth() - self.prop1.GetLineWidth()) \ |
408 |
* index \ |
* index \ |
409 |
+ self.prop1.GetLineWidth() |
+ self.prop1.GetLineWidth() |
|
|
|
410 |
newProps.SetLineWidth(int(round(w))) |
newProps.SetLineWidth(int(round(w))) |
411 |
|
|
412 |
return newProps |
return newProps |
413 |
|
|
414 |
def __SetProperty(self, color1, color2, index, setf): |
def __SetProperty(self, color1, color2, index, setf): |
415 |
|
"""Use setf to set the appropriate property for the point |
416 |
|
index percent between color1 and color2. setf is a function |
417 |
|
to call that accepts a Color object or Transparent. |
418 |
|
""" |
419 |
|
|
420 |
if color1 is Transparent and color2 is Transparent: |
if color1 is Transparent and color2 is Transparent: |
421 |
setf(Transparent) |
setf(Transparent) |
436 |
(color2.blue - color1.blue) * index + color1.blue)) |
(color2.blue - color1.blue) * index + color1.blue)) |
437 |
|
|
438 |
class MonochromaticRamp(CustomRamp): |
class MonochromaticRamp(CustomRamp): |
439 |
|
"""Helper class to make ramps between two colors.""" |
440 |
|
|
441 |
def __init__(self, start, end): |
def __init__(self, start, end): |
442 |
|
"""Create a Monochromatic Ramp. |
443 |
|
|
444 |
|
start -- starting Color |
445 |
|
|
446 |
|
end -- ending Color |
447 |
|
""" |
448 |
sp = ClassGroupProperties() |
sp = ClassGroupProperties() |
449 |
sp.SetLineColor(start) |
sp.SetLineColor(start) |
450 |
sp.SetFill(start) |
sp.SetFill(start) |
455 |
|
|
456 |
CustomRamp.__init__(self, sp, ep) |
CustomRamp.__init__(self, sp, ep) |
457 |
|
|
458 |
GreyRamp = MonochromaticRamp(Color(1, 1, 1), Color(0, 0, 0)) |
grey_ramp = MonochromaticRamp(Color(1, 1, 1), Color(0, 0, 0)) |
459 |
RedRamp = MonochromaticRamp(Color(1, 1, 1), Color(.8, 0, 0)) |
red_ramp = MonochromaticRamp(Color(1, 1, 1), Color(.8, 0, 0)) |
460 |
GreenRamp = MonochromaticRamp(Color(1, 1, 1), Color(0, .8, 0)) |
green_ramp = MonochromaticRamp(Color(1, 1, 1), Color(0, .8, 0)) |
461 |
BlueRamp = MonochromaticRamp(Color(1, 1, 1), Color(0, 0, .8)) |
blue_ramp = MonochromaticRamp(Color(1, 1, 1), Color(0, 0, .8)) |
462 |
GreenToRedRamp = MonochromaticRamp(Color(1, .8, 1), Color(1, 0, 0)) |
green_to_red_ramp = MonochromaticRamp(Color(0, .8, 0), Color(1, 0, 0)) |
463 |
|
|
464 |
class HotToColdRamp: |
class HotToColdRamp: |
465 |
|
"""A ramp that generates properties with colors ranging from |
466 |
|
'hot' colors (e.g. red, orange) to 'cold' colors (e.g. green, blue) |
467 |
|
""" |
468 |
|
|
469 |
def GetRamp(self): |
def GetRamp(self): |
470 |
|
"""Return this ramp.""" |
471 |
return self |
return self |
472 |
|
|
473 |
def GetProperties(self, index): |
def GetProperties(self, index): |
498 |
|
|
499 |
return prop |
return prop |
500 |
|
|
501 |
|
class FixedRamp: |
502 |
|
"""FixedRamp allows particular properties of a ramp to be |
503 |
|
held constant over the ramp. |
504 |
|
""" |
505 |
|
|
506 |
|
def __init__(self, ramp, fixes): |
507 |
|
""" |
508 |
|
ramp -- a source ramp to get the default properties |
509 |
|
|
510 |
|
fixes -- a tuple (lineColor, lineWidth, fillColor) such that |
511 |
|
if any item is not None, the appropriate property will |
512 |
|
be fixed to that item value. |
513 |
|
""" |
514 |
|
|
515 |
|
self.fixes = fixes |
516 |
|
self.ramp = ramp |
517 |
|
|
518 |
|
def GetRamp(self): |
519 |
|
"""Return this ramp.""" |
520 |
|
return self |
521 |
|
|
522 |
|
def GetProperties(self, index): |
523 |
|
"""Return a ClassGroupProperties object whose properties |
524 |
|
represent a point at 'index' between the properties in |
525 |
|
the ramp that initialized this FixedRamp. |
526 |
|
|
527 |
|
index -- a value such that 0 <= index <= 1 |
528 |
|
""" |
529 |
|
|
530 |
|
props = self.ramp.GetProperties(index) |
531 |
|
if self.fixes[0] is not None: props.SetLineColor(self.fixes[0]) |
532 |
|
if self.fixes[1] is not None: props.SetLineWidth(self.fixes[1]) |
533 |
|
if self.fixes[2] is not None: props.SetFill(self.fixes[2]) |
534 |
|
|
535 |
|
return props |