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: make sure to colorize revisions of 1 year old

It cuts off revisions < 1 year old if the palette is full, because their colors
are mostly white.

Changeset 4b84a80c18df

Parent c6bd6201f413

by Yuya Nishihara

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

 
89
90
91
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
@@ -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
254
255
 
 
 
256
257
258
259
260
 
 
261
262
263
 
253
254
255
256
257
258
259
260
261
262
 
263
264
265
266
267
@@ -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
112
113
114
 
115
116
117
 
119
120
121
 
 
122
123
124
 
 
 
 
 
 
 
 
 
125
126
127
128
 
 
 
 
 
 
129
130
131
132
133
134
135
 
136
137
138
139
 
 
111
112
113
 
114
115
116
117
 
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
 
147
148
149
150
 
151
152
153
154
 
155
@@ -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