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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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 = $H(commits_hash),
  6. commits = commits_by_scmid.values();
  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 = Element.select(commit_table_rows.first(),'td').first().getLayout().get('left') - $(holder).getLayout().get('left'),
  17. graph_y_offset = $(holder).getLayout().get('top'),
  18. graph_right_side = graph_x_offset + (graph_space + 1) * XSTEP,
  19. graph_bottom = commit_table_rows.last().getLayout().get('top') + commit_table_rows.last().getLayout().get('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. commits.each(function(commit) {
  31. y = commit_table_rows[max_rdmid - commit.rdmid].getLayout().get('top') - graph_y_offset + CIRCLE_INROW_OFFSET;
  32. x = graph_x_offset + XSTEP / 2 + XSTEP * commit.space;
  33. revisionGraph.circle(x, y, 3)
  34. .attr({
  35. fill: colors[commit.space],
  36. stroke: 'none',
  37. }).toFront();
  38. // paths to parents
  39. commit.parent_scmids.each(function(parent_scmid) {
  40. parent_commit = commits_by_scmid.get(parent_scmid);
  41. if (parent_commit) {
  42. parent_y = commit_table_rows[max_rdmid - parent_commit.rdmid].getLayout().get('top') - graph_y_offset + CIRCLE_INROW_OFFSET;
  43. parent_x = graph_x_offset + XSTEP / 2 + XSTEP * parent_commit.space;
  44. if (parent_commit.space == commit.space) {
  45. // vertical path
  46. path = revisionGraph.path([
  47. 'M', x, y,
  48. 'V', parent_y]);
  49. } else {
  50. // path to a commit in a different branch (Bezier curve)
  51. path = revisionGraph.path([
  52. 'M', x, y,
  53. 'C', x, y, x, y + (parent_y - y) / 2, x + (parent_x - x) / 2, y + (parent_y - y) / 2,
  54. 'C', x + (parent_x - x) / 2, y + (parent_y - y) / 2, parent_x, parent_y-(parent_y-y)/2, parent_x, parent_y]);
  55. }
  56. } else {
  57. // vertical path ending at the bottom of the revisionGraph
  58. path = revisionGraph.path([
  59. 'M', x, y,
  60. 'V', graph_bottom]);
  61. }
  62. path.attr({stroke: colors[commit.space], "stroke-width": 1.5}).toBack();
  63. });
  64. revision_dot_overlay = revisionGraph.circle(x, y, 10);
  65. revision_dot_overlay
  66. .attr({
  67. fill: '#000',
  68. opacity: 0,
  69. cursor: 'pointer',
  70. href: commit.href
  71. });
  72. if(commit.refs != null && commit.refs.length > 0) {
  73. title = document.createElementNS(revisionGraph.canvas.namespaceURI, 'title');
  74. title.appendChild(document.createTextNode(commit.refs));
  75. revision_dot_overlay.node.appendChild(title);
  76. }
  77. top.push(revision_dot_overlay);
  78. });
  79. top.toFront();
  80. };