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