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