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