##// END OF EJS Templates
Revision Graph and Table should work with vertical-align: middle (#22278)....
Jean-Philippe Lang -
r14917:0ef6c949d1b6
parent child
Show More
@@ -1,97 +1,109
1 /* Redmine - project management software
1 /* Redmine - project management software
2 Copyright (C) 2006-2016 Jean-Philippe Lang */
2 Copyright (C) 2006-2016 Jean-Philippe Lang */
3
3
4 var revisionGraph = null;
4 var revisionGraph = null;
5
5
6 function drawRevisionGraph(holder, commits_hash, graph_space) {
6 function drawRevisionGraph(holder, commits_hash, graph_space) {
7 var XSTEP = 20,
7 var XSTEP = 20,
8 CIRCLE_INROW_OFFSET = 10;
8 CIRCLE_INROW_OFFSET = 10;
9 var commits_by_scmid = commits_hash,
9 var commits_by_scmid = commits_hash,
10 commits = $.map(commits_by_scmid, function(val,i){return val;});
10 commits = $.map(commits_by_scmid, function(val,i){return val;});
11 var max_rdmid = commits.length - 1;
11 var max_rdmid = commits.length - 1;
12 var commit_table_rows = $('table.changesets tr.changeset');
12 var commit_table_rows = $('table.changesets tr.changeset');
13
13
14 // create graph
14 // create graph
15 if(revisionGraph != null)
15 if(revisionGraph != null)
16 revisionGraph.clear();
16 revisionGraph.clear();
17 else
17 else
18 revisionGraph = Raphael(holder);
18 revisionGraph = Raphael(holder);
19
19
20 var top = revisionGraph.set();
20 var top = revisionGraph.set();
21 // init dimensions
21 // init dimensions
22 var graph_x_offset = commit_table_rows.first().find('td').first().position().left - $(holder).position().left,
22 var graph_x_offset = commit_table_rows.first().find('td').first().position().left - $(holder).position().left,
23 graph_y_offset = $(holder).position().top,
23 graph_y_offset = $(holder).position().top,
24 graph_right_side = graph_x_offset + (graph_space + 1) * XSTEP,
24 graph_right_side = graph_x_offset + (graph_space + 1) * XSTEP,
25 graph_bottom = commit_table_rows.last().position().top + commit_table_rows.last().height() - graph_y_offset;
25 graph_bottom = commit_table_rows.last().position().top + commit_table_rows.last().height() - graph_y_offset;
26
26
27
28 var yForRow = function (index, commit) {
29 var row = commit_table_rows.eq(index);
30
31 switch (row.find("td:first").css("vertical-align")) {
32 case "middle":
33 return row.position().top + (row.height() / 2) - graph_y_offset;
34 default:
35 return row.position().top + - graph_y_offset + CIRCLE_INROW_OFFSET;
36 }
37 };
38
27 revisionGraph.setSize(graph_right_side, graph_bottom);
39 revisionGraph.setSize(graph_right_side, graph_bottom);
28
40
29 // init colors
41 // init colors
30 var colors = [];
42 var colors = [];
31 Raphael.getColor.reset();
43 Raphael.getColor.reset();
32 for (var k = 0; k <= graph_space; k++) {
44 for (var k = 0; k <= graph_space; k++) {
33 colors.push(Raphael.getColor());
45 colors.push(Raphael.getColor());
34 }
46 }
35
47
36 var parent_commit;
48 var parent_commit;
37 var x, y, parent_x, parent_y;
49 var x, y, parent_x, parent_y;
38 var path, title;
50 var path, title;
39 var revision_dot_overlay;
51 var revision_dot_overlay;
40 $.each(commits, function(index, commit) {
52 $.each(commits, function(index, commit) {
41 if (!commit.hasOwnProperty("space"))
53 if (!commit.hasOwnProperty("space"))
42 commit.space = 0;
54 commit.space = 0;
43
55
44 y = commit_table_rows.eq(max_rdmid - commit.rdmid).position().top - graph_y_offset + CIRCLE_INROW_OFFSET;
56 y = yForRow(max_rdmid - commit.rdmid);
45 x = graph_x_offset + XSTEP / 2 + XSTEP * commit.space;
57 x = graph_x_offset + XSTEP / 2 + XSTEP * commit.space;
46 revisionGraph.circle(x, y, 3)
58 revisionGraph.circle(x, y, 3)
47 .attr({
59 .attr({
48 fill: colors[commit.space],
60 fill: colors[commit.space],
49 stroke: 'none'
61 stroke: 'none'
50 }).toFront();
62 }).toFront();
51 // paths to parents
63 // paths to parents
52 $.each(commit.parent_scmids, function(index, parent_scmid) {
64 $.each(commit.parent_scmids, function(index, parent_scmid) {
53 parent_commit = commits_by_scmid[parent_scmid];
65 parent_commit = commits_by_scmid[parent_scmid];
54 if (parent_commit) {
66 if (parent_commit) {
55 if (!parent_commit.hasOwnProperty("space"))
67 if (!parent_commit.hasOwnProperty("space"))
56 parent_commit.space = 0;
68 parent_commit.space = 0;
57
69
58 parent_y = commit_table_rows.eq(max_rdmid - parent_commit.rdmid).position().top - graph_y_offset + CIRCLE_INROW_OFFSET;
70 parent_y = yForRow(max_rdmid - parent_commit.rdmid);
59 parent_x = graph_x_offset + XSTEP / 2 + XSTEP * parent_commit.space;
71 parent_x = graph_x_offset + XSTEP / 2 + XSTEP * parent_commit.space;
60 if (parent_commit.space == commit.space) {
72 if (parent_commit.space == commit.space) {
61 // vertical path
73 // vertical path
62 path = revisionGraph.path([
74 path = revisionGraph.path([
63 'M', x, y,
75 'M', x, y,
64 'V', parent_y]);
76 'V', parent_y]);
65 } else {
77 } else {
66 // path to a commit in a different branch (Bezier curve)
78 // path to a commit in a different branch (Bezier curve)
67 path = revisionGraph.path([
79 path = revisionGraph.path([
68 'M', x, y,
80 'M', x, y,
69 'C', x, y, x, y + (parent_y - y) / 2, x + (parent_x - x) / 2, y + (parent_y - y) / 2,
81 'C', x, y, x, y + (parent_y - y) / 2, x + (parent_x - x) / 2, y + (parent_y - y) / 2,
70 'C', x + (parent_x - x) / 2, y + (parent_y - y) / 2, parent_x, parent_y-(parent_y-y)/2, parent_x, parent_y]);
82 'C', x + (parent_x - x) / 2, y + (parent_y - y) / 2, parent_x, parent_y-(parent_y-y)/2, parent_x, parent_y]);
71 }
83 }
72 } else {
84 } else {
73 // vertical path ending at the bottom of the revisionGraph
85 // vertical path ending at the bottom of the revisionGraph
74 path = revisionGraph.path([
86 path = revisionGraph.path([
75 'M', x, y,
87 'M', x, y,
76 'V', graph_bottom]);
88 'V', graph_bottom]);
77 }
89 }
78 path.attr({stroke: colors[commit.space], "stroke-width": 1.5}).toBack();
90 path.attr({stroke: colors[commit.space], "stroke-width": 1.5}).toBack();
79 });
91 });
80 revision_dot_overlay = revisionGraph.circle(x, y, 10);
92 revision_dot_overlay = revisionGraph.circle(x, y, 10);
81 revision_dot_overlay
93 revision_dot_overlay
82 .attr({
94 .attr({
83 fill: '#000',
95 fill: '#000',
84 opacity: 0,
96 opacity: 0,
85 cursor: 'pointer',
97 cursor: 'pointer',
86 href: commit.href
98 href: commit.href
87 });
99 });
88
100
89 if(commit.refs != null && commit.refs.length > 0) {
101 if(commit.refs != null && commit.refs.length > 0) {
90 title = document.createElementNS(revisionGraph.canvas.namespaceURI, 'title');
102 title = document.createElementNS(revisionGraph.canvas.namespaceURI, 'title');
91 title.appendChild(document.createTextNode(commit.refs));
103 title.appendChild(document.createTextNode(commit.refs));
92 revision_dot_overlay.node.appendChild(title);
104 revision_dot_overlay.node.appendChild(title);
93 }
105 }
94 top.push(revision_dot_overlay);
106 top.push(revision_dot_overlay);
95 });
107 });
96 top.toFront();
108 top.toFront();
97 };
109 };
General Comments 0
You need to be logged in to leave comments. Login now