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