static void SetSceneGraphProperties(Timeline t)
        {
            t.layout_x = t.left;
            t.layout_y = t.y;
            t.layout_width = t.right - t.left;
            t.layout_height = t.height.Value;

            foreach (var c in t.ChildTimelines)
                SetSceneGraphProperties(c);
        }
        public static void initData()
        {
            /*
            // 1. deserializing ResponseDump.txt
            Timeline root;
            Debug.Write("Deserializing ResponseDump.txt ... ");
            using (var file = File.OpenText(HostingEnvironment.ApplicationPhysicalPath + @"Content/ResponseDumps/ResponseDump.txt"))
            {
                var serializer = new JsonSerializer();
                var r = (TimelineArray)serializer.Deserialize(file, typeof(TimelineArray));
                root = r.d[0];
            }
            Debug.WriteLine("[Done]");

            // 2. calculating layout
            Debug.Write("Calculating Layout ... ");
            var layoutAlg = new LayoutAlgorithm();
            layoutAlg.CalulateLayout(root);
            Debug.WriteLine("[Done]");

            // 3. serialize ResponseDumpWithLayout.txt
            Debug.Write("Serializing and Writting ResponseDumpWithLayout.txt ... ");
            using (var file = File.CreateText(HostingEnvironment.ApplicationPhysicalPath + @"Content/ResponseDumps/ResponseDumpWithLayout.txt"))
            {
                var serializer = new JsonSerializer();
                serializer.Serialize(file, root);
            }
            Debug.WriteLine("[Done]");

            // 4. set SceneGraph
            SetSceneGraphProperties(root);
            SceneGraph = root;
            */

            Timeline root;
            using (var file = File.OpenText(HostingEnvironment.ApplicationPhysicalPath + @"\Content\ResponseDumps\ResponseDumpWithLayout.txt"))
            {
                var serializer = new JsonSerializer();
                var r = (Timeline)serializer.Deserialize(file, typeof(Timeline));
                root = r;
            }

            SetSceneGraphProperties(root);
            SceneGraph = root;
        }
        public Timeline getContent(Timeline tl, BoundingBox wnd, double scale)
        {
            // assert: tl intersects wnd and is visible
            // => tl is part of content
            // => tl is loaded
            // => return tl with ChildTimelines

            var content = tl.clone();
            content.isBuffered = true;

            foreach (var child in tl.ChildTimelines)
            {
                if (child.intersects(wnd) && child.isVisible(scale))
                    content.ChildTimelines.Add(getContent(child, wnd, scale));
                else
                    content.ChildTimelines.Add(child.clone());
            }

            return content;
        }
 public static void GenerateProperty(Timeline timeline, string direction)
 {
     if (direction.ToLower() == "from")
     {
         var fromTimeUnit = timeline.FromTimeUnit.ToLower();
         if (fromTimeUnit == "ga")
         {
             timeline.left = -timeline.FromYear.Value * 1000000000;
         }
         else if (fromTimeUnit == "ma")
         {
             timeline.left = -timeline.FromYear.Value * 1000000;
         }
         else if (fromTimeUnit == "ka")
         {
             timeline.left = -timeline.FromYear.Value * 1000;
         }
         else if (fromTimeUnit == "bce")
         {
             timeline.left = getCoordinateFromDMY(
                 -timeline.FromYear.Value,
                 !timeline.FromMonth.HasValue ? 0 : Math.Min(11, Math.Max(0, timeline.FromMonth.Value - 1)),
                 !timeline.FromDay.HasValue ? 1 : timeline.FromDay.Value
             );
         }
         else if (fromTimeUnit == "ce")
         {
             timeline.left = getCoordinateFromDMY(
                 timeline.FromYear.Value,
                 !timeline.FromMonth.HasValue ? 0 : Math.Min(11, Math.Max(0, timeline.FromMonth.Value - 1)),
                 !timeline.FromDay.HasValue ? 1 : timeline.FromDay.Value
             );
         }
     }
     else if (direction.ToLower() == "to")
     {
         var toTimeUnit = timeline.ToTimeUnit.ToLower();
         if (toTimeUnit == "ga")
         {
             timeline.right = -timeline.ToYear.Value * 1000000000;
         }
         else if (toTimeUnit == "ma")
         {
             timeline.right = -timeline.ToYear.Value * 1000000;
         }
         else if (toTimeUnit == "ka")
         {
             timeline.right = -timeline.ToYear.Value * 1000;
         }
         else if (toTimeUnit == "bce")
         {
             timeline.right = getCoordinateFromDMY(
                 -timeline.ToYear.Value,
                 !timeline.ToMonth.HasValue ? 0 : Math.Min(11, Math.Max(0, timeline.ToMonth.Value - 1)),
                 !timeline.ToDay.HasValue ? 1 : timeline.ToDay.Value
             );
         }
         else if (toTimeUnit == "ce")
         {
             timeline.right = getCoordinateFromDMY(
                 timeline.ToYear.Value,
                 !timeline.ToMonth.HasValue ? 0 : Math.Min(11, Math.Max(0, timeline.ToMonth.Value - 1)),
                 !timeline.ToDay.HasValue ? 1 : timeline.ToDay.Value
             );
         }
     }
 }
        public Timeline getPath(Timeline tl, BoundingBox wnd, ref Timeline lca)
        {
            // assert: tl contains wnd
            // => tl is part of path

            var path = tl.clone();
            path.Exhibits = new List<Exhibit>();
            lca = tl;

            foreach (var child in tl.ChildTimelines)
            {
                if (child.contains(wnd))
                {
                    path.ChildTimelines.Add(getPath(child, wnd, ref lca));
                    break;
                }
            }

            return path;
        }