Commit 38fce3deb03904fdfcf2fe512b094d49e22fe61c
1 parent
f11e855b
Exists in
master
and in
4 other branches
It improves detecting an overlap of a line
Showing
2 changed files
with
31 additions
and
15 deletions
Show diff stats
app/models/graph/commit.rb
@@ -4,12 +4,12 @@ module Graph | @@ -4,12 +4,12 @@ module Graph | ||
4 | class Commit | 4 | class Commit |
5 | include ActionView::Helpers::TagHelper | 5 | include ActionView::Helpers::TagHelper |
6 | 6 | ||
7 | - attr_accessor :time, :space, :refs, :parent_spaces | 7 | + attr_accessor :time, :spaces, :refs, :parent_spaces |
8 | 8 | ||
9 | def initialize(commit) | 9 | def initialize(commit) |
10 | @_commit = commit | 10 | @_commit = commit |
11 | @time = -1 | 11 | @time = -1 |
12 | - @space = 0 | 12 | + @spaces = [] |
13 | @parent_spaces = [] | 13 | @parent_spaces = [] |
14 | end | 14 | end |
15 | 15 | ||
@@ -27,7 +27,7 @@ module Graph | @@ -27,7 +27,7 @@ module Graph | ||
27 | email: author.email | 27 | email: author.email |
28 | } | 28 | } |
29 | h[:time] = time | 29 | h[:time] = time |
30 | - h[:space] = space | 30 | + h[:space] = spaces.first |
31 | h[:parent_spaces] = parent_spaces | 31 | h[:parent_spaces] = parent_spaces |
32 | h[:refs] = refs.collect{|r|r.name}.join(" ") unless refs.nil? | 32 | h[:refs] = refs.collect{|r|r.name}.join(" ") unless refs.nil? |
33 | h[:id] = sha | 33 | h[:id] = sha |
@@ -46,5 +46,13 @@ module Graph | @@ -46,5 +46,13 @@ module Graph | ||
46 | @refs = ref_cache[@_commit.id] if ref_cache.include?(@_commit.id) | 46 | @refs = ref_cache[@_commit.id] if ref_cache.include?(@_commit.id) |
47 | @refs ||= [] | 47 | @refs ||= [] |
48 | end | 48 | end |
49 | + | ||
50 | + def space | ||
51 | + if @spaces.size > 0 | ||
52 | + @spaces.first | ||
53 | + else | ||
54 | + 0 | ||
55 | + end | ||
56 | + end | ||
49 | end | 57 | end |
50 | end | 58 | end |
app/models/graph/json_builder.rb
@@ -151,7 +151,7 @@ module Graph | @@ -151,7 +151,7 @@ module Graph | ||
151 | 151 | ||
152 | def find_free_parent_space(range, space_base, space_step, space_default, times) | 152 | def find_free_parent_space(range, space_base, space_step, space_default, times) |
153 | if is_overlap?(range, times, space_default) then | 153 | if is_overlap?(range, times, space_default) then |
154 | - find_free_space(range, space_base, space_step, space_default) | 154 | + find_free_space(range, space_step, space_base, space_default) |
155 | else | 155 | else |
156 | space_default | 156 | space_default |
157 | end | 157 | end |
@@ -161,7 +161,7 @@ module Graph | @@ -161,7 +161,7 @@ module Graph | ||
161 | range.each do |i| | 161 | range.each do |i| |
162 | if i != range.first && | 162 | if i != range.first && |
163 | i != range.last && | 163 | i != range.last && |
164 | - times[i].space == overlap_space then | 164 | + times[i].spaces.include?(overlap_space) then |
165 | 165 | ||
166 | return true; | 166 | return true; |
167 | end | 167 | end |
@@ -179,9 +179,24 @@ module Graph | @@ -179,9 +179,24 @@ module Graph | ||
179 | if leaves.empty? | 179 | if leaves.empty? |
180 | return | 180 | return |
181 | end | 181 | end |
182 | + | ||
183 | + time_range = leaves.last.time..leaves.first.time | ||
184 | + space = find_free_space(time_range, 2) | ||
185 | + leaves.each do |l| | ||
186 | + l.spaces << space | ||
187 | + # Also add space to parent | ||
188 | + l.parents.each do |p| | ||
189 | + if map.include?(p.id) | ||
190 | + parent = map[p.id] | ||
191 | + if parent.space > 0 | ||
192 | + parent.spaces << space | ||
193 | + end | ||
194 | + end | ||
195 | + end | ||
196 | + end | ||
197 | + | ||
182 | # and mark it as reserved | 198 | # and mark it as reserved |
183 | min_time = leaves.last.time | 199 | min_time = leaves.last.time |
184 | - max_space = 1 | ||
185 | parents = leaves.last.parents.collect | 200 | parents = leaves.last.parents.collect |
186 | parents.each do |p| | 201 | parents.each do |p| |
187 | if map.include? p.id | 202 | if map.include? p.id |
@@ -189,21 +204,14 @@ module Graph | @@ -189,21 +204,14 @@ module Graph | ||
189 | if parent.time < min_time | 204 | if parent.time < min_time |
190 | min_time = parent.time | 205 | min_time = parent.time |
191 | end | 206 | end |
192 | - if max_space < parent.space then | ||
193 | - max_space = parent.space | ||
194 | - end | ||
195 | end | 207 | end |
196 | end | 208 | end |
209 | + | ||
197 | if parent_time.nil? | 210 | if parent_time.nil? |
198 | max_time = leaves.first.time | 211 | max_time = leaves.first.time |
199 | else | 212 | else |
200 | max_time = parent_time - 1 | 213 | max_time = parent_time - 1 |
201 | end | 214 | end |
202 | - | ||
203 | - time_range = leaves.last.time..leaves.first.time | ||
204 | - space = find_free_space(time_range, max_space, 2) | ||
205 | - leaves.each{|l| l.space = space} | ||
206 | - | ||
207 | mark_reserved(min_time..max_time, space) | 215 | mark_reserved(min_time..max_time, space) |
208 | 216 | ||
209 | # Visit branching chains | 217 | # Visit branching chains |
@@ -221,7 +229,7 @@ module Graph | @@ -221,7 +229,7 @@ module Graph | ||
221 | end | 229 | end |
222 | end | 230 | end |
223 | 231 | ||
224 | - def find_free_space(time_range, space_base, space_step, space_default = 1) | 232 | + def find_free_space(time_range, space_step, space_base = 1, space_default = 1) |
225 | reserved = [] | 233 | reserved = [] |
226 | for day in time_range | 234 | for day in time_range |
227 | reserved += @_reserved[day] | 235 | reserved += @_reserved[day] |