Skip to content

Commit

Permalink
[UI] Use a gradient of green to represent categories colors
Browse files Browse the repository at this point in the history
  • Loading branch information
oso committed Jan 8, 2012
1 parent 3a1a861 commit 0c57c8b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 21 deletions.
12 changes: 4 additions & 8 deletions graphic.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
26 changes: 13 additions & 13 deletions qgis_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit 0c57c8b

Please sign in to comment.