2012-02-13 21:20:18 +01:00
|
|
|
var revisionGraph = null;
|
2011-11-03 12:36:12 +01:00
|
|
|
|
2012-02-13 21:20:18 +01:00
|
|
|
function drawRevisionGraph(holder, commits_hash, graph_space) {
|
2012-02-11 15:57:44 +01:00
|
|
|
var XSTEP = 20,
|
|
|
|
CIRCLE_INROW_OFFSET = 10;
|
2012-07-22 15:29:26 +02:00
|
|
|
var commits_by_scmid = commits_hash,
|
|
|
|
commits = $.map(commits_by_scmid, function(val,i){return val;});
|
2012-02-11 15:57:44 +01:00
|
|
|
var max_rdmid = commits.length - 1;
|
2012-07-22 15:29:26 +02:00
|
|
|
var commit_table_rows = $('table.changesets tr.changeset');
|
2012-02-04 15:02:31 +01:00
|
|
|
|
2012-02-13 21:20:18 +01:00
|
|
|
// create graph
|
|
|
|
if(revisionGraph != null)
|
|
|
|
revisionGraph.clear();
|
|
|
|
else
|
|
|
|
revisionGraph = Raphael(holder);
|
|
|
|
|
|
|
|
var top = revisionGraph.set();
|
2012-02-11 15:57:44 +01:00
|
|
|
// init dimensions
|
2012-07-22 15:29:26 +02:00
|
|
|
var graph_x_offset = commit_table_rows.first().find('td').first().position().left - $(holder).position().left,
|
|
|
|
graph_y_offset = $(holder).position().top,
|
2012-02-14 07:22:23 +01:00
|
|
|
graph_right_side = graph_x_offset + (graph_space + 1) * XSTEP,
|
2012-07-22 15:29:26 +02:00
|
|
|
graph_bottom = commit_table_rows.last().position().top + commit_table_rows.last().height() - graph_y_offset;
|
2012-02-04 15:02:31 +01:00
|
|
|
|
2012-02-14 07:22:23 +01:00
|
|
|
revisionGraph.setSize(graph_right_side, graph_bottom);
|
2012-02-04 15:02:31 +01:00
|
|
|
|
|
|
|
// init colors
|
2012-02-11 15:57:44 +01:00
|
|
|
var colors = [];
|
2012-02-13 21:20:18 +01:00
|
|
|
Raphael.getColor.reset();
|
|
|
|
for (var k = 0; k <= graph_space; k++) {
|
2012-02-04 15:02:31 +01:00
|
|
|
colors.push(Raphael.getColor());
|
2011-11-03 12:36:12 +01:00
|
|
|
}
|
2012-02-04 15:02:31 +01:00
|
|
|
|
|
|
|
var parent_commit;
|
|
|
|
var x, y, parent_x, parent_y;
|
2012-03-10 14:44:04 +01:00
|
|
|
var path, title;
|
2012-06-14 23:12:03 +02:00
|
|
|
var revision_dot_overlay;
|
2012-07-22 15:29:26 +02:00
|
|
|
$.each(commits, function(index, commit) {
|
2012-09-11 18:55:32 +02:00
|
|
|
if (!commit.hasOwnProperty("space"))
|
|
|
|
commit.space = 0;
|
|
|
|
|
2012-07-22 15:29:26 +02:00
|
|
|
y = commit_table_rows.eq(max_rdmid - commit.rdmid).position().top - graph_y_offset + CIRCLE_INROW_OFFSET;
|
2012-02-14 07:22:23 +01:00
|
|
|
x = graph_x_offset + XSTEP / 2 + XSTEP * commit.space;
|
2012-03-10 14:41:09 +01:00
|
|
|
revisionGraph.circle(x, y, 3)
|
|
|
|
.attr({
|
|
|
|
fill: colors[commit.space],
|
2013-04-21 11:00:27 +02:00
|
|
|
stroke: 'none'
|
2012-03-10 14:41:09 +01:00
|
|
|
}).toFront();
|
2012-02-04 15:02:31 +01:00
|
|
|
// paths to parents
|
2012-07-22 15:29:26 +02:00
|
|
|
$.each(commit.parent_scmids, function(index, parent_scmid) {
|
|
|
|
parent_commit = commits_by_scmid[parent_scmid];
|
2012-02-04 15:02:31 +01:00
|
|
|
if (parent_commit) {
|
2012-09-11 18:55:32 +02:00
|
|
|
if (!parent_commit.hasOwnProperty("space"))
|
|
|
|
parent_commit.space = 0;
|
|
|
|
|
2012-07-22 15:29:26 +02:00
|
|
|
parent_y = commit_table_rows.eq(max_rdmid - parent_commit.rdmid).position().top - graph_y_offset + CIRCLE_INROW_OFFSET;
|
2012-02-14 07:22:23 +01:00
|
|
|
parent_x = graph_x_offset + XSTEP / 2 + XSTEP * parent_commit.space;
|
2012-02-04 15:02:31 +01:00
|
|
|
if (parent_commit.space == commit.space) {
|
|
|
|
// vertical path
|
2012-02-13 21:20:18 +01:00
|
|
|
path = revisionGraph.path([
|
2012-02-04 15:02:31 +01:00
|
|
|
'M', x, y,
|
|
|
|
'V', parent_y]);
|
2011-11-03 12:36:12 +01:00
|
|
|
} else {
|
2012-02-04 15:02:31 +01:00
|
|
|
// path to a commit in a different branch (Bezier curve)
|
2012-02-13 21:20:18 +01:00
|
|
|
path = revisionGraph.path([
|
2012-02-04 15:02:31 +01:00
|
|
|
'M', x, y,
|
|
|
|
'C', x, y, x, y + (parent_y - y) / 2, x + (parent_x - x) / 2, y + (parent_y - y) / 2,
|
|
|
|
'C', x + (parent_x - x) / 2, y + (parent_y - y) / 2, parent_x, parent_y-(parent_y-y)/2, parent_x, parent_y]);
|
2011-11-03 12:36:12 +01:00
|
|
|
}
|
|
|
|
} else {
|
2012-02-13 21:20:18 +01:00
|
|
|
// vertical path ending at the bottom of the revisionGraph
|
|
|
|
path = revisionGraph.path([
|
2012-02-04 15:02:31 +01:00
|
|
|
'M', x, y,
|
2012-02-14 07:22:23 +01:00
|
|
|
'V', graph_bottom]);
|
2011-11-03 12:36:12 +01:00
|
|
|
}
|
2012-03-10 14:41:09 +01:00
|
|
|
path.attr({stroke: colors[commit.space], "stroke-width": 1.5}).toBack();
|
2012-02-04 15:02:31 +01:00
|
|
|
});
|
2012-03-10 14:41:09 +01:00
|
|
|
revision_dot_overlay = revisionGraph.circle(x, y, 10);
|
|
|
|
revision_dot_overlay
|
2012-02-04 15:02:31 +01:00
|
|
|
.attr({
|
2012-09-06 08:46:13 +02:00
|
|
|
fill: '#000',
|
2012-02-04 15:02:31 +01:00
|
|
|
opacity: 0,
|
2012-03-10 14:41:09 +01:00
|
|
|
cursor: 'pointer',
|
|
|
|
href: commit.href
|
|
|
|
});
|
|
|
|
|
|
|
|
if(commit.refs != null && commit.refs.length > 0) {
|
|
|
|
title = document.createElementNS(revisionGraph.canvas.namespaceURI, 'title');
|
|
|
|
title.appendChild(document.createTextNode(commit.refs));
|
|
|
|
revision_dot_overlay.node.appendChild(title);
|
|
|
|
}
|
|
|
|
top.push(revision_dot_overlay);
|
2012-02-04 15:02:31 +01:00
|
|
|
});
|
|
|
|
top.toFront();
|
2011-11-03 12:36:12 +01:00
|
|
|
};
|