/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 viz/linegraph.py

  • Committer: Gary van der Merwe
  • Date: 2007-08-16 11:18:01 UTC
  • mto: (256.2.37 gtk)
  • mto: This revision was merged to the branch mainline in revision 289.
  • Revision ID: garyvdm@gmail.com-20070816111801-o1a22rjj6n7odyyy
Implement color selection

Show diffs side-by-side

added added

removed removed

Lines of Context:
13
13
from bzrlib.revision import Revision
14
14
from bzrlib.tsort import merge_sort
15
15
 
16
 
def linegraph(revisions, revisionparents, maxnum):
 
16
def linegraph(revisions, revisionparents, revindex):
17
17
    """Produce a directed graph of a bzr branch.
18
18
 
19
19
    Returns a list of tuples of (revision, node, lines, parents, children).
33
33
    curved, kinked, etc.) and to pick the actual colours for each index.
34
34
    """
35
35
    
 
36
    directparentcache = [None for revision in revisions]
 
37
    def getdirectparent(childindex, childsparents):
 
38
        """Return the revision id of the direct parent
 
39
        
 
40
        The direct parent is the first parent with the same committer"""
 
41
        childrevision = revisions[childindex]
 
42
        directparent = directparentcache[childindex]
 
43
        if directparent is None:
 
44
            for parentrevid in childsparents:
 
45
                parentrevision = revisions[revindex[parentrevid]]
 
46
                if childrevision.committer == parentrevision.committer:
 
47
                    directparent = parentrevid
 
48
                    break
 
49
            #no parents have the same commiter
 
50
            if directparent is None:
 
51
                directparent = ""
 
52
            directparentcache[childindex] = directparent
 
53
        return directparent
 
54
        
 
55
 
 
56
    
36
57
    #This will hold the lines we have not yet added to lines
37
58
    #The position of the item in this list indicates the column, and it
38
59
    #it may change if we need to make space for other branches.
42
63
    
43
64
    linegraph = []
44
65
    
 
66
    lastcolor = 0
 
67
    
45
68
    for (index, revision) in enumerate(revisions):
46
69
        parents = [parent for parent in revisionparents[index]\
47
70
                   if parent!="null:"]
76
99
        if revnodecolumn is None:
77
100
            revnodecolumn = 0
78
101
        
79
 
        color = 0
 
102
        color = None
 
103
        
 
104
        #Try and see if we are the same "branch" as one of our children
 
105
        #If we are, use the childs color
 
106
        for childrevid in children:
 
107
            childindex = revindex[childrevid]
 
108
            childsparents = revisionparents[childindex]
 
109
            if len(children) == 1 and len(childsparents) == 1: 
 
110
                # one-one relationship between parent and child, same colour
 
111
                #1st [1] selects the node
 
112
                #2nd [1] selects the color
 
113
                color = linegraph[childindex][1][1]
 
114
                break
 
115
            
 
116
            #Is the current revision the direct parent of the child?
 
117
            if revision.revision_id == getdirectparent(childindex, childsparents):
 
118
                color = linegraph[childindex][1][1]
 
119
                break
 
120
        
 
121
        if color is None:
 
122
            color = lastcolor = lastcolor + 1
80
123
        
81
124
        #We now have every thing (except for the lines) so we can add
82
125
        #our tuple to our list.
135
178
                    #no more columns, so add one to the end
136
179
                    activelines.append(line)
137
180
                    break
138
 
        if maxnum is not None and index > maxnum:
139
 
            break
140
181
 
141
182
    return linegraph
142
183