It improves detecting an overlap of a line

This commit is contained in:
Sato Hiroyuki 2013-02-27 22:37:38 +09:00
parent f11e855bdb
commit 38fce3deb0
2 changed files with 31 additions and 15 deletions

View file

@ -4,12 +4,12 @@ module Graph
class Commit class Commit
include ActionView::Helpers::TagHelper include ActionView::Helpers::TagHelper
attr_accessor :time, :space, :refs, :parent_spaces attr_accessor :time, :spaces, :refs, :parent_spaces
def initialize(commit) def initialize(commit)
@_commit = commit @_commit = commit
@time = -1 @time = -1
@space = 0 @spaces = []
@parent_spaces = [] @parent_spaces = []
end end
@ -27,7 +27,7 @@ module Graph
email: author.email email: author.email
} }
h[:time] = time h[:time] = time
h[:space] = space h[:space] = spaces.first
h[:parent_spaces] = parent_spaces h[:parent_spaces] = parent_spaces
h[:refs] = refs.collect{|r|r.name}.join(" ") unless refs.nil? h[:refs] = refs.collect{|r|r.name}.join(" ") unless refs.nil?
h[:id] = sha h[:id] = sha
@ -46,5 +46,13 @@ module Graph
@refs = ref_cache[@_commit.id] if ref_cache.include?(@_commit.id) @refs = ref_cache[@_commit.id] if ref_cache.include?(@_commit.id)
@refs ||= [] @refs ||= []
end end
def space
if @spaces.size > 0
@spaces.first
else
0
end
end
end end
end end

View file

@ -151,7 +151,7 @@ module Graph
def find_free_parent_space(range, space_base, space_step, space_default, times) def find_free_parent_space(range, space_base, space_step, space_default, times)
if is_overlap?(range, times, space_default) then if is_overlap?(range, times, space_default) then
find_free_space(range, space_base, space_step, space_default) find_free_space(range, space_step, space_base, space_default)
else else
space_default space_default
end end
@ -161,7 +161,7 @@ module Graph
range.each do |i| range.each do |i|
if i != range.first && if i != range.first &&
i != range.last && i != range.last &&
times[i].space == overlap_space then times[i].spaces.include?(overlap_space) then
return true; return true;
end end
@ -179,9 +179,24 @@ module Graph
if leaves.empty? if leaves.empty?
return return
end end
time_range = leaves.last.time..leaves.first.time
space = find_free_space(time_range, 2)
leaves.each do |l|
l.spaces << space
# Also add space to parent
l.parents.each do |p|
if map.include?(p.id)
parent = map[p.id]
if parent.space > 0
parent.spaces << space
end
end
end
end
# and mark it as reserved # and mark it as reserved
min_time = leaves.last.time min_time = leaves.last.time
max_space = 1
parents = leaves.last.parents.collect parents = leaves.last.parents.collect
parents.each do |p| parents.each do |p|
if map.include? p.id if map.include? p.id
@ -189,21 +204,14 @@ module Graph
if parent.time < min_time if parent.time < min_time
min_time = parent.time min_time = parent.time
end end
if max_space < parent.space then
max_space = parent.space
end
end end
end end
if parent_time.nil? if parent_time.nil?
max_time = leaves.first.time max_time = leaves.first.time
else else
max_time = parent_time - 1 max_time = parent_time - 1
end end
time_range = leaves.last.time..leaves.first.time
space = find_free_space(time_range, max_space, 2)
leaves.each{|l| l.space = space}
mark_reserved(min_time..max_time, space) mark_reserved(min_time..max_time, space)
# Visit branching chains # Visit branching chains
@ -221,7 +229,7 @@ module Graph
end end
end end
def find_free_space(time_range, space_base, space_step, space_default = 1) def find_free_space(time_range, space_step, space_base = 1, space_default = 1)
reserved = [] reserved = []
for day in time_range for day in time_range
reserved += @_reserved[day] reserved += @_reserved[day]