Wed Sep 21 18:24:58 UTC 2005 Alberto Bertogli * Shade and zebra styles for annotate. This patch adds two more annotate styles: zebra and shade. Zebra alternates the line background colour according to the patch, just like most CVS viewers do. Shade is a lot more fun: it gives each patch a shade of a colour, the newer the brighter, so newer patches (which are often the ones you're intrested in) are easier to spot. It could use a little tuning on some constants to make it look better, but it's pretty usable as is, and it can be done later if needed. Thanks to Max Battcher for the idea. diff -rN -u old-darcsweb/darcsweb.cgi new-darcsweb/darcsweb.cgi --- old-darcsweb/darcsweb.cgi 2015-04-18 08:11:27.000000000 +0000 +++ new-darcsweb/darcsweb.cgi 2015-04-18 08:11:27.000000000 +0000 @@ -358,10 +358,14 @@ print """ plain """ % { "myreponame": config.myreponame, "fname": f } - elif f and h and action == "annotate": + + elif f and h and action.startswith("annotate"): # same for annotate print """ -plain +normal +| plain +| shade +| zebra """ % { "myreponame": config.myreponame, "fname": f, @@ -979,7 +983,7 @@ count += 1 print '' -def print_annotate(ann): +def print_annotate(ann, style): print '
' if isbinary(ann.fname): print """ @@ -988,6 +992,31 @@ """ return + if style == 'shade': + # here's the idea: we will assign to each patch a shade of + # color from its date (newer gets darker) + max = 0xff + min = max - 80 + + # to do that, we need to get a list of the patch hashes + # ordered by their dates + l = [ (date, hash) for (hash, date) in ann.patches.items() ] + l.sort() + l = [ hash for (date, hash) in l ] + + # now we have to map each element to a number in the range + # min-max, with max being close to l[0] and min l[len(l) - 1] + lenn = max - min + lenl = len(l) + shadetable = {} + for i in range(0, lenl): + hash = l[i] + n = float(i * lenn) / lenl + n = max - int(round(n)) + shadetable[hash] = n + elif style == "zebra": + lineclass = 'dark' + count = 1 prevhash = None for l in ann.lines: @@ -1002,6 +1031,21 @@ 'hash': l.phash } + if style == "shade": + linestyle = 'style="background-color:#ffff%.2x"' % \ + shadetable[l.phash] + lineclass = '' + elif style == "zebra": + linestyle = '' + if l.phash != prevhash: + if lineclass == 'dark': + lineclass = 'light' + else: + lineclass = 'dark' + else: + linestyle = '' + lineclass = '' + if l.phash != prevhash: pdate = time.strftime("%Y-%m-%d", l.pdate) @@ -1022,12 +1066,14 @@ date = "%-10.10s" % "" print """\ -
\ + """ % { + 'class': lineclass, + 'style': linestyle, 'date': date, 'desc': desc, 'c': count, @@ -1502,7 +1548,7 @@ sys.stdout.write(fixu8(l)) -def do_annotate(fname, phash): +def do_annotate(fname, phash, style): print_header() ann = get_annotate(fname, phash) print_navbar(f = fname, h = ann.lastchange_hash) @@ -1521,7 +1567,7 @@ 'fname': escape(fname), } - print_annotate(ann) + print_annotate(ann, style) print_footer() def do_annotate_plain(fname, phash): @@ -1834,7 +1880,7 @@ phash = filter_hash(form["h"].value) else: phash = None - do_annotate(fname, phash) + do_annotate(fname, phash, "normal") elif action == "annotate_plain": fname = filter_file(form["f"].value) if form.has_key("h"): @@ -1842,6 +1888,20 @@ else: phash = None do_annotate_plain(fname, phash) +elif action == "annotate_zebra": + fname = filter_file(form["f"].value) + if form.has_key("h"): + phash = filter_hash(form["h"].value) + else: + phash = None + do_annotate(fname, phash, "zebra") +elif action == "annotate_shade": + fname = filter_file(form["f"].value) + if form.has_key("h"): + phash = filter_hash(form["h"].value) + else: + phash = None + do_annotate(fname, phash, "shade") elif action == "shortlog": if form.has_key("topi"): diff -rN -u old-darcsweb/style.css new-darcsweb/style.css --- old-darcsweb/style.css 2015-04-18 08:11:27.000000000 +0000 +++ new-darcsweb/style.css 2015-04-18 08:11:27.000000000 +0000 @@ -145,15 +145,15 @@ text-align:left; } -tr.light:hover { +.light:hover { background-color:#edece6; } -tr.dark { +.dark { background-color:#f6f6f0; } -tr.dark:hover { +.dark:hover { background-color:#edece6; }