1
# Copyright (C) 2005 Dan Loda <danloda@gmail.com>
3
# This program is free software; you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation; either version 2 of the License, or
6
# (at your option) any later version.
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
# GNU General Public License for more details.
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18
class AnnotateColorMap:
20
really_old_color = "#0046FF"
42
def __init__(self, span=340.):
45
def set_span(self, span):
47
self._scale = span / max(self.colors.keys())
49
def _days(self, revision, now):
50
return (now - revision.timestamp) / (24 * 60 * 60)
52
def get_color(self, revision, now):
53
color = self.really_old_color
54
days = self.colors.keys()
56
days_old = self._days(revision, now)
58
if (days_old <= day * self._scale):
59
color = self.colors[day]
64
class AnnotateColorSaturation(AnnotateColorMap):
65
def __init__(self, span=340.):
66
AnnotateColorMap.__init__(self, span)
67
self.current_angle = 0
70
return tuple([self.v(angle, r) for r in (0, 120, 240)])
73
def ang(angle, rotation):
77
angle = 180 - (angle - 180)
80
def v(self, angle, rotation):
81
ang = self.ang(angle, rotation)
87
return 1 - ((ang - 60) / 60)
89
def saturate_v(self, saturation, hv):
90
return int(255 - (saturation/3*(1-hv)))
92
def committer_angle(self, committer):
93
return float(abs(hash(committer))) / sys.maxint * 360.0
95
def get_color(self, revision, now):
96
days = self._days(revision, now)
97
saturation = 255/((days/50) + 1)
98
hue = self.hue(self.committer_angle(revision.committer))
99
color = tuple([self.saturate_v(saturation, h) for h in hue])
100
return "#%x%x%x" % color