Kiln » TortoiseHg » TortoiseHg
Clone URL:  
Pushed to one repository · View In Graph Contained in 1.9, 1.9.1, and 1.9.2

colormap, annotate: limit number of age saturations

Changeset c6bd6201f413

Parent 68f586d0b7fd

by Yuya Nishihara

Changes to 3 files · Browse files at c6bd6201f413 Showing diff from parent 68f586d0b7fd Diff from another changeset...

 
50
51
52
 
 
 
 
 
 
 
 
 
53
54
55
 
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
@@ -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
257
258
259
 
 
260
261
262
 
256
257
258
 
259
260
261
262
263
@@ -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
14
15
16
 
17
18
19
 
21
22
23
 
 
 
24
25
26
 
65
66
67
68
 
69
 
70
71
72
 
100
101
102
 
 
103
104
105
106
107
 
 
108
109
110
111
112
113
 
114
115
116
117
 
 
118
119
120
 
13
14
15
 
16
17
18
19
 
21
22
23
24
25
26
27
28
29
 
68
69
70
 
71
72
73
74
75
76
 
104
105
106
107
108
109
110
111
112
 
113
114
115
116
117
118
119
120
121
122
123
124
 
125
126
127
128
129
@@ -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