From 00d0e57e859454c62084893a74fad71c26d5c50c Mon Sep 17 00:00:00 2001
From: Sato Hiroyuki <sathiroyuki@gmail.com>
Date: Wed, 27 Feb 2013 23:43:33 +0900
Subject: [PATCH] Commits are arranged below their first parent.

---
 app/models/graph/json_builder.rb | 21 +++++++++++++++++++--
 1 file changed, 19 insertions(+), 2 deletions(-)

diff --git a/app/models/graph/json_builder.rb b/app/models/graph/json_builder.rb
index 5237ccfe081..013d15fb754 100644
--- a/app/models/graph/json_builder.rb
+++ b/app/models/graph/json_builder.rb
@@ -181,7 +181,8 @@ module Graph
       end
 
       time_range = leaves.last.time..leaves.first.time
-      space = find_free_space(time_range, 2)
+      space_base = get_space_base(leaves, map)
+      space = find_free_space(time_range, 2, space_base)
       leaves.each do |l|
         l.spaces << space
         # Also add space to parent
@@ -223,13 +224,29 @@ module Graph
       end
     end
 
+    def get_space_base(leaves, map)
+      space_base = 1
+      if leaves.last.parents.size > 0
+        first_parent = leaves.last.parents.first
+        if map.include?(first_parent.id)
+          first_p = map[first_parent.id]
+          if first_p.space > 0
+            space_base = first_p.space
+          end
+        end
+      end
+      space_base
+    end
+
     def mark_reserved(time_range, space)
       for day in time_range
         @_reserved[day].push(space)
       end
     end
 
-    def find_free_space(time_range, space_step, space_base = 1, space_default = 1)
+    def find_free_space(time_range, space_step, space_base = 1, space_default = nil)
+      space_default ||= space_base
+
       reserved = []
       for day in time_range
         reserved += @_reserved[day]
-- 
GitLab