Permalink
Browse files

[UI] Use a gradient of green to represent categories colors

  • Loading branch information...
1 parent 3a1a861 commit 0c57c8b30572db9041a5cfe3dac18aa9bd60cb55 @oso committed Jan 8, 2012
Showing with 17 additions and 21 deletions.
  1. +4 −8 graphic.py
  2. +13 −13 qgis_utils.py
View
@@ -146,14 +146,10 @@ def __profile_get_points(self, profile):
return points
def __get_category_brush(self, category):
- nprof = len(self.model.profiles)
- if nprof == 0:
- h = 1
- else:
- h = 1-float(category)/nprof*float(2)/3
- r, g, b = colorsys.hls_to_rgb(h, 0.5, 0.5)
- return QtGui.QBrush(QtGui.QColor(r*255, g*255, b*255))
-
+ ncategories = len(self.model.profiles)+1
+ color = QtGui.QColor(0, 255-220*(ncategories-category)/(ncategories), 0)
+ return QtGui.QBrush(QtGui.QColor(color))
+
def __plot_profiles(self):
profiles = self.model.profiles
minima = self.model.model_min
View
@@ -148,27 +148,27 @@ def render_decision_map_old(layer, nprofils):
sr = QgsUniqueValueRenderer(layer.geometryType())
sr.setClassificationField(0)
- for i in range(1, nprofils+2):
+ nclasses = nprofils+1
+ for i in range(nclasses):
s = QgsSymbol(layer.geometryType())
- h = 1-float(i-1)/nprofils*float(2)/3
- r, g, b = colorsys.hls_to_rgb(h, 0.5, 0.5)
- s.setBrush(QBrush(QColor(r*255, g*255, b*255)))
- label = 'Category %d' % i
+ color = QColor(0, 255-220*(nclasses-1-i)/(nclasses), 0)
+ s.setBrush(QBrush(color))
+ label = 'Category %d' % (i+1)
s.setLabel(label)
- s.setLowerValue(str(i))
- s.setUpperValue(str(i))
- sr.insertValue(str(i), s)
+ s.setLowerValue(str(i+1))
+ s.setUpperValue(str(i+1))
+ sr.insertValue(str(i+1), s)
layer.setRenderer(sr)
def render_decision_map_new(layer, nprofils):
cat_list = []
- for i in range(1, nprofils+2):
+ nclasses = nprofils+1
+ for i in range(nclasses):
s = QgsSymbolV2.defaultSymbol(layer.geometryType())
- h = 1-float(i-1)/nprofils*float(2)/3
- r, g, b = colorsys.hls_to_rgb(h, 0.5, 0.5)
- s.setColor(QColor(r*255, g*255, b*255))
- cat_list.append(QgsRendererCategoryV2(i, s, 'Category %d' % i))
+ color = QColor(0, 255-220*(nclasses-1-i)/(nclasses), 0)
+ s.setColor(color)
+ cat_list.append(QgsRendererCategoryV2(i+1, s, 'Category %d' % (i+1)))
sr = QgsCategorizedSymbolRendererV2("categories", cat_list)
sr.setClassAttribute("category")

0 comments on commit 0c57c8b

Please sign in to comment.