Commits

Nozomu Kaneko  committed f65c51f

refine graph shape and color

  • Participants
  • Parent commits a2ecc58

Comments (0)

Files changed (3)

File graph-color.diff

+# HG changeset patch
+# Parent 40fb7dea3e21f97a3d6c6e5214fa7f7856e496c6
+
+diff --git a/mercurial/graphmod.py b/mercurial/graphmod.py
+--- a/mercurial/graphmod.py
++++ b/mercurial/graphmod.py
+@@ -82,33 +82,32 @@
+     """
+     tree = []
+     seen = []
++    branch_colors = {}
+     colors = {}
+     newcolor = 1
+     maxcol = 0
+-    for (cur, type, data, parents) in dag:
++    for (cur, type, ctx, parents) in dag:
+ 
+         # Compute seen and next
+         if cur not in seen:
+-            seen.append(cur) # new head
+-            colors[cur] = newcolor
++            # new head
++            seen.append(cur)
++
++        branch = ctx.branch()
++        if branch not in branch_colors:
++            # new branch
++            branch_colors[branch] = newcolor
+             newcolor += 1
+ 
+         col = seen.index(cur)
+-        color = colors.pop(cur)
++        colors[cur] = branch_colors[branch]
++        color = colors[cur]
+         next = seen[:]
+ 
+         # Add parents to next
+         addparents = [p for p in parents if p not in next]
+         next[col:col + 1] = addparents
+ 
+-        # Set colors for the parents
+-        for i, p in enumerate(addparents):
+-            if not i:
+-                colors[p] = color
+-            else:
+-                colors[p] = newcolor
+-                newcolor += 1
+-
+         # Add edges to the graph
+         edges = []
+         for ecol, eid in enumerate(seen):
+@@ -116,17 +115,21 @@
+                 edges.append((ecol, next.index(eid), colors[eid]))
+             elif eid == cur:
+                 for p in parents:
+-                    edges.append((ecol, next.index(p), colors[p]))
++                    edges.append((ecol, next.index(p), color))
++
++        # Set colors for the parents
++        for i, p in enumerate(parents):
++            colors[p] = color
+ 
+         # Append and move on
+-        tree.append((cur, type, data, (col, color), edges))
++        tree.append((cur, type, ctx, (col, color), edges))
+         maxcol = max(maxcol, len(seen))
+         seen = next
+ 
+-    for cur, type, data, (col, color), edges in tree:
++    for cur, type, ctx, (col, color), edges in tree:
+         edges = [(maxcol - ecol - 1, maxcol - nextcol - 1, ecolor)
+                  for ecol, nextcol, ecolor in edges]
+-        yield (cur, type, data, (maxcol - col - 1, color), edges)
++        yield (cur, type, ctx, (maxcol - col - 1, color), edges)
+ 
+ def grandparent(cl, lowestrev, roots, head):
+     """Return all ancestors of head in roots which revision is

File graph-curve.diff

+# HG changeset patch
+# Parent 12a5424536ed96d2b7bb4b1aaf4135540273a823
+
+diff --git a/mercurial/templates/monoblue/graph.tmpl b/mercurial/templates/monoblue/graph.tmpl
+--- a/mercurial/templates/monoblue/graph.tmpl
++++ b/mercurial/templates/monoblue/graph.tmpl
+@@ -75,7 +75,7 @@
+         this.ctx.fill();
+ 
+         var bg = '<li class="bg parity' + parity + '"></li>';
+-        var left = (this.columns + 1.5) * this.box_size;
++        var left = (this.maxcolumns + 1.5) * this.box_size;
+         var nstyle = 'padding-left: ' + left + 'px;';
+         var item = revlink.replace(/_STYLE/, nstyle);
+         item = item.replace(/_PARITY/, 'parity' + parity);
+@@ -117,6 +117,111 @@
+ 
+     }
+ 
++    function adjust_position(position, min, max) \{
++        var stretch = 0.2;
++        var margin = 0.5;
++
++        for (var i = 0; i < data.length; i++) \{
++            var cur = data[i];
++            var edges = cur[2];
++            for (var j = 0; j < edges.length; j++) \{
++                var line = edges[j];
++                var start = line[0];
++                var end = line[1];
++                if (position[i][start].x > position[i+1][end].x) \{
++                    // get closer to the base line
++                    var d = position[i][start].x - position[i+1][end].x;
++                    position[i][start].x -= d * stretch;
++                    position[i+1][end].x += d * stretch;
++                }
++                else if (position[i][start].x < position[i+1][end].x) \{
++                    // get away from the base line
++                    var d = position[i+1][end].x - position[i][start].x;
++                    position[i][start].x += d * stretch;
++                    position[i+1][end].x -= d * stretch;
++                }
++            }
++        }
++
++        for (var i = 0; i < data.length + 1; i++) \{
++            var row = position[i];
++            for (var j in row) \{
++                for (var k in row) \{
++                    if (row[j].x > row[k].x) \{
++                        if (row[j].x - row[k].x < 1) \{
++                            var e = 1 - (row[j].x - row[k].x);
++                            row[j].x += e * margin;
++                            row[k].x -= e * margin;
++                        }
++                    }
++                    else if (row[j].x < row[k].x) \{
++                        if (row[k].x - row[j].x < 1) \{
++                            var e = 1 - (row[k].x - row[j].x);
++                            row[j].x -= e * margin;
++                            row[k].x += e * margin;
++                        }
++                    }
++                }
++            }
++        }
++
++        for (var i = 0; i < data.length + 1; i++) \{
++            var row = position[i];
++            for (var j in row) \{
++                if (row[j].x < min) \{
++                    row[j].x = min;
++                }
++                else if (row[j].x > max) \{
++                    row[j].x = max;
++                }
++            }
++        }
++    }
++
++    var max = 0;
++    var position = [];
++    for (var i = 0; i < data.length; i++) \{
++        var cur = data[i];
++        var edges = cur[2];
++        if (i == 0) \{
++            position[0] = \{};
++        }
++        position[i+1] = \{};
++        for (var j = 0; j < edges.length; j++) \{
++            var line = edges[j];
++            var start = line[0];
++            var end = line[1];
++            if (! position[i][start]) \{
++                position[i][start] = \{x: start, outlink: 0, inlink: 0};
++            }
++            if (! position[i+1][end]) \{
++                position[i+1][end] = \{x: end, outlink: 0, inlink: 0};
++            }
++            position[i][start].outlink += 1;
++            position[i+1][end].inlink += 1;
++            if (max < start) max = start;
++            if (max < end) max = end;
++        }
++    }
++
++    for (var i = 0; i < 3; i++) \{
++        adjust_position(position, 0, max);
++    }
++
++    for (var i = 0; i < data.length; i++) \{
++        var cur = data[i];
++        var node = cur[1];
++        var edges = cur[2];
++        var column = node[0];
++        for (var j = 0; j < edges.length; j++) \{
++            var line = edges[j];
++            line[0] = position[i][line[0]].x;
++            line[1] = position[i+1][line[1]].x;
++        }
++        node[0] = position[i][node[0]].x;
++    }
++
++    graph.maxcolumns = max;
+     graph.render(data);
+ 
+     // stop hiding script -->
 fix-title.diff
 page-nav.diff
 fix-direntry.diff
+graph-curve.diff
+graph-color.diff