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

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