From f33a80a522a712d6404e6de5bed8f86d551ff525 Mon Sep 17 00:00:00 2001 From: Dmitry Kalinkin Date: Fri, 15 Jun 2012 18:37:59 +0400 Subject: [PATCH 1/5] #909 fix network graph json generation --- lib/graph_commit.rb | 87 ++++++++++++++++++++++++++++++++++++++------- 1 file changed, 74 insertions(+), 13 deletions(-) diff --git a/lib/graph_commit.rb b/lib/graph_commit.rb index 64498d8b..269378e8 100644 --- a/lib/graph_commit.rb +++ b/lib/graph_commit.rb @@ -50,10 +50,14 @@ class GraphCommit end end - j = 0 + @_reserved = {} + days.each_index do |i| + @_reserved[i] = [] + end + heads.each do |h| if map.include? h.commit.id then - j = mark_chain(j+=1, map[h.commit.id], map) + place_chain(map[h.commit.id], map) end end days @@ -61,23 +65,80 @@ class GraphCommit # Add space mark on commit and its parents # - # @param [Fixnum] space (row on the graph) to be set + # @param [GraphCommit] the commit object. + # @param [Hash] map of commits + def self.place_chain(commit, map, parent_time = nil) + leaves = take_left_leaves(commit, map) + if leaves.empty? then + return + end + space = find_free_space(leaves.last.time..leaves.first.time) + leaves.each{|l| l.space = space} + # and mark it as reserved + min_time = leaves.last.time + parents = leaves.last.parents.collect + parents.each do |p| + if map.include? p.id then + parent = map[p.id] + if parent.time < min_time then + min_time = parent.time + end + end + end + if parent_time.nil? then + max_time = leaves.first.time + else + max_time = parent_time - 1 + end + mark_reserved(min_time..max_time, space) + # Visit branching chains + leaves.each do |l| + parents = l.parents.collect + .select{|p| map.include? p.id and map[p.id].space == 0} + for p in parents + place_chain(map[p.id], map, l.time) + end + end + end + + def self.mark_reserved(time_range, space) + for day in time_range + @_reserved[day].push(space) + end + end + + def self.find_free_space(time_range) + reserved = [] + for day in time_range + reserved += @_reserved[day] + end + space = 1 + while reserved.include? space do + space += 1 + end + space + end + + # Takes most left subtree branch of commits + # which don't have space mark yet. + # # @param [GraphCommit] the commit object. # @param [Hash] map of commits # - # @return [Fixnum] max space used. - def self.mark_chain(mark, commit, map) - commit.space = mark if commit.space == 0 - m1 = mark - 1 - marks = commit.parents.collect do |p| - if map.include? p.id and map[p.id].space == 0 then - mark_chain(m1 += 1, map[p.id],map) + # @return [Array] list of branch commits + def self.take_left_leaves(commit, map) + leaves = [] + leaves.push(commit) if commit.space == 0 + while true + parent = commit.parents.collect + .select{|p| map.include? p.id and map[p.id].space == 0} + if parent.count == 0 then + return leaves else - m1 + 1 + commit = map[parent.first.id] + leaves.push(commit) end end - marks << mark - marks.compact.max end From efc86f9711240f0fef09ba15ec0fc575a8d7673e Mon Sep 17 00:00:00 2001 From: Dmitry Kalinkin Date: Fri, 15 Jun 2012 18:38:30 +0400 Subject: [PATCH 2/5] small refactoring for branch-graph.js --- vendor/assets/javascripts/branch-graph.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/vendor/assets/javascripts/branch-graph.js b/vendor/assets/javascripts/branch-graph.js index ad6ceae1..063a1677 100644 --- a/vendor/assets/javascripts/branch-graph.js +++ b/vendor/assets/javascripts/branch-graph.js @@ -79,10 +79,10 @@ function branchGraph(holder) { .attr({stroke: colors[c.space], "stroke-width": 2}); } else if (c.space < commits[i].space) { - r.path(["M", x - 5, y + .0001, "l-5-2,0,4,5,-2C",x-5,y,x -17, y+2, x -20, y-10,"L", cx,y-10,cx , cy]) + r.path(["M", x - 5, y + .0001, "l-5-2,0,4,5,-2C", x - 5, y, x - 17, y + 2, x - 20, y - 10, "L", cx, y - 10, cx, cy]) .attr({stroke: colors[commits[i].space], "stroke-width": 2}); } else { - r.path(["M", x-5, y, "l-5-2,0,4,5,-2C",x-5,y,x -17, y-2, x -20, y+10,"L", cx,y+10,cx , cy]) + r.path(["M", x - 5, y, "l-5-2,0,4,5,-2C", x - 5, y, x - 17, y - 2, x - 20, y + 10, "L", cx, y + 10, cx, cy]) .attr({stroke: colors[commits[i].space], "stroke-width": 2}); } } From 464ca2a248fc2fd3ddda6209d0a6a1780fd19b18 Mon Sep 17 00:00:00 2001 From: Dmitry Kalinkin Date: Tue, 19 Jun 2012 15:51:54 +0400 Subject: [PATCH 3/5] network graph: change lines to be more github-like (removes some ambiguousness in graph presentation) --- vendor/assets/javascripts/branch-graph.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/vendor/assets/javascripts/branch-graph.js b/vendor/assets/javascripts/branch-graph.js index 063a1677..9063d45c 100644 --- a/vendor/assets/javascripts/branch-graph.js +++ b/vendor/assets/javascripts/branch-graph.js @@ -79,10 +79,10 @@ function branchGraph(holder) { .attr({stroke: colors[c.space], "stroke-width": 2}); } else if (c.space < commits[i].space) { - r.path(["M", x - 5, y + .0001, "l-5-2,0,4,5,-2C", x - 5, y, x - 17, y + 2, x - 20, y - 10, "L", cx, y - 10, cx, cy]) + r.path(["M", x - 5, y + .0001, "l-5-2,0,4,5,-2C", x - 5, y, x - 17, y + 2, x - 20, y - 5, "L", cx, y - 5, cx, cy]) .attr({stroke: colors[commits[i].space], "stroke-width": 2}); } else { - r.path(["M", x - 5, y, "l-5-2,0,4,5,-2C", x - 5, y, x - 17, y - 2, x - 20, y + 10, "L", cx, y + 10, cx, cy]) + r.path(["M", x - 3, y + 4, "l-4,3,3,2,1,-4L", x - 10, y + 14, "L", x - 10, cy, cx, cy]) .attr({stroke: colors[commits[i].space], "stroke-width": 2}); } } From c31c84f58a8787fa78ee504ea36487264d8b8721 Mon Sep 17 00:00:00 2001 From: Dmitry Kalinkin Date: Tue, 19 Jun 2012 15:55:59 +0400 Subject: [PATCH 4/5] network graph: use same color for all branch --- vendor/assets/javascripts/branch-graph.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vendor/assets/javascripts/branch-graph.js b/vendor/assets/javascripts/branch-graph.js index 9063d45c..0f40c9f9 100644 --- a/vendor/assets/javascripts/branch-graph.js +++ b/vendor/assets/javascripts/branch-graph.js @@ -83,7 +83,7 @@ function branchGraph(holder) { .attr({stroke: colors[commits[i].space], "stroke-width": 2}); } else { r.path(["M", x - 3, y + 4, "l-4,3,3,2,1,-4L", x - 10, y + 14, "L", x - 10, cy, cx, cy]) - .attr({stroke: colors[commits[i].space], "stroke-width": 2}); + .attr({stroke: colors[c.space], "stroke-width": 2}); } } } From 163395793b787d86d43c61e6f90a6ce74b988e5c Mon Sep 17 00:00:00 2001 From: Dmitry Kalinkin Date: Tue, 19 Jun 2012 16:15:13 +0400 Subject: [PATCH 5/5] network graph: fixed minor visual artefacts --- vendor/assets/javascripts/branch-graph.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vendor/assets/javascripts/branch-graph.js b/vendor/assets/javascripts/branch-graph.js index 0f40c9f9..e8699bdf 100644 --- a/vendor/assets/javascripts/branch-graph.js +++ b/vendor/assets/javascripts/branch-graph.js @@ -82,7 +82,7 @@ function branchGraph(holder) { r.path(["M", x - 5, y + .0001, "l-5-2,0,4,5,-2C", x - 5, y, x - 17, y + 2, x - 20, y - 5, "L", cx, y - 5, cx, cy]) .attr({stroke: colors[commits[i].space], "stroke-width": 2}); } else { - r.path(["M", x - 3, y + 4, "l-4,3,3,2,1,-4L", x - 10, y + 14, "L", x - 10, cy, cx, cy]) + r.path(["M", x - 3, y + 6, "l-4,3,4,2,0,-5L", x - 10, y + 20, "L", x - 10, cy, cx, cy]) .attr({stroke: colors[c.space], "stroke-width": 2}); } }