From e614711d91bc1e5c7f79430e03c563e0e9a8c126 Mon Sep 17 00:00:00 2001 From: murin Date: Tue, 20 May 2025 16:08:53 +0300 Subject: [PATCH 3/3] Change the shape of curves connecting commits across different branches in the revision graph The original curve design made it difficult to identify which commits were connected, when several commits existed between the connected ones on the branches. Now, connections between commits on different branches are more easily recognizable in typical scenarios. The new curves connect from the left or right side to commit that already have vertical connections, and from the top or bottom to the last or first commit on a branch, respectively. | | | | | * /-* * * *-\ | | | | | | | *-/ * *-/ * * | | | | | Related to #10954 --- app/assets/javascripts/revision_graph.js | 38 ++++++++++++++++++++---- app/helpers/repositories_helper.rb | 9 ++++++ 2 files changed, 41 insertions(+), 6 deletions(-) diff --git a/app/assets/javascripts/revision_graph.js b/app/assets/javascripts/revision_graph.js index faa872287..e54cf5750 100644 --- a/app/assets/javascripts/revision_graph.js +++ b/app/assets/javascripts/revision_graph.js @@ -63,26 +63,52 @@ function drawRevisionGraph(holder, commits_hash, graph_space) { fill: colors[commit.space], stroke: 'none' }).toFront(); - // paths to parents - $.each(commit.parent_scmids, function(index, parent_scmid) { - parent_commit = commits_by_scmid[parent_scmid]; + + // check for parents in the same column + let noVerticalParents = true; + $.each(commit.parent_scmids, function (index, parentScmid) { + parent_commit = commits_by_scmid[parentScmid]; if (parent_commit) { if (!parent_commit.hasOwnProperty("space")) parent_commit.space = 0; + // has parent in the same column on this page + if (parent_commit.space === commit.space) + noVerticalParents = false; + } else { + // has parent in the same column on the other page + noVerticalParents = false; + } + }); + + // paths to parents + $.each(commit.parent_scmids, function(index, parent_scmid) { + parent_commit = commits_by_scmid[parent_scmid]; + if (parent_commit) { parent_y = yForRow(max_rdmid - parent_commit.rdmid); parent_x = graph_x_offset + XSTEP / 2 + XSTEP * parent_commit.space; - if (parent_commit.space == commit.space) { + const controlPointDelta = (parent_y - y) / 8; + + if (parent_commit.space === commit.space) { // vertical path path = revisionGraph.path([ 'M', x, y, 'V', parent_y]); + } else if (noVerticalParents) { + // branch start (Bezier curve) + path = revisionGraph.path([ + 'M', x, y, + 'C', x, y + controlPointDelta, x, parent_y - controlPointDelta, parent_x, parent_y]); + } else if (!parent_commit.hasOwnProperty('vertical_children')) { + // branch end (Bezier curve) + path = revisionGraph.path([ + 'M', x, y, + 'C', parent_x, y + controlPointDelta, parent_x, parent_y, parent_x, parent_y]); } else { // path to a commit in a different branch (Bezier curve) path = revisionGraph.path([ 'M', x, y, - 'C', x, y, x, y + (parent_y - y) / 2, x + (parent_x - x) / 2, y + (parent_y - y) / 2, - 'C', x + (parent_x - x) / 2, y + (parent_y - y) / 2, parent_x, parent_y-(parent_y-y)/2, parent_x, parent_y]); + 'C', parent_x, y, x, parent_y, parent_x, parent_y]); } } else { // vertical path ending at the bottom of the revisionGraph diff --git a/app/helpers/repositories_helper.rb b/app/helpers/repositories_helper.rb index 6ed17c692..7cfbcdda0 100644 --- a/app/helpers/repositories_helper.rb +++ b/app/helpers/repositories_helper.rb @@ -310,6 +310,15 @@ module RepositoriesHelper while (commit = commits.find { |commit| commits_by_scmid[commit.scmid][:space].nil? }) space = index_head(space + 1, commit, commits_by_scmid) end + # Set vertical_children flag for commits that have children in the same column + # for S-style connections between commits + commits_by_scmid.each_value do |commit| + commit[:parent_scmids].each do |scmid| + if (parent = commits_by_scmid[scmid]) && parent[:space] == commit[:space] + parent[:vertical_children] = true + end + end + end return commits_by_scmid, space end -- 2.50.1