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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. /* Redmine - project management software
  2. Copyright (C) 2006-2020 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. var yForRow = function (index, commit) {
  23. var row = commit_table_rows.eq(index);
  24. switch (row.find("td:first").css("vertical-align")) {
  25. case "middle":
  26. return row.position().top + (row.height() / 2) - graph_y_offset;
  27. default:
  28. return row.position().top + - graph_y_offset + CIRCLE_INROW_OFFSET;
  29. }
  30. };
  31. revisionGraph.setSize(graph_right_side, graph_bottom);
  32. // init colors
  33. var colors = [];
  34. Raphael.getColor.reset();
  35. for (var k = 0; k <= graph_space; k++) {
  36. colors.push(Raphael.getColor());
  37. }
  38. var parent_commit;
  39. var x, y, parent_x, parent_y;
  40. var path, title;
  41. var revision_dot_overlay;
  42. $.each(commits, function(index, commit) {
  43. if (!commit.hasOwnProperty("space"))
  44. commit.space = 0;
  45. y = yForRow(max_rdmid - commit.rdmid);
  46. x = graph_x_offset + XSTEP / 2 + XSTEP * commit.space;
  47. revisionGraph.circle(x, y, 3)
  48. .attr({
  49. fill: colors[commit.space],
  50. stroke: 'none'
  51. }).toFront();
  52. // paths to parents
  53. $.each(commit.parent_scmids, function(index, parent_scmid) {
  54. parent_commit = commits_by_scmid[parent_scmid];
  55. if (parent_commit) {
  56. if (!parent_commit.hasOwnProperty("space"))
  57. parent_commit.space = 0;
  58. parent_y = yForRow(max_rdmid - parent_commit.rdmid);
  59. parent_x = graph_x_offset + XSTEP / 2 + XSTEP * parent_commit.space;
  60. if (parent_commit.space == commit.space) {
  61. // vertical path
  62. path = revisionGraph.path([
  63. 'M', x, y,
  64. 'V', parent_y]);
  65. } else {
  66. // path to a commit in a different branch (Bezier curve)
  67. path = revisionGraph.path([
  68. 'M', x, y,
  69. 'C', x, y, x, y + (parent_y - y) / 2, x + (parent_x - x) / 2, y + (parent_y - y) / 2,
  70. 'C', x + (parent_x - x) / 2, y + (parent_y - y) / 2, parent_x, parent_y-(parent_y-y)/2, parent_x, parent_y]);
  71. }
  72. } else {
  73. // vertical path ending at the bottom of the revisionGraph
  74. path = revisionGraph.path([
  75. 'M', x, y,
  76. 'V', graph_bottom]);
  77. }
  78. path.attr({stroke: colors[commit.space], "stroke-width": 1.5}).toBack();
  79. });
  80. revision_dot_overlay = revisionGraph.circle(x, y, 10);
  81. revision_dot_overlay
  82. .attr({
  83. fill: '#000',
  84. opacity: 0,
  85. cursor: 'pointer',
  86. href: commit.href
  87. });
  88. if(commit.refs != null && commit.refs.length > 0) {
  89. title = document.createElementNS(revisionGraph.canvas.namespaceURI, 'title');
  90. title.appendChild(document.createTextNode(commit.refs));
  91. revision_dot_overlay.node.appendChild(title);
  92. }
  93. top.push(revision_dot_overlay);
  94. });
  95. top.toFront();
  96. };