/b-gtk/fix-viz

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/b-gtk/fix-viz

« back to all changes in this revision

Viewing changes to annotate/colormap.py

  • Committer: Jelmer Vernooij
  • Date: 2006-05-19 16:56:46 UTC
  • mfrom: (0.1.25 gannotate)
  • Revision ID: jelmer@samba.org-20060519165646-0d867938fdbc9097
Merge in Dan Loda's gannotate plugin and put it in annotate/

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (C) 2005 Dan Loda <danloda@gmail.com>
 
2
 
 
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.
 
7
 
 
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.
 
12
 
 
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
 
16
import sys
 
17
 
 
18
class AnnotateColorMap:
 
19
 
 
20
    really_old_color = "#0046FF"
 
21
 
 
22
    colors = {
 
23
        20.: "#FF0000",
 
24
        40.: "#FF3800",
 
25
        60.: "#FF7000",
 
26
        80.: "#FFA800",
 
27
        100.:"#FFE000",
 
28
        120.:"#E7FF00",
 
29
        140.:"#AFFF00",
 
30
        160.:"#77FF00",
 
31
        180.:"#3FFF00",
 
32
        200.:"#07FF00",
 
33
        220.:"#00FF31",
 
34
        240.:"#00FF69",
 
35
        260.:"#00FFA1",
 
36
        280.:"#00FFD9",
 
37
        300.:"#00EEFF",
 
38
        320.:"#00B6FF",
 
39
        340.:"#007EFF"
 
40
    }
 
41
 
 
42
    def __init__(self, span=340.):
 
43
        self.set_span(span)
 
44
 
 
45
    def set_span(self, span):
 
46
        self._span = span
 
47
        self._scale = span / max(self.colors.keys())
 
48
 
 
49
    def _days(self, revision, now):
 
50
        return (now - revision.timestamp) / (24 * 60 * 60)
 
51
 
 
52
    def get_color(self, revision, now):
 
53
        color = self.really_old_color
 
54
        days = self.colors.keys()
 
55
        days.sort()
 
56
        days_old = self._days(revision, now)
 
57
        for day in days:
 
58
            if (days_old <= day * self._scale):
 
59
                color = self.colors[day]
 
60
                break
 
61
 
 
62
        return color
 
63
 
 
64
class AnnotateColorSaturation(AnnotateColorMap):
 
65
    def __init__(self, span=340.):
 
66
        AnnotateColorMap.__init__(self, span)
 
67
        self.current_angle = 0
 
68
 
 
69
    def hue(self, angle):
 
70
        return tuple([self.v(angle, r) for r in (0, 120, 240)])
 
71
 
 
72
    @staticmethod
 
73
    def ang(angle, rotation):
 
74
        angle += rotation
 
75
        angle = angle % 360
 
76
        if angle > 180:
 
77
            angle = 180 - (angle - 180)
 
78
        return abs(angle)
 
79
 
 
80
    def v(self, angle, rotation):
 
81
        ang = self.ang(angle, rotation)
 
82
        if ang < 60:
 
83
            return 1
 
84
        elif ang > 120:
 
85
            return 0
 
86
        else:
 
87
            return 1 - ((ang - 60) / 60)
 
88
 
 
89
    def saturate_v(self, saturation, hv):
 
90
        return int(255 - (saturation/3*(1-hv)))
 
91
    
 
92
    def committer_angle(self, committer):
 
93
        return float(abs(hash(committer))) / sys.maxint * 360.0
 
94
 
 
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