Commit 3ca6c960 authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Merge pull request #942 from veprbl/network_graph_fix

Network graph fix (#909)
parents 25f1a7ec 16339579
...@@ -50,10 +50,14 @@ class GraphCommit ...@@ -50,10 +50,14 @@ class GraphCommit
end end
end end
j = 0 @_reserved = {}
days.each_index do |i|
@_reserved[i] = []
end
heads.each do |h| heads.each do |h|
if map.include? h.commit.id then 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
end end
days days
...@@ -61,23 +65,80 @@ class GraphCommit ...@@ -61,23 +65,80 @@ class GraphCommit
# Add space mark on commit and its parents # 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<String,GraphCommit>] 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 [GraphCommit] the commit object.
# @param [Hash<String,GraphCommit>] map of commits # @param [Hash<String,GraphCommit>] map of commits
# #
# @return [Fixnum] max space used. # @return [Array<GraphCommit>] list of branch commits
def self.mark_chain(mark, commit, map) def self.take_left_leaves(commit, map)
commit.space = mark if commit.space == 0 leaves = []
m1 = mark - 1 leaves.push(commit) if commit.space == 0
marks = commit.parents.collect do |p| while true
if map.include? p.id and map[p.id].space == 0 then parent = commit.parents.collect
mark_chain(m1 += 1, map[p.id],map) .select{|p| map.include? p.id and map[p.id].space == 0}
if parent.count == 0 then
return leaves
else else
m1 + 1 commit = map[parent.first.id]
leaves.push(commit)
end end
end end
marks << mark
marks.compact.max
end end
......
...@@ -79,11 +79,11 @@ function branchGraph(holder) { ...@@ -79,11 +79,11 @@ function branchGraph(holder) {
.attr({stroke: colors[c.space], "stroke-width": 2}); .attr({stroke: colors[c.space], "stroke-width": 2});
} else if (c.space < commits[i].space) { } 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}); .attr({stroke: colors[commits[i].space], "stroke-width": 2});
} else { } 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 + 6, "l-4,3,4,2,0,-5L", x - 10, y + 20, "L", x - 10, cy, cx, cy])
.attr({stroke: colors[commits[i].space], "stroke-width": 2}); .attr({stroke: colors[c.space], "stroke-width": 2});
} }
} }
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment