Example #1
0
 /// <summary>
 /// Moves the branch down to the correct levels if a collision was detected when working back down the tree towards the root node.
 /// </summary>
 /// <param name="nodeGroup">The start position (branch of the tree)</param>
 /// <param name="depth">The current node depth</param>
 private void OffsetNodes(TreeNodeGroup nodeGroup, int depth)
 {
     nodeGroup.ParentNode.MoveNode(new Point(nodeGroup.ParentNode.Location.X, _depthYMargin[depth]), true);
     _depthYMargin[depth] = nodeGroup.ParentNode.Location.Y + nodeGroup.ParentNode.NodeControl.ActualHeight + VERTICAL_BUFFER;
     foreach (TreeNodeGroup branchGroup in nodeGroup.ParentChildGroups)
     {
         OffsetNodes(branchGroup, depth + 1);
     }
 }
Example #2
0
        /// <summary>
        /// Recursively goes through the node tree until it reaches the ends and places the Y coordinate for each node
        /// Each node is moved with relation to nodes above and to the right of it.
        /// </summary>
        public void PositionNodes(TreeNodeGroup nodeGroup, int depth)
        {
            if (nodeGroup.ParentChildGroups.Count == 0) //is a leaf node
            {
                if (!_depthYMargin.ContainsKey(depth))
                {
                    //if you're positioning nodes below nodes that have already been positioned but deeper into the tree
                    //they must be lower than those nodes above, this gets that value and passes it on
                    if (depth > _maxTreeDepth && _depthYMargin.ContainsKey(_maxTreeDepth))
                    {
                        _depthYMargin[depth] = _depthYMargin[_maxTreeDepth];
                        _maxTreeDepth = depth;
                    }
                    else
                    {
                        _depthYMargin[depth] = MarginFromTop;
                        if (depth > _maxTreeDepth)
                        {
                            _maxTreeDepth = depth;
                        }
                    }
                }
                nodeGroup.ParentNode.MoveNode(new Point(nodeGroup.ParentNode.Location.X, _depthYMargin[depth]), true);
                _depthYMargin[depth] += nodeGroup.ParentNode.NodeControl.ActualHeight + VERTICAL_BUFFER;
            }
            else //is a parent node
            {
                bool firstRow = false;
                for (int i = 0; i < nodeGroup.ParentChildGroups.Count; i++)
                {
                    if (!_depthYMargin.ContainsKey(depth))
                    {
                        firstRow = true;
                        _depthYMargin[depth] = nodeGroup.ParentNode.NodeControl.ActualHeight + VERTICAL_BUFFER;
                    }
                    else
                    {
                        firstRow = false;
                    }
                    PositionNodes(nodeGroup.ParentChildGroups[i], depth+1);
                }

                double position = nodeGroup.GetYPosition();

                //if it's not the top most nodes check that it doesn't collide with a row of nodes above it
                if ((position < _depthYMargin[depth] - MarginFromTop) && !firstRow)
                {
                    OffsetNodes(nodeGroup, depth); //collision was detected, move all the nodes from this node to the depth of the tree down
                }
                else
                {
                    nodeGroup.ParentNode.MoveNode(new Point(nodeGroup.ParentNode.Location.X, position), true);
                    _depthYMargin[depth] = position + nodeGroup.ParentNode.NodeControl.ActualHeight + VERTICAL_BUFFER;
                }
            }
        }
