##// END OF EJS Templates
Revision graph code cleanup....
Etienne Massip -
r8653:b9c26d6ddcd3
parent child
Show More
@@ -256,59 +256,64 module RepositoriesHelper
256 '<br />'.html_safe + l(:text_scm_path_encoding_note))
256 '<br />'.html_safe + l(:text_scm_path_encoding_note))
257 end
257 end
258
258
259 def index_commits(commits, heads, href_proc = nil)
259 def index_commits(commits, heads)
260 return nil if commits.nil? or commits.first.parents.nil?
260 return nil if commits.nil? or commits.first.parents.nil?
261 map = {}
261
262 commit_hashes = []
263 refs_map = {}
262 refs_map = {}
264 href_proc ||= Proc.new {|x|x}
263 heads.each do |head|
265 heads.each{|r| refs_map[r.scmid] ||= []; refs_map[r.scmid] << r}
264 refs_map[head.scmid] ||= []
266 commits.reverse.each_with_index do |c, i|
265 refs_map[head.scmid] << head
267 h = {}
268 h[:parents] = c.parents.collect do |p|
269 [p.scmid, 0, 0]
270 end
271 h[:rdmid] = i
272 h[:space] = 0
273 h[:refs] = refs_map[c.scmid].join(" ") if refs_map.include? c.scmid
274 h[:scmid] = c.scmid
275 h[:href] = href_proc.call(c.scmid)
276 commit_hashes << h
277 map[c.scmid] = h
278 end
266 end
279 heads.sort! do |a,b|
267
280 a.to_s <=> b.to_s
268 commits_by_scmid = {}
269 commits.reverse.each_with_index do |commit, commit_index|
270
271 commits_by_scmid[commit.scmid] = {
272 :parent_scmids => commit.parents.collect { |parent| parent.scmid },
273 :rdmid => commit_index,
274 :space => 0,
275 :refs => refs_map.include?(commit.scmid) ? refs_map[commit.scmid].join(" ") : nil,
276 :scmid => commit.scmid,
277 :href => block_given? ? yield(commit.scmid) : commit.scmid
278 }
281 end
279 end
282 j = 0
280
283 heads.each do |h|
281 heads.sort! { |head1, head2| head1.to_s <=> head2.to_s }
284 if map.include? h.scmid then
282
285 j = mark_chain(j += 1, map[h.scmid], map)
283 mark_index = 0
284 heads.each do |head|
285 if commits_by_scmid.include? head.scmid
286 mark_index = mark_chain(mark_index += 1, commits_by_scmid[head.scmid], commits_by_scmid)
286 end
287 end
287 end
288 end
288 # when no head matched anything use first commit
289 # when no head matched anything use first commit
289 if j == 0 then
290 if mark_index == 0
290 mark_chain(j += 1, map.values.first, map)
291 mark_chain(mark_index += 1, commits_by_scmid.values.first, commits_by_scmid)
291 end
292 end
292 map
293 commits_by_scmid
293 end
294 end
294
295
295 def mark_chain(mark, commit, map)
296 def mark_chain(mark_index, commit, commits_by_scmid)
296 stack = [[mark, commit]]
297
297 markmax = mark
298 stack = [[mark_index, commit]]
299 mark_max_index = mark_index
300
298 until stack.empty?
301 until stack.empty?
299 current = stack.pop
302 mark_index, commit = stack.pop
300 m, commit = current
303 commit[:space] = mark_index if commit[:space] == 0
301 commit[:space] = m if commit[:space] == 0
304
302 m1 = m - 1
305 mark_index -=1
303 commit[:parents].each_with_index do |p, i|
306 commit[:parent_scmids].each_with_index do |parent_scmid, parent_index|
304 psha = p[0]
307
305 if map.include? psha and map[psha][:space] == 0 then
308 parent_commit = commits_by_scmid[parent_scmid]
306 stack << [m1 += 1, map[psha]] if i == 0
309
307 stack = [[m1 += 1, map[psha]]] + stack if i > 0
310 if parent_commit and parent_commit[:space] == 0
311
312 stack.unshift [mark_index += 1, parent_commit]
308 end
313 end
309 end
314 end
310 markmax = m1 if markmax < m1
315 mark_max_index = mark_index if mark_max_index < mark_index
311 end
316 end
312 markmax
317 mark_max_index
313 end
318 end
314 end
319 end
@@ -1,13 +1,12
1 <%= javascript_include_tag "raphael.js" %>
1 <%= javascript_include_tag 'raphael.js' %>
2 <script type="text/javascript" charset="utf-8">
2 <%= javascript_include_tag 'revision_graph.js' %>
3 var chunk = {commits:<%= commits.values.to_json.html_safe %>}
4 </script>
5 <%= javascript_include_tag "revision_graph.js" %>
6
3
7 <script type="text/javascript">
4 <script type="text/javascript" charset="utf-8">
8 Event.observe(window,"load", function(){
5 Event.observe(window, 'load', function(){
9 branchGraph(document.getElementById("holder"));
6 branchGraph(
10 })
7 document.getElementById("holder"),
8 <%= commits.to_json.html_safe %>);
9 });
11 </script>
10 </script>
12
11
13 <div id="holder" class="graph"></div>
12 <div id="holder" class="graph"></div>
@@ -24,18 +24,18
24 <% if show_revision_graph %>
24 <% if show_revision_graph %>
25 <% if line_num == 1 %>
25 <% if line_num == 1 %>
26 <td class="revision_graph" rowspan="<%= revisions.size %>">
26 <td class="revision_graph" rowspan="<%= revisions.size %>">
27 <% href_base = Proc.new {|x| url_for(:controller => 'repositories',
28 :action => 'revision',
29 :id => project,
30 :repository_id => @repository.identifier_param,
31 :rev => x) } %>
32 <%= render :partial => 'revision_graph',
27 <%= render :partial => 'revision_graph',
33 :locals => {
28 :locals => {
34 :commits => index_commits(
29 :commits => index_commits(
35 revisions,
30 revisions,
36 @repository.branches,
31 @repository.branches) do |scmid|
37 href_base
32 url_for(
38 )
33 :controller => 'repositories',
34 :action => 'revision',
35 :id => project,
36 :repository_id => @repository.identifier_param,
37 :rev => scmid)
38 end
39 } %>
39 } %>
40 </td>
40 </td>
41 <% end %>
41 <% end %>
@@ -1,172 +1,99
1 var commits = chunk.commits,
2 comms = {},
3 pixelsX = [],
4 pixelsY = [],
5 mmax = Math.max,
6 max_rdmid = 0,
7 max_space = 0,
8 parents = {};
9 for (var i = 0, ii = commits.length; i < ii; i++) {
10 for (var j = 0, jj = commits[i].parents.length; j < jj; j++) {
11 parents[commits[i].parents[j][0]] = true;
12 }
13 max_rdmid = Math.max(max_rdmid, commits[i].rdmid);
14 max_space = Math.max(max_space, commits[i].space);
15 }
16
1
17 for (i = 0; i < ii; i++) {
2 function branchGraph(holder, commits_hash) {
18 if (commits[i].scmid in parents) {
3
19 commits[i].isParent = true;
4 var LEFT_PADDING = 3,
5 TOP_PADDING = 10,
6 XSTEP = YSTEP = 20;
7
8 var commits_by_scmid = $H(commits_hash),
9 commits = commits_by_scmid.values();
10
11 // init max dimensions
12 var max_rdmid = max_space = 0;
13 commits.each(function(commit) {
14
15 max_rdmid = Math.max(max_rdmid, commit.rdmid);
16 max_space = Math.max(max_space, commit.space);
17 });
18
19 var graph_height = max_rdmid * YSTEP + YSTEP,
20 graph_width = max_space * XSTEP + XSTEP;
21
22 // init colors
23 var colors = ['#000'];
24 for (var k = 0; k < max_space; k++) {
25 colors.push(Raphael.getColor());
20 }
26 }
21 comms[commits[i].scmid] = commits[i];
27
22 }
28 // create graph
23 var colors = ["#000"];
29 var graph = Raphael(holder, graph_width, graph_height),
24 for (var k = 0; k < max_space; k++) {
30 top = graph.set();
25 colors.push(Raphael.getColor());
31
26 }
32 var parent_commit;
27
33 var x, y, parent_x, parent_y;
28 function branchGraph(holder) {
34 var path, longrefs, shortrefs, label, labelBBox;
29 var xstep = 20, ystep = 20;
35
30 var ch, cw;
36 commits.each(function(commit) {
31 cw = max_space * xstep + xstep;
37
32 ch = max_rdmid * ystep + ystep;
38 y = TOP_PADDING + YSTEP *(max_rdmid - commit.rdmid);
33 var r = Raphael("holder", cw, ch),
39 x = LEFT_PADDING + XSTEP * commit.space;
34 top = r.set();
40
35 var cuday = 0, cumonth = "";
41 graph.circle(x, y, 3).attr({fill: colors[commit.space], stroke: 'none'});
36
42
37 for (i = 0; i < ii; i++) {
43 // title
38 var x, y;
44 if (commit.refs != null && commit.refs != '') {
39 y = 10 + ystep *(max_rdmid - commits[i].rdmid);
45 longrefs = commit.refs;
40 x = 3 + xstep * commits[i].space;
46 shortrefs = longrefs.length > 15 ? longrefs.substr(0, 13) + '...' : longrefs;
41 var stroke = "none";
47
42 r.circle(x, y, 3).attr({fill: colors[commits[i].space], stroke: stroke});
48 label = graph.text(x + 5, y + 5, shortrefs)
43 if (commits[i].refs != null && commits[i].refs != "") {
49 .attr({
44 var longrefs = commits[i].refs
50 font: '12px Fontin-Sans, Arial',
45 var shortrefs = commits[i].refs;
51 fill: '#666',
46 if (shortrefs.length > 15) {
52 title: longrefs,
47 shortrefs = shortrefs.substr(0,13) + "...";
53 cursor: 'pointer',
48 }
54 rotation: '0'});
49 var t = r.text(x+5,y+5,shortrefs).attr({font: "12px Fontin-Sans, Arial", fill: "#666",
55
50 title: longrefs, cursor: "pointer", rotation: "0"});
56 labelBBox = label.getBBox();
51
57 label.translate(labelBBox.width / 2, -labelBBox.height / 3);
52 var textbox = t.getBBox();
58 }
53 t.translate(textbox.width / 2, textbox.height / -3);
59
54 }
60 // paths to parents
55 for (var j = 0, jj = commits[i].parents.length; j < jj; j++) {
61 commit.parent_scmids.each(function(parent_scmid) {
56 var c = comms[commits[i].parents[j][0]];
62 parent_commit = commits_by_scmid.get(parent_scmid);
57 var p,arrow;
63
58 if (c) {
64 if (parent_commit) {
59 var cy, cx;
65 parent_y = TOP_PADDING + YSTEP * (max_rdmid - parent_commit.rdmid);
60 cy = 10 + ystep * (max_rdmid - c.rdmid),
66 parent_x = LEFT_PADDING + XSTEP * parent_commit.space;
61 cx = 3 + xstep * c.space;
67
62
68 if (parent_commit.space == commit.space) {
63 if (c.space == commits[i].space) {
69 // vertical path
64 p = r.path("M" + x + "," + y + "L" + cx + "," + cy);
70 path = graph.path([
71 'M', x, y,
72 'V', parent_y]);
65 } else {
73 } else {
66 p = r.path(["M", x, y, "C",x,y,x, y+(cy-y)/2,x+(cx-x)/2, y+(cy-y)/2,
74 // path to a commit in a different branch (Bezier curve)
67 "C", x+(cx-x)/2,y+(cy-y)/2, cx, cy-(cy-y)/2, cx, cy]);
75 path = graph.path([
76 'M', x, y,
77 'C', x, y, x, y + (parent_y - y) / 2, x + (parent_x - x) / 2, y + (parent_y - y) / 2,
78 'C', x + (parent_x - x) / 2, y + (parent_y - y) / 2, parent_x, parent_y-(parent_y-y)/2, parent_x, parent_y]);
68 }
79 }
69 } else {
80 } else {
70 p = r.path("M" + x + "," + y + "L" + x + "," + ch);
81 // vertical path ending at the bottom of the graph
71 }
82 path = graph.path([
72 p.attr({stroke: colors[commits[i].space], "stroke-width": 1.5});
83 'M', x, y,
73 }
84 'V', graph_height]);
74 (function (c, x, y) {
75 top.push(r.circle(x, y, 10).attr({fill: "#000", opacity: 0,
76 cursor: "pointer", href: commits[i].href})
77 .hover(function () {}, function () {})
78 );
79 }(commits[i], x, y));
80 }
81 top.toFront();
82 var hw = holder.offsetWidth,
83 hh = holder.offsetHeight,
84 drag,
85 dragger = function (e) {
86 if (drag) {
87 e = e || window.event;
88 holder.scrollLeft = drag.sl - (e.clientX - drag.x);
89 holder.scrollTop = drag.st - (e.clientY - drag.y);
90 }
85 }
91 };
86 path.attr({stroke: colors[commit.space], "stroke-width": 1.5});
92 holder.onmousedown = function (e) {
87 });
93 e = e || window.event;
94 drag = {x: e.clientX, y: e.clientY, st: holder.scrollTop, sl: holder.scrollLeft};
95 document.onmousemove = dragger;
96 };
97 document.onmouseup = function () {
98 drag = false;
99 document.onmousemove = null;
100 };
101 holder.scrollLeft = cw;
102 };
103
88
104 Raphael.fn.popupit = function (x, y, set, dir, size) {
89 top.push(graph.circle(x, y, 10)
105 dir = dir == null ? 2 : dir;
90 .attr({
106 size = size || 5;
91 fill: '#000',
107 x = Math.round(x);
92 opacity: 0,
108 y = Math.round(y);
93 cursor: 'pointer',
109 var bb = set.getBBox(),
94 href: commit.href})
110 w = Math.round(bb.width / 2),
95 .hover(function () {}, function () {}));
111 h = Math.round(bb.height / 2),
96 });
112 dx = [0, w + size * 2, 0, -w - size * 2],
113 dy = [-h * 2 - size * 3, -h - size, 0, -h - size],
114 p = ["M", x - dx[dir], y - dy[dir], "l", -size, (dir == 2) * -size, -mmax(w - size, 0),
115 0, "a", size, size, 0, 0, 1, -size, -size,
116 "l", 0, -mmax(h - size, 0), (dir == 3) * -size, -size, (dir == 3) * size, -size, 0,
117 -mmax(h - size, 0), "a", size, size, 0, 0, 1, size, -size,
118 "l", mmax(w - size, 0), 0, size, !dir * -size, size, !dir * size, mmax(w - size, 0),
119 0, "a", size, size, 0, 0, 1, size, size,
120 "l", 0, mmax(h - size, 0), (dir == 1) * size, size, (dir == 1) * -size, size, 0,
121 mmax(h - size, 0), "a", size, size, 0, 0, 1, -size, size,
122 "l", -mmax(w - size, 0), 0, "z"].join(","),
123 xy = [{x: x, y: y + size * 2 + h},
124 {x: x - size * 2 - w, y: y},
125 {x: x, y: y - size * 2 - h},
126 {x: x + size * 2 + w, y: y}]
127 [dir];
128 set.translate(xy.x - w - bb.x, xy.y - h - bb.y);
129 return this.set(this.path(p).attr({fill: "#234", stroke: "none"})
130 .insertBefore(set.node ? set : set[0]), set);
131 };
132
97
133 Raphael.fn.popup = function (x, y, text, dir, size) {
98 top.toFront();
134 dir = dir == null ? 2 : dir > 3 ? 3 : dir;
135 size = size || 5;
136 text = text || "$9.99";
137 var res = this.set(),
138 d = 3;
139 res.push(this.path().attr({fill: "#000", stroke: "#000"}));
140 res.push(this.text(x, y, text).attr(this.g.txtattr).attr({fill: "#fff", "font-family": "Helvetica, Arial"}));
141 res.update = function (X, Y, withAnimation) {
142 X = X || x;
143 Y = Y || y;
144 var bb = this[1].getBBox(),
145 w = bb.width / 2,
146 h = bb.height / 2,
147 dx = [0, w + size * 2, 0, -w - size * 2],
148 dy = [-h * 2 - size * 3, -h - size, 0, -h - size],
149 p = ["M", X - dx[dir], Y - dy[dir], "l", -size, (dir == 2) * -size,
150 -mmax(w - size, 0), 0, "a", size, size, 0, 0, 1, -size, -size,
151 "l", 0, -mmax(h - size, 0), (dir == 3) * -size, -size, (dir == 3) * size, -size,
152 0, -mmax(h - size, 0), "a", size, size, 0, 0, 1, size, -size,
153 "l", mmax(w - size, 0), 0, size, !dir * -size, size, !dir * size, mmax(w - size, 0),
154 0, "a", size, size, 0, 0, 1, size, size,
155 "l", 0, mmax(h - size, 0), (dir == 1) * size, size, (dir == 1) * -size, size, 0,
156 mmax(h - size, 0), "a", size, size, 0, 0, 1, -size, size,
157 "l", -mmax(w - size, 0), 0, "z"].join(","),
158 xy = [{x: X, y: Y + size * 2 + h},
159 {x: X - size * 2 - w, y: Y},
160 {x: X, y: Y - size * 2 - h},
161 {x: X + size * 2 + w, y: Y}]
162 [dir];
163 xy.path = p;
164 if (withAnimation) {
165 this.animate(xy, 500, ">");
166 } else {
167 this.attr(xy);
168 }
169 return this;
170 };
171 return res.update(x, y);
172 };
99 };
General Comments 0
You need to be logged in to leave comments. Login now