Exemple #1
0
        public void _apportion(LayoutNode node, int level)
        {
            var firstChild             = node._getFirstChild();
            var firstChildLeftNeighbor = firstChild.LeftNeighbor;
            var j = 1;

            for (var k = Config.iMaxDepth - level; firstChild != null && firstChildLeftNeighbor != null && j <= k;)
            {
                double modifierSumRight = 0;
                double modifierSumLeft  = 0;
                var    rightAncestor    = firstChild;
                var    leftAncestor     = firstChildLeftNeighbor;
                for (var l = 0; l < j; l++)
                {
                    rightAncestor     = rightAncestor.Parent;
                    leftAncestor      = leftAncestor.Parent;
                    modifierSumRight += rightAncestor.Modifier;
                    modifierSumLeft  += leftAncestor.Modifier;
                }

                var totalGap = (firstChildLeftNeighbor.Prelim + modifierSumLeft + GetNodeSize(firstChildLeftNeighbor) + Config.iSubtreeSeparation) - (firstChild.Prelim + modifierSumRight);
                if (totalGap > 0)
                {
                    var subtreeAux  = node;
                    var numSubtrees = 0;
                    for (; subtreeAux != null && subtreeAux != leftAncestor; subtreeAux = subtreeAux._getLeftSibling())
                    {
                        numSubtrees++;
                    }

                    if (subtreeAux != null)
                    {
                        var subtreeMoveAux = node;
                        var singleGap      = totalGap / numSubtrees;
                        for (; subtreeMoveAux != leftAncestor; subtreeMoveAux = subtreeMoveAux._getLeftSibling())
                        {
                            subtreeMoveAux.Prelim   += totalGap;
                            subtreeMoveAux.Modifier += totalGap;
                            totalGap -= singleGap;
                        }
                    }
                }
                j++;
                if (firstChild._getChildrenCount() == 0)
                {
                    firstChild = _GetLeftmost(node, 0, j);
                }
                else
                {
                    firstChild = firstChild._getFirstChild();
                }
                if (firstChild != null)
                {
                    firstChildLeftNeighbor = firstChild.LeftNeighbor;
                }
            }
        }
Exemple #2
0
        public void _secondWalk(TreeLayout tree, LayoutNode node, int level, double X, double Y)
        {
            if (level <= tree.Config.iMaxDepth)
            {
                var    xTmp        = tree.RootXOffset + node.Prelim + X;
                var    yTmp        = tree.RootYOffset + Y;
                double maxsizeTmp  = 0;
                double nodesizeTmp = 0;
                var    flag        = false;

                switch (tree.Config.iRootOrientation)
                {
                case TreeLayout.RO_TOP:
                case TreeLayout.RO_BOTTOM:
                    maxsizeTmp  = tree.MaxLevelHeight[level];
                    nodesizeTmp = node.H;
                    break;

                case TreeLayout.RO_RIGHT:
                case TreeLayout.RO_LEFT:
                    maxsizeTmp  = tree.MaxLevelWidth[level];
                    flag        = true;
                    nodesizeTmp = node.W;
                    break;
                }
                switch (tree.Config.iNodeJustification)
                {
                case TreeLayout.NJ_TOP:
                    node.X = xTmp;
                    node.Y = yTmp;
                    break;

                case TreeLayout.NJ_CENTER:
                    node.X = xTmp;
                    node.Y = yTmp + (maxsizeTmp - nodesizeTmp) / 2;
                    break;

                case TreeLayout.NJ_BOTTOM:
                    node.X = xTmp;
                    node.Y = (yTmp + maxsizeTmp) - nodesizeTmp;
                    break;
                }
                if (flag)
                {
                    var swapTmp = node.X;
                    node.X = node.Y;
                    node.Y = swapTmp;
                }
                switch (tree.Config.iRootOrientation)
                {
                case TreeLayout.RO_BOTTOM:
                    node.Y = -node.Y - nodesizeTmp;
                    break;

                case TreeLayout.RO_RIGHT:
                    node.X = -node.X - nodesizeTmp;
                    break;
                }
                if (node._getChildrenCount() != 0)
                {
                    _secondWalk(tree, node._getFirstChild(), level + 1, X + node.Modifier, Y + maxsizeTmp + tree.Config.iLevelSeparation);
                }
                var rightSibling = node._getRightSibling();
                if (rightSibling != null)
                {
                    _secondWalk(tree, rightSibling, level, X, Y);
                }
            }
        }