Example #3
0
        /// <summary>
        /// Recursively goes through the node tree until it reaches the ends and places the Y coordinate for each node
        /// Each node is moved with relation to nodes above and to the right of it.
        /// </summary>
        public void PositionNodes(TreeNodeGroup nodeGroup, int depth)
        {
            if (nodeGroup.ParentChildGroups.Count == 0) //is a leaf node
            {
                if (!_depthYMargin.ContainsKey(depth))
                {
                    //if you're positioning nodes below nodes that have already been positioned but deeper into the tree
                    //they must be lower than those nodes above, this gets that value and passes it on
                    if (depth > _maxTreeDepth && _depthYMargin.ContainsKey(_maxTreeDepth))
                    {
                        _depthYMargin[depth] = _depthYMargin[_maxTreeDepth];
                        _maxTreeDepth        = depth;
                    }
                    else
                    {
                        _depthYMargin[depth] = MarginFromTop;
                        if (depth > _maxTreeDepth)
                        {
                            _maxTreeDepth = depth;
                        }
                    }
                }
                nodeGroup.ParentNode.MoveNode(new Point(nodeGroup.ParentNode.Location.X, _depthYMargin[depth]), true);
                _depthYMargin[depth] += nodeGroup.ParentNode.NodeControl.ActualHeight + VERTICAL_BUFFER;
            }
            else //is a parent node
            {
                bool firstRow = false;
                for (int i = 0; i < nodeGroup.ParentChildGroups.Count; i++)
                {
                    if (!_depthYMargin.ContainsKey(depth))
                    {
                        firstRow             = true;
                        _depthYMargin[depth] = nodeGroup.ParentNode.NodeControl.ActualHeight + VERTICAL_BUFFER;
                    }
                    else
                    {
                        firstRow = false;
                    }
                    PositionNodes(nodeGroup.ParentChildGroups[i], depth + 1);
                }

                double position = nodeGroup.GetYPosition();

                //if it's not the top most nodes check that it doesn't collide with a row of nodes above it
                if ((position < _depthYMargin[depth] - MarginFromTop) && !firstRow)
                {
                    OffsetNodes(nodeGroup, depth); //collision was detected, move all the nodes from this node to the depth of the tree down
                }
                else
                {
                    nodeGroup.ParentNode.MoveNode(new Point(nodeGroup.ParentNode.Location.X, position), true);
                    _depthYMargin[depth] = position + nodeGroup.ParentNode.NodeControl.ActualHeight + VERTICAL_BUFFER;
                }
            }
        }
        private TreeNodeGroup BuildTreeNodeGroup(NodeRenderer leftMostNode)
        {
            TreeNodeGroup nodeGroup = new TreeNodeGroup();
            nodeGroup.ParentNode = leftMostNode;
            nodeGroup.ChildNodes = GetChildNodeRenderers(leftMostNode);
            nodeGroup.ChildNodes.Sort(new Comparison<NodeRenderer>(NodePositionComparison));
            nodeGroup.ParentChildGroups = new List<TreeNodeGroup>();

            foreach (NodeRenderer nodeRenderer in nodeGroup.ChildNodes)
            {
                TreeNodeGroup childGroup = BuildTreeNodeGroup(nodeRenderer);
                nodeGroup.ParentChildGroups.Add(childGroup);
            }
            return nodeGroup;
        }
        private TreeNodeGroup BuildTreeNodeGroup(NodeRenderer leftMostNode)
        {
            TreeNodeGroup nodeGroup = new TreeNodeGroup();

            nodeGroup.ParentNode = leftMostNode;
            nodeGroup.ChildNodes = GetChildNodeRenderers(leftMostNode);
            nodeGroup.ChildNodes.Sort(new Comparison <NodeRenderer>(NodePositionComparison));
            nodeGroup.ParentChildGroups = new List <TreeNodeGroup>();

            foreach (NodeRenderer nodeRenderer in nodeGroup.ChildNodes)
            {
                TreeNodeGroup childGroup = BuildTreeNodeGroup(nodeRenderer);
                nodeGroup.ParentChildGroups.Add(childGroup);
            }
            return(nodeGroup);
        }
        public void SortLeftToRight()
        {
            lock (_columns)
            {
                _columns.Clear();
                _trees.Clear();

                List <NodeRenderer> leftMostNodes = GetLeftMostNodes();
                leftMostNodes.Sort(new Comparison <NodeRenderer>(NodePositionComparison));
                _columns[1] = leftMostNodes;

                PopulateColumns(2, leftMostNodes, true);

                //position the X coord of each column
                SetNodeXLocations();

                foreach (NodeRenderer leftMostNode in leftMostNodes)
                {
                    TreeNodeGroup treeStructure = BuildTreeNodeGroup(leftMostNode);
                    _trees.Add(treeStructure);
                }

                double marginFromTop = 20; //the margin between the breadcrumb and top of the map
                foreach (TreeNodeGroup treeStructure in _trees)
                {
                    TreeRenderer renderer = new TreeRenderer(marginFromTop);
                    renderer.PositionNodes(treeStructure, 1);
                    marginFromTop = renderer.GetMaximumYPosition();
                }

                //Store the new locations
                foreach (NodeRenderer nodeRenderer in ViewManager.CurrentView.NodeRenderers.Values)
                {
                    nodeRenderer.StoreLocation();
                }
            }
        }
Example #7
0
 /// <summary>
 /// Moves the branch down to the correct levels if a collision was detected when working back down the tree towards the root node.
 /// </summary>
 /// <param name="nodeGroup">The start position (branch of the tree)</param>
 /// <param name="depth">The current node depth</param>
 private void OffsetNodes(TreeNodeGroup nodeGroup, int depth)
 {
     nodeGroup.ParentNode.MoveNode(new Point(nodeGroup.ParentNode.Location.X, _depthYMargin[depth]), true);
     _depthYMargin[depth] = nodeGroup.ParentNode.Location.Y + nodeGroup.ParentNode.NodeControl.ActualHeight + VERTICAL_BUFFER;
     foreach (TreeNodeGroup branchGroup in nodeGroup.ParentChildGroups)
     {
         OffsetNodes(branchGroup, depth+1);
     }
 }