@@ -256,59 +256,64 module RepositoriesHelper | |||
|
256 | 256 | '<br />'.html_safe + l(:text_scm_path_encoding_note)) |
|
257 | 257 | end |
|
258 | 258 | |
|
259 |
def index_commits(commits, heads |
|
|
259 | def index_commits(commits, heads) | |
|
260 | 260 | return nil if commits.nil? or commits.first.parents.nil? |
|
261 | map = {} | |
|
262 | commit_hashes = [] | |
|
261 | ||
|
263 | 262 | refs_map = {} |
|
264 | href_proc ||= Proc.new {|x|x} | |
|
265 | heads.each{|r| refs_map[r.scmid] ||= []; refs_map[r.scmid] << r} | |
|
266 | commits.reverse.each_with_index do |c, i| | |
|
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 |
|
|
|
275 | h[:href] = href_proc.call(c.scmid) | |
|
276 | commit_hashes << h | |
|
277 | map[c.scmid] = h | |
|
278 | end | |
|
279 | heads.sort! do |a,b| | |
|
280 | a.to_s <=> b.to_s | |
|
281 | end | |
|
282 | j = 0 | |
|
283 | heads.each do |h| | |
|
284 | if map.include? h.scmid then | |
|
285 | j = mark_chain(j += 1, map[h.scmid], map) | |
|
263 | heads.each do |head| | |
|
264 | refs_map[head.scmid] ||= [] | |
|
265 | refs_map[head.scmid] << head | |
|
266 | end | |
|
267 | ||
|
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 | } | |
|
279 | end | |
|
280 | ||
|
281 | heads.sort! { |head1, head2| head1.to_s <=> head2.to_s } | |
|
282 | ||
|
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 | 287 | end |
|
287 | 288 | end |
|
288 | 289 | # when no head matched anything use first commit |
|
289 |
if |
|
|
290 |
mark_chain( |
|
|
290 | if mark_index == 0 | |
|
291 | mark_chain(mark_index += 1, commits_by_scmid.values.first, commits_by_scmid) | |
|
291 | 292 | end |
|
292 | map | |
|
293 | commits_by_scmid | |
|
293 | 294 | end |
|
294 | 295 | |
|
295 |
def mark_chain(mark, commit, |
|
|
296 | stack = [[mark, commit]] | |
|
297 | markmax = mark | |
|
296 | def mark_chain(mark_index, commit, commits_by_scmid) | |
|
297 | ||
|
298 | stack = [[mark_index, commit]] | |
|
299 | mark_max_index = mark_index | |
|
300 | ||
|
298 | 301 | until stack.empty? |
|
299 |
|
|
|
300 | m, commit = current | |
|
301 | commit[:space] = m if commit[:space] == 0 | |
|
302 | m1 = m - 1 | |
|
303 | commit[:parents].each_with_index do |p, i| | |
|
304 | psha = p[0] | |
|
305 | if map.include? psha and map[psha][:space] == 0 then | |
|
306 | stack << [m1 += 1, map[psha]] if i == 0 | |
|
307 | stack = [[m1 += 1, map[psha]]] + stack if i > 0 | |
|
302 | mark_index, commit = stack.pop | |
|
303 | commit[:space] = mark_index if commit[:space] == 0 | |
|
304 | ||
|
305 | mark_index -=1 | |
|
306 | commit[:parent_scmids].each_with_index do |parent_scmid, parent_index| | |
|
307 | ||
|
308 | parent_commit = commits_by_scmid[parent_scmid] | |
|
309 | ||
|
310 | if parent_commit and parent_commit[:space] == 0 | |
|
311 | ||
|
312 | stack.unshift [mark_index += 1, parent_commit] | |
|
308 | 313 | end |
|
309 | 314 | end |
|
310 |
markmax = m |
|
|
315 | mark_max_index = mark_index if mark_max_index < mark_index | |
|
311 | 316 | end |
|
312 | markmax | |
|
317 | mark_max_index | |
|
313 | 318 | end |
|
314 | 319 | end |
@@ -1,13 +1,12 | |||
|
1 |
<%= javascript_include_tag |
|
|
2 | <script type="text/javascript" charset="utf-8"> | |
|
3 | var chunk = {commits:<%= commits.values.to_json.html_safe %>} | |
|
4 | </script> | |
|
5 | <%= javascript_include_tag "revision_graph.js" %> | |
|
1 | <%= javascript_include_tag 'raphael.js' %> | |
|
2 | <%= javascript_include_tag 'revision_graph.js' %> | |
|
6 | 3 | |
|
7 | <script type="text/javascript"> | |
|
8 |
Event.observe(window, |
|
|
9 | branchGraph(document.getElementById("holder")); | |
|
10 | }) | |
|
4 | <script type="text/javascript" charset="utf-8"> | |
|
5 | Event.observe(window, 'load', function(){ | |
|
6 | branchGraph( | |
|
7 | document.getElementById("holder"), | |
|
8 | <%= commits.to_json.html_safe %>); | |
|
9 | }); | |
|
11 | 10 | </script> |
|
12 | 11 | |
|
13 | 12 | <div id="holder" class="graph"></div> |
@@ -24,18 +24,18 | |||
|
24 | 24 | <% if show_revision_graph %> |
|
25 | 25 | <% if line_num == 1 %> |
|
26 | 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 | 27 | <%= render :partial => 'revision_graph', |
|
33 | 28 | :locals => { |
|
34 | 29 | :commits => index_commits( |
|
35 | 30 |
|
|
36 |
|
|
|
37 |
|
|
|
38 |
|
|
|
31 | @repository.branches) do |scmid| | |
|
32 | url_for( | |
|
33 | :controller => 'repositories', | |
|
34 | :action => 'revision', | |
|
35 | :id => project, | |
|
36 | :repository_id => @repository.identifier_param, | |
|
37 | :rev => scmid) | |
|
38 | end | |
|
39 | 39 | } %> |
|
40 | 40 | </td> |
|
41 | 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++) { | |
|
18 | if (commits[i].scmid in parents) { | |
|
19 | commits[i].isParent = true; | |
|
20 | } | |
|
21 | comms[commits[i].scmid] = commits[i]; | |
|
22 | } | |
|
23 | var colors = ["#000"]; | |
|
2 | function branchGraph(holder, commits_hash) { | |
|
3 | ||
|
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 | 24 | for (var k = 0; k < max_space; k++) { |
|
25 | 25 | colors.push(Raphael.getColor()); |
|
26 | 26 | } |
|
27 | 27 | |
|
28 | function branchGraph(holder) { | |
|
29 | var xstep = 20, ystep = 20; | |
|
30 | var ch, cw; | |
|
31 | cw = max_space * xstep + xstep; | |
|
32 | ch = max_rdmid * ystep + ystep; | |
|
33 | var r = Raphael("holder", cw, ch), | |
|
34 | top = r.set(); | |
|
35 | var cuday = 0, cumonth = ""; | |
|
36 | ||
|
37 | for (i = 0; i < ii; i++) { | |
|
38 | var x, y; | |
|
39 | y = 10 + ystep *(max_rdmid - commits[i].rdmid); | |
|
40 | x = 3 + xstep * commits[i].space; | |
|
41 | var stroke = "none"; | |
|
42 | r.circle(x, y, 3).attr({fill: colors[commits[i].space], stroke: stroke}); | |
|
43 | if (commits[i].refs != null && commits[i].refs != "") { | |
|
44 | var longrefs = commits[i].refs | |
|
45 |
|
|
|
46 | if (shortrefs.length > 15) { | |
|
47 | shortrefs = shortrefs.substr(0,13) + "..."; | |
|
48 | } | |
|
49 | var t = r.text(x+5,y+5,shortrefs).attr({font: "12px Fontin-Sans, Arial", fill: "#666", | |
|
50 | title: longrefs, cursor: "pointer", rotation: "0"}); | |
|
28 | // create graph | |
|
29 | var graph = Raphael(holder, graph_width, graph_height), | |
|
30 | top = graph.set(); | |
|
31 | ||
|
32 | var parent_commit; | |
|
33 | var x, y, parent_x, parent_y; | |
|
34 | var path, longrefs, shortrefs, label, labelBBox; | |
|
35 | ||
|
36 | commits.each(function(commit) { | |
|
37 | ||
|
38 | y = TOP_PADDING + YSTEP *(max_rdmid - commit.rdmid); | |
|
39 | x = LEFT_PADDING + XSTEP * commit.space; | |
|
40 | ||
|
41 | graph.circle(x, y, 3).attr({fill: colors[commit.space], stroke: 'none'}); | |
|
42 | ||
|
43 | // title | |
|
44 | if (commit.refs != null && commit.refs != '') { | |
|
45 | longrefs = commit.refs; | |
|
46 | shortrefs = longrefs.length > 15 ? longrefs.substr(0, 13) + '...' : longrefs; | |
|
47 | ||
|
48 | label = graph.text(x + 5, y + 5, shortrefs) | |
|
49 | .attr({ | |
|
50 | font: '12px Fontin-Sans, Arial', | |
|
51 | fill: '#666', | |
|
52 | title: longrefs, | |
|
53 | cursor: 'pointer', | |
|
54 | rotation: '0'}); | |
|
51 | 55 | |
|
52 |
|
|
|
53 |
|
|
|
56 | labelBBox = label.getBBox(); | |
|
57 | label.translate(labelBBox.width / 2, -labelBBox.height / 3); | |
|
54 | 58 |
|
|
55 | for (var j = 0, jj = commits[i].parents.length; j < jj; j++) { | |
|
56 | var c = comms[commits[i].parents[j][0]]; | |
|
57 | var p,arrow; | |
|
58 | if (c) { | |
|
59 | var cy, cx; | |
|
60 | cy = 10 + ystep * (max_rdmid - c.rdmid), | |
|
61 | cx = 3 + xstep * c.space; | |
|
62 | ||
|
63 | if (c.space == commits[i].space) { | |
|
64 | p = r.path("M" + x + "," + y + "L" + cx + "," + cy); | |
|
59 | ||
|
60 | // paths to parents | |
|
61 | commit.parent_scmids.each(function(parent_scmid) { | |
|
62 | parent_commit = commits_by_scmid.get(parent_scmid); | |
|
63 | ||
|
64 | if (parent_commit) { | |
|
65 | parent_y = TOP_PADDING + YSTEP * (max_rdmid - parent_commit.rdmid); | |
|
66 | parent_x = LEFT_PADDING + XSTEP * parent_commit.space; | |
|
67 | ||
|
68 | if (parent_commit.space == commit.space) { | |
|
69 | // vertical path | |
|
70 | path = graph.path([ | |
|
71 | 'M', x, y, | |
|
72 | 'V', parent_y]); | |
|
65 | 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, | |
|
67 | "C", x+(cx-x)/2,y+(cy-y)/2, cx, cy-(cy-y)/2, cx, cy]); | |
|
74 | // path to a commit in a different branch (Bezier curve) | |
|
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 | 80 | } else { |
|
70 | p = r.path("M" + x + "," + y + "L" + x + "," + ch); | |
|
71 | } | |
|
72 | p.attr({stroke: colors[commits[i].space], "stroke-width": 1.5}); | |
|
81 | // vertical path ending at the bottom of the graph | |
|
82 | path = graph.path([ | |
|
83 | 'M', x, y, | |
|
84 | 'V', graph_height]); | |
|
73 | 85 | } |
|
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 | } | |
|
91 | }; | |
|
92 | holder.onmousedown = function (e) { | |
|
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 | }; | |
|
86 | path.attr({stroke: colors[commit.space], "stroke-width": 1.5}); | |
|
87 | }); | |
|
103 | 88 | |
|
104 | Raphael.fn.popupit = function (x, y, set, dir, size) { | |
|
105 | dir = dir == null ? 2 : dir; | |
|
106 | size = size || 5; | |
|
107 | x = Math.round(x); | |
|
108 | y = Math.round(y); | |
|
109 | var bb = set.getBBox(), | |
|
110 | w = Math.round(bb.width / 2), | |
|
111 | h = Math.round(bb.height / 2), | |
|
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 | }; | |
|
89 | top.push(graph.circle(x, y, 10) | |
|
90 | .attr({ | |
|
91 | fill: '#000', | |
|
92 | opacity: 0, | |
|
93 | cursor: 'pointer', | |
|
94 | href: commit.href}) | |
|
95 | .hover(function () {}, function () {})); | |
|
96 | }); | |
|
132 | 97 | |
|
133 | Raphael.fn.popup = function (x, y, text, dir, size) { | |
|
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); | |
|
98 | top.toFront(); | |
|
172 | 99 | }; |
General Comments 0
You need to be logged in to leave comments.
Login now