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