public Timeline getPath(Timeline timeline, int lca_id, ref Timeline lca) { if (timeline.UniqueID == lca_id) { lca = timeline; Timeline t1 = timeline.clone(); t1.isBuffered = false; t1.pathID = -1; return t1; } else { foreach (var child in timeline.ChildTimelines) { Timeline t1 = getPath(child, lca_id, ref lca); if (t1 != null) { var t2 = timeline.clone(); t2.isBuffered = false; var k = 0; foreach (var c in timeline.ChildTimelines) { if (c.UniqueID == t1.UniqueID) { t2.ChildTimelines.Add(t1); t2.pathID = k; } else { var t = c.clone(); t.isBuffered = false; t2.ChildTimelines.Add(t); } k++; } foreach (var e in timeline.Exhibits) { // var i = e.clone(); t2.Exhibits.Add(e); } return t2; } } return null; } }
public Timeline getContent(Timeline timeline, double left, double right, double min_width) { var t1 = timeline.clone(); t1.isBuffered = true; t1.Exhibits.AddRange(timeline.Exhibits); foreach (var child in timeline.ChildTimelines) { if (!(child.left < left && child.right < left || child.left > right && child.right > right) && child.width >= min_width) t1.ChildTimelines.Add(getContent(child, left, right, min_width)); else t1.ChildTimelines.Add(child.clone()); } return t1; }
public static void initData() { StreamReader file = null; try { file = File.OpenText(HostingEnvironment.ApplicationPhysicalPath + @"\Content\ResponseDumps\ResponseDump.txt"); var serializer = new JsonSerializer(); var r = (ReponseDump)serializer.Deserialize(file, typeof(ReponseDump)); Root = r.d[0]; Utility.ParseLeftRight(Root); } catch (Exception e) { Debug.WriteLine(e.Message); } finally { if (file != null) file.Close(); } }
public static void ParseLeftRight(Timeline timeline) { // from -> left 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 ); } // to -> right 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 ); } // set width timeline.width = Math.Max(0, timeline.right - timeline.left); // recurse foreach (var childTimeline in timeline.ChildTimelines) ParseLeftRight(childTimeline); }