private Elem WlkRightmostChild(Elem e) { //this can be made much more efficient with direct acess to Node::m_children Elem rm = null; foreach (Elem elem in e.Children()) { rm = elem; } return rm; }
private void WlkSecondWalk(Elem v, int m, int level, Point origin) { int myy = v.Parent == null ? origin.Y : v.Parent.Location.Y + m_levelDimensions[level - 1].Height + MarginVertical(); v.Location = new Point(v.prelim + m + origin.X, myy); foreach (Elem w in v.Children()) WlkSecondWalk(w, m + v.mod, level + 1, origin); }
private void WlkFirstWalk(Elem v) { if (v.NumChildren() == 0) { v.prelim = 0; Elem left = WlkGetLeftSibling(v); if (left != null) v.prelim = left.prelim + MarginHorizontal() + left.Dimensions.Width; } else { Elem leftmostChild = WlkLeftmostChild(v); Elem rightmostChild = WlkRightmostChild(v); Elem defaultAncestor = leftmostChild; foreach (Elem w1 in v.Children()) { WlkFirstWalk(w1); WlkApportion(w1, defaultAncestor); } WlkExecuteShifts(v); int midpoint = (leftmostChild.prelim + leftmostChild.Dimensions.Width / 2 + rightmostChild.prelim + rightmostChild.Dimensions.Width / 2) - v.Dimensions.Width; midpoint /= 2; Elem w = WlkGetLeftSibling(v); if (w != null) { v.prelim = w.prelim + MarginHorizontal() + w.Dimensions.Width; v.mod = v.prelim - midpoint; } else v.prelim = midpoint; } }
private Elem WlkLeftmostChild(Elem e) { //this can be made much more efficient with direct acess to Node::m_children foreach (Elem elem in e.Children()) { return elem; } return null; }
private void WlkFindExtents(Elem node, int m, int depth, ref int max, ref int min) { int thismin = m + node.prelim; int thismax = m + node.prelim + node.Dimensions.Width; int maxheight = 0; foreach (Elem elem in node.Children()) { int localmin = 0, localmax = 0; WlkFindExtents(elem, node.mod + m, depth + 1, ref localmax, ref localmin); thismin = Math.Min(thismin, localmin); thismax = Math.Max(thismax, localmax); maxheight = Math.Max(maxheight, elem.BranchDimensions.Height); } if (maxheight == 0) maxheight = m_levelDimensions[depth].Height; else maxheight += m_levelDimensions[depth].Height + MarginVertical(); max = thismax; min = thismin; node.shift = min; node.BranchDimensions = new Size(max - min, maxheight); }
private void WlkExecuteShifts(Elem v) { int shift = 0; int change = 0; List<Elem> reverse = new List<Elem>(v.NumChildren()); foreach (Elem e in v.Children()) /*and this monstrosity. ug!*/ reverse.Add(e); reverse.Reverse(); foreach (Elem w in reverse) { w.prelim = w.prelim + shift; w.mod = w.mod + shift; change = change + w.change; shift = shift + w.shift + change; } }
private void UpdateTraces(Elem elem) { foreach (Elem e in elem.Children()) UpdateTraces(e); UpdateTracesWorker(elem); }
void CalcNodeInfoRecurse(Elem elem, int current, int target) { int nchildren = elem.GetNode().NumChildren(); elem.BranchDimensions = new Size(target, elem.BranchDimensions.Height); if (nchildren == 0) return; int delta = target - current; int target_delta = delta / nchildren; foreach (Elem child in elem.Children()) { int child_width = child.BranchDimensions.Width; CalcNodeInfoRecurse(child, child_width, child_width + target_delta); } }
private void CalcBranchDimensions(Elem elem, int depth) { Node n = elem.GetNode(); if (!n.HasChildren()) elem.BranchDimensions = elem.Dimensions; else { int wsum = 0; int hmax = 0; int wmax = 0; foreach (Elem child in elem.Children()) { CalcBranchDimensions(child, depth + 1); wmax = Math.Max(wmax, child.BranchDimensions.Width); hmax = Math.Max(hmax, child.BranchDimensions.Height); wsum += MarginHorizontal() + child.BranchDimensions.Width; } if (RowsArranged()) hmax += m_levelDimensions[depth].Height + MarginVertical(); else hmax += elem.Dimensions.Height + MarginVertical(); wsum -= MarginHorizontal(); if (ShouldDoBalancedTree()) { foreach (Elem child in elem.Children()) { if (wmax > child.BranchDimensions.Width) CalcNodeInfoRecurse(child, child.BranchDimensions.Width, wmax); child.BranchDimensions = new Size(wmax, child.BranchDimensions.Height); } wsum = (elem.GetNode().NumChildren()) * wmax + (MarginHorizontal() * (elem.GetNode().NumChildren() - 1)); } if (wsum < elem.Dimensions.Width) { CalcNodeInfoRecurse(elem, wsum, elem.Dimensions.Width); wsum = elem.Dimensions.Width; } elem.BranchDimensions = new Size(wsum, hmax); } }