public HierarchicalData Hit(HierarchicalData item, Point mousePos) { // We may find a more detailed hit deeper. HierarchicalData best = null; if (item.Layout == null) { return(null); } if (item.Layout.IsHit(mousePos)) { best = item; if (item.IsLeafNode) { return(item); } } foreach (var child in item.Children) { if (child.Layout.IsHit(mousePos)) { return(Hit(child, mousePos)); } } return(best); }
private void RemoveLeafNodes(HierarchicalData root, Func <HierarchicalData, bool> removePredicate) { foreach (var child in root.Children) { RemoveLeafNodes(child, removePredicate); } root._children.RemoveAll(x => x.IsLeafNode && removePredicate(x)); }
private void Dump(HierarchicalData item, int level) { Debug.WriteLine(new string(Enumerable.Repeat('\t', level).ToArray()) + item.Name + " " + item.Layout); foreach (var child in item.Children) { Dump(child, level + 1); } }
private void RemoveLeafNodesWithoutArea(HierarchicalData data) { foreach (var child in data._children) { RemoveLeafNodesWithoutArea(child); } // During the recursive process new empty nodes may arise. So bottom to top. data._children.RemoveAll(x => x.IsLeafNode && (double.IsNaN(x.AreaMetric) || Math.Abs(x.AreaMetric) <= 0)); }
private HierarchicalData Clone(HierarchicalData cloneThis) { var newData = new HierarchicalData(cloneThis.Name, cloneThis.AreaMetric, cloneThis.WeightMetric, _weightIsAleadyNormalized); newData.Description = cloneThis.Description; newData.ColorKey = cloneThis.ColorKey; newData.Tag = cloneThis.Tag; foreach (var child in cloneThis.Children) { newData.AddChild(Clone(child)); } return(newData); }
private HierarchicalData Clone(HierarchicalData cloneThis) { var newData = new HierarchicalData(cloneThis.Name, cloneThis.AreaMetric, cloneThis.WeightMetric); newData.Description = cloneThis.Description; newData.ColorKey = cloneThis.ColorKey; newData.Tag = cloneThis.Tag; newData.AreaMetricSum = cloneThis.AreaMetricSum; newData.NormalizedWeightMetric = cloneThis.NormalizedWeightMetric; // TODO remove newData.Id = cloneThis.Id; foreach (var child in cloneThis._children) { newData.AddChild(Clone(child)); } return(newData); }
public void AddChild(HierarchicalData child) { _children.Add(child); child.Parent = this; }