revision_graph.js
97 lines
| 3.8 KiB
| application/javascript
|
JavascriptLexer
|
r14029 | /* Redmine - project management software | ||
|
r14856 | Copyright (C) 2006-2016 Jean-Philippe Lang */ | ||
|
r14029 | |||
|
r8746 | var revisionGraph = null; | ||
|
r7605 | |||
|
r8746 | function drawRevisionGraph(holder, commits_hash, graph_space) { | ||
|
r8730 | var XSTEP = 20, | ||
CIRCLE_INROW_OFFSET = 10; | ||||
|
r9885 | var commits_by_scmid = commits_hash, | ||
commits = $.map(commits_by_scmid, function(val,i){return val;}); | ||||
|
r8730 | var max_rdmid = commits.length - 1; | ||
|
r9885 | 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 | ||
|
r9885 | var graph_x_offset = commit_table_rows.first().find('td').first().position().left - $(holder).position().left, | ||
graph_y_offset = $(holder).position().top, | ||||
|
r8747 | graph_right_side = graph_x_offset + (graph_space + 1) * XSTEP, | ||
|
r9885 | graph_bottom = commit_table_rows.last().position().top + commit_table_rows.last().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; | ||||
|
r9051 | var path, title; | ||
|
r9652 | var revision_dot_overlay; | ||
|
r9885 | $.each(commits, function(index, commit) { | ||
|
r10186 | if (!commit.hasOwnProperty("space")) | ||
commit.space = 0; | ||||
|
r9885 | y = commit_table_rows.eq(max_rdmid - commit.rdmid).position().top - graph_y_offset + CIRCLE_INROW_OFFSET; | ||
|
r8747 | x = graph_x_offset + XSTEP / 2 + XSTEP * commit.space; | ||
|
r9049 | revisionGraph.circle(x, y, 3) | ||
.attr({ | ||||
fill: colors[commit.space], | ||||
|
r11508 | stroke: 'none' | ||
|
r9049 | }).toFront(); | ||
|
r8653 | // paths to parents | ||
|
r9885 | $.each(commit.parent_scmids, function(index, parent_scmid) { | ||
parent_commit = commits_by_scmid[parent_scmid]; | ||||
|
r8653 | if (parent_commit) { | ||
|
r10186 | if (!parent_commit.hasOwnProperty("space")) | ||
parent_commit.space = 0; | ||||
|
r9885 | parent_y = commit_table_rows.eq(max_rdmid - parent_commit.rdmid).position().top - graph_y_offset + CIRCLE_INROW_OFFSET; | ||
|
r8747 | 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 | } | ||
|
r9049 | path.attr({stroke: colors[commit.space], "stroke-width": 1.5}).toBack(); | ||
|
r8653 | }); | ||
|
r9049 | revision_dot_overlay = revisionGraph.circle(x, y, 10); | ||
revision_dot_overlay | ||||
|
r8653 | .attr({ | ||
|
r10109 | fill: '#000', | ||
|
r8653 | opacity: 0, | ||
|
r9049 | 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); | ||||
|
r8653 | }); | ||
top.toFront(); | ||||
|
r7605 | }; | ||