예제 #1
0
        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);
        }
예제 #2
0
        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));
        }
예제 #3
0
        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);
            }
        }
예제 #4
0
        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));
        }
예제 #5
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);
        }
예제 #6
0
        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);
        }
예제 #7
0
 public void AddChild(HierarchicalData child)
 {
     _children.Add(child);
     child.Parent = this;
 }