You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

revision_graph.js 3.8KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. /* Redmine - project management software
  2. Copyright (C) 2006-2015 Jean-Philippe Lang */
  3. var revisionGraph = null;
  4. function drawRevisionGraph(holder, commits_hash, graph_space) {
  5. var XSTEP = 20,
  6. CIRCLE_INROW_OFFSET = 10;
  7. var commits_by_scmid = commits_hash,
  8. commits = $.map(commits_by_scmid, function(val,i){return val;});
  9. var max_rdmid = commits.length - 1;
  10. var commit_table_rows = $('table.changesets tr.changeset');
  11. // create graph
  12. if(revisionGraph != null)
  13. revisionGraph.clear();
  14. else
  15. revisionGraph = Raphael(holder);
  16. var top = revisionGraph.set();
  17. // init dimensions
  18. var graph_x_offset = commit_table_rows.first().find('td').first().position().left - $(holder).position().left,
  19. graph_y_offset = $(holder).position().top,
  20. graph_right_side = graph_x_offset + (graph_space + 1) * XSTEP,
  21. graph_bottom = commit_table_rows.last().position().top + commit_table_rows.last().height() - graph_y_offset;
  22. revisionGraph.setSize(graph_right_side, graph_bottom);
  23. // init colors
  24. var colors = [];
  25. Raphael.getColor.reset();
  26. for (var k = 0; k <= graph_space; k++) {
  27. colors.push(Raphael.getColor());
  28. }
  29. var parent_commit;
  30. var x, y, parent_x, parent_y;
  31. var path, title;
  32. var revision_dot_overlay;
  33. $.each(commits, function(index, commit) {
  34. if (!commit.hasOwnProperty("space"))
  35. commit.space = 0;
  36. y = commit_table_rows.eq(max_rdmid - commit.rdmid).position().top - graph_y_offset + CIRCLE_INROW_OFFSET;
  37. x = graph_x_offset + XSTEP / 2 + XSTEP * commit.space;
  38. revisionGraph.circle(x, y, 3)
  39. .attr({
  40. fill: colors[commit.space],
  41. stroke: 'none'
  42. }).toFront();
  43. // paths to parents
  44. $.each(commit.parent_scmids, function(index, parent_scmid) {
  45. parent_commit = commits_by_scmid[parent_scmid];
  46. if (parent_commit) {
  47. if (!parent_commit.hasOwnProperty("space"))
  48. parent_commit.space = 0;
  49. parent_y = commit_table_rows.eq(max_rdmid - parent_commit.rdmid).position().top - graph_y_offset + CIRCLE_INROW_OFFSET;
  50. parent_x = graph_x_offset + XSTEP / 2 + XSTEP * parent_commit.space;
  51. if (parent_commit.space == commit.space) {
  52. // vertical path
  53. path = revisionGraph.path([
  54. 'M', x, y,
  55. 'V', parent_y]);
  56. } else {
  57. // path to a commit in a different branch (Bezier curve)
  58. path = revisionGraph.path([
  59. 'M', x, y,
  60. 'C', x, y, x, y + (parent_y - y) / 2, x + (parent_x - x) / 2, y + (parent_y - y) / 2,
  61. 'C', x + (parent_x - x) / 2, y + (parent_y - y) / 2, parent_x, parent_y-(parent_y-y)/2, parent_x, parent_y]);
  62. }
  63. } else {
  64. // vertical path ending at the bottom of the revisionGraph
  65. path = revisionGraph.path([
  66. 'M', x, y,
  67. 'V', graph_bottom]);
  68. }
  69. path.attr({stroke: colors[commit.space], "stroke-width": 1.5}).toBack();
  70. });
  71. revision_dot_overlay = revisionGraph.circle(x, y, 10);
  72. revision_dot_overlay
  73. .attr({
  74. fill: '#000',
  75. opacity: 0,
  76. cursor: 'pointer',
  77. href: commit.href
  78. });
  79. if(commit.refs != null && commit.refs.length > 0) {
  80. title = document.createElementNS(revisionGraph.canvas.namespaceURI, 'title');
  81. title.appendChild(document.createTextNode(commit.refs));
  82. revision_dot_overlay.node.appendChild(title);
  83. }
  84. top.push(revision_dot_overlay);
  85. });
  86. top.toFront();
  87. };