Changeset c6bd6201f413…
Parent 68f586d0b7fd…
by
Changes to 3 files · Browse files at c6bd6201f413 Showing diff from parent 68f586d0b7fd Diff from another changeset...
@@ -50,6 +50,15 @@ for i, c in sorted(samples.iteritems(), key=lambda a: a[0]):
assert_equals(c, cm.get_color(fakectx(0, 0), float(i * SECS_PER_DAY)))
+def test_age_saturation_limit():
+ cm = colormap.AnnotateColorSaturation(maxsaturations=16)
+
+ samples = {0: '#ffaaaa', 3: '#ffaaaa', 4: '#ffafaf', 7: '#ffafaf',
+ 8: '#ffb4b4', 11: '#ffb4b4', 12: '#ffb9b9', 16: '#ffb9b9',
+ 17: '#ffbfbf', 22: '#ffbfbf', 23: '#ffc4c4', 29: '#ffc4c4'}
+ for i, c in sorted(samples.iteritems(), key=lambda a: a[0]):
+ assert_equals(c, cm.get_color(fakectx(0, 0), float(i * SECS_PER_DAY)))
+
def test_age_calc():
"""Color shouldn't depend on the date but the age"""
cm = colormap.AnnotateColorSaturation()
|
@@ -256,7 +256,8 @@ self._revmarkers.clear()
filectxs = iter(fctx for fctx, _origline in self._links)
palette = colormap.makeannotatepalette(filectxs, curdate,
- maxcolors=32, maxhues=8)
+ maxcolors=32, maxhues=8,
+ maxsaturations=16)
for i, (color, fctxs) in enumerate(palette.iteritems()):
self.markerDefine(QsciScintilla.Background, i)
self.setMarkerBackgroundColor(QColor(color), i)
|
@@ -13,7 +13,7 @@ # You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-import sys
+import sys, math
def _days(ctx, now):
return (now - ctx.date()[0]) / (24 * 60 * 60)
@@ -21,6 +21,9 @@def _rescale(val, step):
return float(step) * int(val / step)
+def _rescaleceil(val, step):
+ return float(step) * math.ceil(float(val) / step)
+
class AnnotateColorMap:
really_old_color = "#0046FF"
@@ -65,8 +68,9 @@ return color
class AnnotateColorSaturation(object):
- def __init__(self, maxhues=None):
+ def __init__(self, maxhues=None, maxsaturations=None):
self._maxhues = maxhues
+ self._maxsaturations = maxsaturations
def hue(self, angle):
return tuple([self.v(angle, r) for r in (0, 120, 240)])
@@ -100,21 +104,26 @@ def get_color(self, ctx, now):
days = _days(ctx, now)
saturation = 255/((days/50) + 1)
+ if self._maxsaturations:
+ saturation = _rescaleceil(saturation, 255. / self._maxsaturations)
hue = self.hue(self.committer_angle(ctx.user()))
color = tuple([self.saturate_v(saturation, h) for h in hue])
return "#%x%x%x" % color
-def makeannotatepalette(fctxs, now, maxcolors, maxhues=None):
+def makeannotatepalette(fctxs, now, maxcolors, maxhues=None,
+ maxsaturations=None):
"""Assign limited number of colors for annotation
:fctxs: list of filecontexts by lines
:now: latest time which will have most significat color
:maxcolors: max number of colors
:maxhues: max number of committer angles (hues)
+ :maxsaturations: max number of saturations by age
This returns dict of {color: fctxs, ...}.
"""
- cm = AnnotateColorSaturation(maxhues=maxhues)
+ cm = AnnotateColorSaturation(maxhues=maxhues,
+ maxsaturations=maxsaturations)
palette = {}
# assign from the latest for maximum discrimination
|
Loading...