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.7KB

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