Use category min/max in change list colors

When colorizing the votes on the change list, look up the category
min and max values to use the stronger versions of those colors
only if the min or max values are present.

Change-Id: I37525f0d9cda09b644a4a9dac5266cb6d56ca346
This commit is contained in:
James E. Blair 2015-01-21 17:29:20 +13:00
parent 2da6039416
commit c320a48c2a
4 changed files with 41 additions and 14 deletions

View File

@ -231,6 +231,22 @@ class Change(object):
cat_value[approval.category] = cur_value cat_value[approval.category] = cur_value
self._approval_cache = cat_value self._approval_cache = cat_value
def getMinMaxPermittedForCategory(self, category):
if not hasattr(self, '_permitted_cache'):
self._updatePermittedCache()
return self._permitted_cache.get(category, (0,0))
def _updatePermittedCache(self):
cache = {}
for label in self.labels:
if label.category not in cache:
cache[label.category] = [0, 0]
if label.value > cache[label.category][1]:
cache[label.category][1] = label.value
if label.value < cache[label.category][0]:
cache[label.category][0] = label.value
self._permitted_cache = cache
def createRevision(self, *args, **kw): def createRevision(self, *args, **kw):
session = Session.object_session(self) session = Session.object_session(self)
args = [self] + list(args) args = [self] + list(args)

View File

@ -23,6 +23,10 @@ DEFAULT_PALETTE={
'negative-label': ['dark red', ''], 'negative-label': ['dark red', ''],
'max-label': ['light green', ''], 'max-label': ['light green', ''],
'min-label': ['light red', ''], 'min-label': ['light red', ''],
'focused-positive-label': ['dark green,standout', ''],
'focused-negative-label': ['dark red,standout', ''],
'focused-max-label': ['light green,standout', ''],
'focused-min-label': ['light red,standout', ''],
'link': ['dark blue', ''], 'link': ['dark blue', ''],
'focused-link': ['light blue', ''], 'focused-link': ['light blue', ''],
# Diff # Diff

View File

@ -569,14 +569,8 @@ class ChangeView(urwid.WidgetWrap):
self.commit_message.set_text(change.revisions[-1].message) self.commit_message.set_text(change.revisions[-1].message)
categories = [] categories = []
max_values = {}
min_values = {}
approval_headers = [urwid.Text(('table-header', 'Name'))] approval_headers = [urwid.Text(('table-header', 'Name'))]
for label in change.labels: for label in change.labels:
if label.value > max_values.get(label.category, 0):
max_values[label.category] = label.value
if label.value < min_values.get(label.category, 0):
min_values[label.category] = label.value
if label.category in categories: if label.category in categories:
continue continue
approval_headers.append(urwid.Text(('table-header', label.category))) approval_headers.append(urwid.Text(('table-header', label.category)))
@ -600,15 +594,16 @@ class ChangeView(urwid.WidgetWrap):
approvals_for_name[approval.reviewer.name] = approvals approvals_for_name[approval.reviewer.name] = approvals
votes.addRow(row) votes.addRow(row)
if str(approval.value) != '0': if str(approval.value) != '0':
cat_min, cat_max = change.getMinMaxPermittedForCategory(approval.category)
if approval.value > 0: if approval.value > 0:
val = '+%i' % approval.value val = '+%i' % approval.value
if approval.value == max_values.get(approval.category): if approval.value == cat_max:
val = ('max-label', val) val = ('max-label', val)
else: else:
val = ('positive-label', val) val = ('positive-label', val)
else: else:
val = '%i' % approval.value val = '%i' % approval.value
if approval.value == min_values.get(approval.category): if approval.value == cat_min:
val = ('min-label', val) val = ('min-label', val)
else: else:
val = ('negative-label', val) val = ('negative-label', val)

View File

@ -50,6 +50,10 @@ class ChangeRow(urwid.Button):
change_focus_map = {None: 'focused', change_focus_map = {None: 'focused',
'unreviewed-change': 'focused-unreviewed-change', 'unreviewed-change': 'focused-unreviewed-change',
'reviewed-change': 'focused-reviewed-change', 'reviewed-change': 'focused-reviewed-change',
'positive-label': 'focused-positive-label',
'negative-label': 'focused-negative-label',
'min-label': 'focused-min-label',
'max-label': 'focused-max-label',
} }
def selectable(self): def selectable(self):
@ -100,14 +104,22 @@ class ChangeRow(urwid.Button):
del self.columns.contents[self.num_columns:] del self.columns.contents[self.num_columns:]
for category in categories: for category in categories:
v = change.getMaxForCategory(category) v = change.getMaxForCategory(category)
cat_min, cat_max = change.getMinMaxPermittedForCategory(category)
if v == 0: if v == 0:
v = '' val = ''
elif v < 0:
v = ('min-label', '%2i' % v)
elif v > 0: elif v > 0:
v = ('max-label', '%2i' % v) val = '%2i' % v
if v == cat_max:
self.columns.contents.append((urwid.Text(v), self.columns.options('given', 2))) val = ('max-label', val)
else:
val = ('positive-label', val)
else:
val = '%i' % v
if v == cat_min:
val = ('min-label', val)
else:
val = ('negative-label', val)
self.columns.contents.append((urwid.Text(val), self.columns.options('given', 2)))
class ChangeListHeader(urwid.WidgetWrap): class ChangeListHeader(urwid.WidgetWrap):
def __init__(self, project=False, owner=False, updated=False): def __init__(self, project=False, owner=False, updated=False):