@@ -1,88 +1,94 | |||
|
1 | 1 | var revisionGraph = null; |
|
2 | 2 | |
|
3 | 3 | function drawRevisionGraph(holder, commits_hash, graph_space) { |
|
4 | 4 | var XSTEP = 20, |
|
5 | 5 | CIRCLE_INROW_OFFSET = 10; |
|
6 | 6 | var commits_by_scmid = commits_hash, |
|
7 | 7 | commits = $.map(commits_by_scmid, function(val,i){return val;}); |
|
8 | 8 | var max_rdmid = commits.length - 1; |
|
9 | 9 | var commit_table_rows = $('table.changesets tr.changeset'); |
|
10 | 10 | |
|
11 | 11 | // create graph |
|
12 | 12 | if(revisionGraph != null) |
|
13 | 13 | revisionGraph.clear(); |
|
14 | 14 | else |
|
15 | 15 | revisionGraph = Raphael(holder); |
|
16 | 16 | |
|
17 | 17 | var top = revisionGraph.set(); |
|
18 | 18 | // init dimensions |
|
19 | 19 | var graph_x_offset = commit_table_rows.first().find('td').first().position().left - $(holder).position().left, |
|
20 | 20 | graph_y_offset = $(holder).position().top, |
|
21 | 21 | graph_right_side = graph_x_offset + (graph_space + 1) * XSTEP, |
|
22 | 22 | graph_bottom = commit_table_rows.last().position().top + commit_table_rows.last().height() - graph_y_offset; |
|
23 | 23 | |
|
24 | 24 | revisionGraph.setSize(graph_right_side, graph_bottom); |
|
25 | 25 | |
|
26 | 26 | // init colors |
|
27 | 27 | var colors = []; |
|
28 | 28 | Raphael.getColor.reset(); |
|
29 | 29 | for (var k = 0; k <= graph_space; k++) { |
|
30 | 30 | colors.push(Raphael.getColor()); |
|
31 | 31 | } |
|
32 | 32 | |
|
33 | 33 | var parent_commit; |
|
34 | 34 | var x, y, parent_x, parent_y; |
|
35 | 35 | var path, title; |
|
36 | 36 | var revision_dot_overlay; |
|
37 | 37 | $.each(commits, function(index, commit) { |
|
38 | if (!commit.hasOwnProperty("space")) | |
|
39 | commit.space = 0; | |
|
40 | ||
|
38 | 41 | y = commit_table_rows.eq(max_rdmid - commit.rdmid).position().top - graph_y_offset + CIRCLE_INROW_OFFSET; |
|
39 | 42 | x = graph_x_offset + XSTEP / 2 + XSTEP * commit.space; |
|
40 | 43 | revisionGraph.circle(x, y, 3) |
|
41 | 44 | .attr({ |
|
42 | 45 | fill: colors[commit.space], |
|
43 | 46 | stroke: 'none', |
|
44 | 47 | }).toFront(); |
|
45 | 48 | // paths to parents |
|
46 | 49 | $.each(commit.parent_scmids, function(index, parent_scmid) { |
|
47 | 50 | parent_commit = commits_by_scmid[parent_scmid]; |
|
48 | 51 | if (parent_commit) { |
|
52 | if (!parent_commit.hasOwnProperty("space")) | |
|
53 | parent_commit.space = 0; | |
|
54 | ||
|
49 | 55 | parent_y = commit_table_rows.eq(max_rdmid - parent_commit.rdmid).position().top - graph_y_offset + CIRCLE_INROW_OFFSET; |
|
50 | 56 | parent_x = graph_x_offset + XSTEP / 2 + XSTEP * parent_commit.space; |
|
51 | 57 | if (parent_commit.space == commit.space) { |
|
52 | 58 | // vertical path |
|
53 | 59 | path = revisionGraph.path([ |
|
54 | 60 | 'M', x, y, |
|
55 | 61 | 'V', parent_y]); |
|
56 | 62 | } else { |
|
57 | 63 | // path to a commit in a different branch (Bezier curve) |
|
58 | 64 | path = revisionGraph.path([ |
|
59 | 65 | 'M', x, y, |
|
60 | 66 | 'C', x, y, x, y + (parent_y - y) / 2, x + (parent_x - x) / 2, y + (parent_y - y) / 2, |
|
61 | 67 | 'C', x + (parent_x - x) / 2, y + (parent_y - y) / 2, parent_x, parent_y-(parent_y-y)/2, parent_x, parent_y]); |
|
62 | 68 | } |
|
63 | 69 | } else { |
|
64 | 70 | // vertical path ending at the bottom of the revisionGraph |
|
65 | 71 | path = revisionGraph.path([ |
|
66 | 72 | 'M', x, y, |
|
67 | 73 | 'V', graph_bottom]); |
|
68 | 74 | } |
|
69 | 75 | path.attr({stroke: colors[commit.space], "stroke-width": 1.5}).toBack(); |
|
70 | 76 | }); |
|
71 | 77 | revision_dot_overlay = revisionGraph.circle(x, y, 10); |
|
72 | 78 | revision_dot_overlay |
|
73 | 79 | .attr({ |
|
74 | 80 | fill: '#000', |
|
75 | 81 | opacity: 0, |
|
76 | 82 | cursor: 'pointer', |
|
77 | 83 | href: commit.href |
|
78 | 84 | }); |
|
79 | 85 | |
|
80 | 86 | if(commit.refs != null && commit.refs.length > 0) { |
|
81 | 87 | title = document.createElementNS(revisionGraph.canvas.namespaceURI, 'title'); |
|
82 | 88 | title.appendChild(document.createTextNode(commit.refs)); |
|
83 | 89 | revision_dot_overlay.node.appendChild(title); |
|
84 | 90 | } |
|
85 | 91 | top.push(revision_dot_overlay); |
|
86 | 92 | }); |
|
87 | 93 | top.toFront(); |
|
88 | 94 | }; |
General Comments 0
You need to be logged in to leave comments.
Login now