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 | 4 | class Commit |
5 | 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 | 9 | def initialize(commit) |
10 | 10 | @_commit = commit |
11 | 11 | @time = -1 |
12 | - @space = 0 | |
12 | + @spaces = [] | |
13 | 13 | @parent_spaces = [] |
14 | 14 | end |
15 | 15 | |
... | ... | @@ -27,7 +27,7 @@ module Graph |
27 | 27 | email: author.email |
28 | 28 | } |
29 | 29 | h[:time] = time |
30 | - h[:space] = space | |
30 | + h[:space] = spaces.first | |
31 | 31 | h[:parent_spaces] = parent_spaces |
32 | 32 | h[:refs] = refs.collect{|r|r.name}.join(" ") unless refs.nil? |
33 | 33 | h[:id] = sha |
... | ... | @@ -46,5 +46,13 @@ module Graph |
46 | 46 | @refs = ref_cache[@_commit.id] if ref_cache.include?(@_commit.id) |
47 | 47 | @refs ||= [] |
48 | 48 | end |
49 | + | |
50 | + def space | |
51 | + if @spaces.size > 0 | |
52 | + @spaces.first | |
53 | + else | |
54 | + 0 | |
55 | + end | |
56 | + end | |
49 | 57 | end |
50 | 58 | end | ... | ... |
app/models/graph/json_builder.rb
... | ... | @@ -151,7 +151,7 @@ module Graph |
151 | 151 | |
152 | 152 | def find_free_parent_space(range, space_base, space_step, space_default, times) |
153 | 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 | 155 | else |
156 | 156 | space_default |
157 | 157 | end |
... | ... | @@ -161,7 +161,7 @@ module Graph |
161 | 161 | range.each do |i| |
162 | 162 | if i != range.first && |
163 | 163 | i != range.last && |
164 | - times[i].space == overlap_space then | |
164 | + times[i].spaces.include?(overlap_space) then | |
165 | 165 | |
166 | 166 | return true; |
167 | 167 | end |
... | ... | @@ -179,9 +179,24 @@ module Graph |
179 | 179 | if leaves.empty? |
180 | 180 | return |
181 | 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 | 198 | # and mark it as reserved |
183 | 199 | min_time = leaves.last.time |
184 | - max_space = 1 | |
185 | 200 | parents = leaves.last.parents.collect |
186 | 201 | parents.each do |p| |
187 | 202 | if map.include? p.id |
... | ... | @@ -189,21 +204,14 @@ module Graph |
189 | 204 | if parent.time < min_time |
190 | 205 | min_time = parent.time |
191 | 206 | end |
192 | - if max_space < parent.space then | |
193 | - max_space = parent.space | |
194 | - end | |
195 | 207 | end |
196 | 208 | end |
209 | + | |
197 | 210 | if parent_time.nil? |
198 | 211 | max_time = leaves.first.time |
199 | 212 | else |
200 | 213 | max_time = parent_time - 1 |
201 | 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 | 215 | mark_reserved(min_time..max_time, space) |
208 | 216 | |
209 | 217 | # Visit branching chains |
... | ... | @@ -221,7 +229,7 @@ module Graph |
221 | 229 | end |
222 | 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 | 233 | reserved = [] |
226 | 234 | for day in time_range |
227 | 235 | reserved += @_reserved[day] | ... | ... |