revision_graph.js
105 lines
| 3.8 KiB
| application/javascript
|
JavascriptLexer
|
r8746 | var revisionGraph = null; | ||
|
r7605 | |||
|
r8746 | function drawRevisionGraph(holder, commits_hash, graph_space) { | ||
|
r8653 | |||
|
r8730 | var XSTEP = 20, | ||
CIRCLE_INROW_OFFSET = 10; | ||||
|
r8653 | |||
var commits_by_scmid = $H(commits_hash), | ||||
commits = commits_by_scmid.values(); | ||||
|
r8730 | var max_rdmid = commits.length - 1; | ||
var commit_table_rows = $$('table.changesets tr.changeset'); | ||||
|
r8653 | |||
|
r8746 | // create graph | ||
if(revisionGraph != null) | ||||
revisionGraph.clear(); | ||||
else | ||||
revisionGraph = Raphael(holder); | ||||
var top = revisionGraph.set(); | ||||
|
r8730 | // init dimensions | ||
|
r8747 | var graph_x_offset = Element.select(commit_table_rows.first(),'td').first().getLayout().get('left') - $(holder).getLayout().get('left'), | ||
graph_y_offset = $(holder).getLayout().get('top'), | ||||
graph_right_side = graph_x_offset + (graph_space + 1) * XSTEP, | ||||
graph_bottom = commit_table_rows.last().getLayout().get('top') + commit_table_rows.last().getLayout().get('height') - graph_y_offset; | ||||
|
r8653 | |||
|
r8747 | revisionGraph.setSize(graph_right_side, graph_bottom); | ||
|
r8653 | |||
// init colors | ||||
|
r8730 | var colors = []; | ||
|
r8746 | Raphael.getColor.reset(); | ||
for (var k = 0; k <= graph_space; k++) { | ||||
|
r8653 | colors.push(Raphael.getColor()); | ||
|
r7605 | } | ||
|
r8653 | |||
var parent_commit; | ||||
var x, y, parent_x, parent_y; | ||||
var path, longrefs, shortrefs, label, labelBBox; | ||||
commits.each(function(commit) { | ||||
|
r8747 | y = commit_table_rows[max_rdmid - commit.rdmid].getLayout().get('top') - graph_y_offset + CIRCLE_INROW_OFFSET; | ||
x = graph_x_offset + XSTEP / 2 + XSTEP * commit.space; | ||||
|
r8653 | |||
|
r8746 | revisionGraph.circle(x, y, 3).attr({fill: colors[commit.space], stroke: 'none'}); | ||
|
r8653 | |||
// title | ||||
if (commit.refs != null && commit.refs != '') { | ||||
longrefs = commit.refs; | ||||
shortrefs = longrefs.length > 15 ? longrefs.substr(0, 13) + '...' : longrefs; | ||||
|
r8746 | label = revisionGraph.text(x + 5, y + 5, shortrefs) | ||
|
r8653 | .attr({ | ||
font: '12px Fontin-Sans, Arial', | ||||
fill: '#666', | ||||
title: longrefs, | ||||
cursor: 'pointer', | ||||
rotation: '0'}); | ||||
labelBBox = label.getBBox(); | ||||
label.translate(labelBBox.width / 2, -labelBBox.height / 3); | ||||
} | ||||
// paths to parents | ||||
commit.parent_scmids.each(function(parent_scmid) { | ||||
parent_commit = commits_by_scmid.get(parent_scmid); | ||||
if (parent_commit) { | ||||
|
r8747 | parent_y = commit_table_rows[max_rdmid - parent_commit.rdmid].getLayout().get('top') - graph_y_offset + CIRCLE_INROW_OFFSET; | ||
parent_x = graph_x_offset + XSTEP / 2 + XSTEP * parent_commit.space; | ||||
|
r8653 | |||
if (parent_commit.space == commit.space) { | ||||
// vertical path | ||||
|
r8746 | path = revisionGraph.path([ | ||
|
r8653 | 'M', x, y, | ||
'V', parent_y]); | ||||
|
r7605 | } else { | ||
|
r8653 | // path to a commit in a different branch (Bezier curve) | ||
|
r8746 | path = revisionGraph.path([ | ||
|
r8653 | '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]); | ||||
|
r7605 | } | ||
} else { | ||||
|
r8746 | // vertical path ending at the bottom of the revisionGraph | ||
path = revisionGraph.path([ | ||||
|
r8653 | 'M', x, y, | ||
|
r8747 | 'V', graph_bottom]); | ||
|
r7605 | } | ||
|
r8653 | path.attr({stroke: colors[commit.space], "stroke-width": 1.5}); | ||
}); | ||||
|
r7605 | |||
|
r8746 | top.push(revisionGraph.circle(x, y, 10) | ||
|
r8653 | .attr({ | ||
fill: '#000', | ||||
opacity: 0, | ||||
cursor: 'pointer', | ||||
href: commit.href}) | ||||
.hover(function () {}, function () {})); | ||||
}); | ||||
|
r7605 | |||
|
r8653 | top.toFront(); | ||
|
r7605 | }; | ||