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