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