@@ -2,11 +2,16 | |||
|
2 | 2 | <%= javascript_include_tag 'revision_graph.js' %> |
|
3 | 3 | |
|
4 | 4 | <script type="text/javascript" charset="utf-8"> |
|
5 | Event.observe(window, 'load', function(){ | |
|
6 | revisionGraph( | |
|
7 | document.getElementById('holder'), | |
|
8 | <%= commits.to_json.html_safe %>, | |
|
9 | <%= space %>); | |
|
5 | ||
|
6 | ['load', 'resize'].each(function(window_event) { | |
|
7 | ||
|
8 | Event.observe(window, window_event, function(){ | |
|
9 | ||
|
10 | drawRevisionGraph( | |
|
11 | document.getElementById('holder'), | |
|
12 | <%= commits.to_json.html_safe %>, | |
|
13 | <%= space %>); | |
|
14 | }); | |
|
10 | 15 | }); |
|
11 | 16 | </script> |
|
12 | 17 |
@@ -1,5 +1,6 | |||
|
1 | var revisionGraph = null; | |
|
1 | 2 |
|
|
2 | function revisionGraph(holder, commits_hash, graph_space) { | |
|
3 | function drawRevisionGraph(holder, commits_hash, graph_space) { | |
|
3 | 4 | |
|
4 | 5 | var XSTEP = 20, |
|
5 | 6 | CIRCLE_INROW_OFFSET = 10; |
@@ -11,22 +12,28 function revisionGraph(holder, commits_hash, graph_space) { | |||
|
11 | 12 | |
|
12 | 13 | var commit_table_rows = $$('table.changesets tr.changeset'); |
|
13 | 14 | |
|
15 | // create graph | |
|
16 | if(revisionGraph != null) | |
|
17 | revisionGraph.clear(); | |
|
18 | else | |
|
19 | revisionGraph = Raphael(holder); | |
|
20 | ||
|
21 | var top = revisionGraph.set(); | |
|
22 | ||
|
14 | 23 | // init dimensions |
|
15 | 24 | var graph_offset = $(holder).getLayout().get('top'), |
|
16 | 25 | graph_width = (graph_space + 1) * XSTEP, |
|
17 | 26 | graph_height = commit_table_rows[max_rdmid].getLayout().get('top') + commit_table_rows[max_rdmid].getLayout().get('height') - graph_offset; |
|
18 | 27 | |
|
28 | revisionGraph.setSize(graph_width, graph_height); | |
|
19 | 29 | |
|
20 | 30 | // init colors |
|
21 | 31 | var colors = []; |
|
22 | for (var k = 0; k < graph_space + 1; k++) { | |
|
32 | Raphael.getColor.reset(); | |
|
33 | for (var k = 0; k <= graph_space; k++) { | |
|
23 | 34 | colors.push(Raphael.getColor()); |
|
24 | 35 | } |
|
25 | 36 | |
|
26 | // create graph | |
|
27 | var graph = Raphael(holder, graph_width, graph_height), | |
|
28 | top = graph.set(); | |
|
29 | ||
|
30 | 37 | var parent_commit; |
|
31 | 38 | var x, y, parent_x, parent_y; |
|
32 | 39 | var path, longrefs, shortrefs, label, labelBBox; |
@@ -36,14 +43,14 function revisionGraph(holder, commits_hash, graph_space) { | |||
|
36 | 43 | y = commit_table_rows[max_rdmid - commit.rdmid].getLayout().get('top') - graph_offset + CIRCLE_INROW_OFFSET; |
|
37 | 44 | x = XSTEP / 2 + XSTEP * commit.space; |
|
38 | 45 | |
|
39 |
|
|
|
46 | revisionGraph.circle(x, y, 3).attr({fill: colors[commit.space], stroke: 'none'}); | |
|
40 | 47 | |
|
41 | 48 | // title |
|
42 | 49 | if (commit.refs != null && commit.refs != '') { |
|
43 | 50 | longrefs = commit.refs; |
|
44 | 51 | shortrefs = longrefs.length > 15 ? longrefs.substr(0, 13) + '...' : longrefs; |
|
45 | 52 | |
|
46 |
label = |
|
|
53 | label = revisionGraph.text(x + 5, y + 5, shortrefs) | |
|
47 | 54 | .attr({ |
|
48 | 55 | font: '12px Fontin-Sans, Arial', |
|
49 | 56 | fill: '#666', |
@@ -65,26 +72,26 function revisionGraph(holder, commits_hash, graph_space) { | |||
|
65 | 72 | |
|
66 | 73 | if (parent_commit.space == commit.space) { |
|
67 | 74 | // vertical path |
|
68 |
path = |
|
|
75 | path = revisionGraph.path([ | |
|
69 | 76 | 'M', x, y, |
|
70 | 77 | 'V', parent_y]); |
|
71 | 78 | } else { |
|
72 | 79 | // path to a commit in a different branch (Bezier curve) |
|
73 |
path = |
|
|
80 | path = revisionGraph.path([ | |
|
74 | 81 | 'M', x, y, |
|
75 | 82 | 'C', x, y, x, y + (parent_y - y) / 2, x + (parent_x - x) / 2, y + (parent_y - y) / 2, |
|
76 | 83 | 'C', x + (parent_x - x) / 2, y + (parent_y - y) / 2, parent_x, parent_y-(parent_y-y)/2, parent_x, parent_y]); |
|
77 | 84 | } |
|
78 | 85 | } else { |
|
79 |
// vertical path ending at the bottom of the |
|
|
80 |
path = |
|
|
86 | // vertical path ending at the bottom of the revisionGraph | |
|
87 | path = revisionGraph.path([ | |
|
81 | 88 | 'M', x, y, |
|
82 | 89 | 'V', graph_height]); |
|
83 | 90 | } |
|
84 | 91 | path.attr({stroke: colors[commit.space], "stroke-width": 1.5}); |
|
85 | 92 | }); |
|
86 | 93 | |
|
87 |
top.push( |
|
|
94 | top.push(revisionGraph.circle(x, y, 10) | |
|
88 | 95 | .attr({ |
|
89 | 96 | fill: '#000', |
|
90 | 97 | opacity: 0, |
General Comments 0
You need to be logged in to leave comments.
Login now