Changeset 4b84a80c18df…
Parent c6bd6201f413…
by
Changes to 3 files · Browse files at 4b84a80c18df Showing diff from parent c6bd6201f413 Diff from another changeset...
@@ -89,3 +89,31 @@ assert_equals(set([filectxs[0], filectxs[1]]), set(palette['#ffaaaa']))
assert_equals(set([filectxs[2], filectxs[3]]), set(palette['#ffaae9']))
assert_equals(set([filectxs[4]]), set(palette['#d4aaff']))
+
+def test_makeannotatepalette_mindate_included():
+ agestep = 10 * SECS_PER_DAY
+ filectxs = [fakectx(0, 0 * agestep), fakectx(0, 1 * agestep),
+ fakectx(0, 2 * agestep), fakectx(0, 3 * agestep),
+ fakectx(0, 4 * agestep), fakectx(0, 5 * agestep),
+ fakectx(0, 6 * agestep), fakectx(0, 7 * agestep)]
+ palette = colormap.makeannotatepalette(filectxs, now=7 * agestep,
+ maxcolors=4, maxhues=4,
+ maxsaturations=255,
+ mindate=2 * agestep)
+ palfctxs = set()
+ for _color, fctxs in palette.iteritems():
+ palfctxs.update(fctxs)
+ for fctx in filectxs[2:]:
+ assert fctx in palfctxs
+
+def test_makeannotatepalette_mindate_earlier_than_rev0():
+ agestep = 50 * SECS_PER_DAY
+ filectxs = [fakectx(0, 1 * agestep), fakectx(0, 2 * agestep)]
+ palette = colormap.makeannotatepalette(filectxs, now=2 * agestep,
+ maxcolors=1, maxhues=1,
+ maxsaturations=255, mindate=0)
+ palfctxs = set()
+ for _color, fctxs in palette.iteritems():
+ palfctxs.update(fctxs)
+ for fctx in filectxs:
+ assert fctx in palfctxs
|
@@ -253,11 +253,15 @@ """Redefine line markers according to the current revs"""
curdate = self.repo[self._rev].date()[0]
+ # make sure to colorize at least 1 year
+ mindate = curdate - 365 * 24 * 60 * 60
+
self._revmarkers.clear()
filectxs = iter(fctx for fctx, _origline in self._links)
palette = colormap.makeannotatepalette(filectxs, curdate,
maxcolors=32, maxhues=8,
- maxsaturations=16)
+ maxsaturations=16,
+ mindate=mindate)
for i, (color, fctxs) in enumerate(palette.iteritems()):
self.markerDefine(QsciScintilla.Background, i)
self.setMarkerBackgroundColor(QColor(color), i)
|
@@ -111,7 +111,7 @@ return "#%x%x%x" % color
def makeannotatepalette(fctxs, now, maxcolors, maxhues=None,
- maxsaturations=None):
+ maxsaturations=None, mindate=None):
"""Assign limited number of colors for annotation
:fctxs: list of filecontexts by lines
@@ -119,21 +119,37 @@ :maxcolors: max number of colors
:maxhues: max number of committer angles (hues)
:maxsaturations: max number of saturations by age
+ :mindate: reassign palette until it includes fctx of mindate
+ (requires maxsaturations)
This returns dict of {color: fctxs, ...}.
"""
+ if mindate is not None and maxsaturations is None:
+ raise ValueError('mindate must be specified with maxsaturations')
+
+ sortedfctxs = list(sorted(set(fctxs), key=lambda fctx: -fctx.date()[0]))
+ return _makeannotatepalette(sortedfctxs, now, maxcolors, maxhues,
+ maxsaturations, mindate)[0]
+
+def _makeannotatepalette(sortedfctxs, now, maxcolors, maxhues,
+ maxsaturations, mindate):
cm = AnnotateColorSaturation(maxhues=maxhues,
maxsaturations=maxsaturations)
palette = {}
+ def reassignifneeded(fctx):
+ if mindate is None or fctx.date()[0] <= mindate or maxsaturations <= 1:
+ return palette, cm
+ return _makeannotatepalette(sortedfctxs, now, maxcolors, maxhues,
+ maxsaturations - 1, mindate)
+
# assign from the latest for maximum discrimination
- sortedfctxs = sorted(set(fctxs), key=lambda fctx: -fctx.date()[0])
for fctx in sortedfctxs:
color = cm.get_color(fctx, now)
if color not in palette:
if len(palette) >= maxcolors:
- break
+ return reassignifneeded(fctx)
palette[color] = []
palette[color].append(fctx)
- return palette
+ return palette, cm # return cm for debbugging
|
Loading...