Commit f11e855bdb7f4026a4ec4c553ce7308b9bf71a0a

Authored by Sato Hiroyuki
1 parent aa36f07a

Finding free space from the way near commit which is downward

Showing 1 changed file with 6 additions and 6 deletions   Show diff stats
app/models/graph/json_builder.rb
... ... @@ -136,9 +136,9 @@ module Graph
136 136 end
137 137  
138 138 space = if commit.space >= parent.space then
139   - find_free_parent_space(range, parent.space, 1, commit.space, times)
  139 + find_free_parent_space(range, parent.space, -1, commit.space, times)
140 140 else
141   - find_free_parent_space(range, parent.space, -1, parent.space, times)
  141 + find_free_parent_space(range, commit.space, -1, parent.space, times)
142 142 end
143 143  
144 144 mark_reserved(range, space)
... ... @@ -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)
  154 + find_free_space(range, space_base, space_step, space_default)
155 155 else
156 156 space_default
157 157 end
... ... @@ -221,17 +221,17 @@ module Graph
221 221 end
222 222 end
223 223  
224   - def find_free_space(time_range, space_base, space_step)
  224 + def find_free_space(time_range, space_base, space_step, space_default = 1)
225 225 reserved = []
226 226 for day in time_range
227 227 reserved += @_reserved[day]
228 228 end
229 229 reserved.uniq!
230 230  
231   - space = space_base
  231 + space = space_default
232 232 while reserved.include?(space) do
233 233 space += space_step
234   - if space <= 0 then
  234 + if space < space_base then
235 235 space_step *= -1
236 236 space = space_base + space_step
237 237 end
... ...