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