Exemple #1
0
 void _setLevelWidth(LayoutNode node, int level)
 {
     if (this.MaxLevelWidth[level] < node.W)
     {
         this.MaxLevelWidth[level] = node.W;
     }
 }
Exemple #2
0
        public void CreateNode(string id, object element, double w, double h)
        {
            var node = new LayoutNode(this, id, element, w, h); //New node creation...

            NodeMap[id] = node;
            Nodes.Add(node);
        }
Exemple #3
0
        LayoutNode _GetLeftmost(LayoutNode node, int level, int maxlevel)
        {
            if (level >= maxlevel)
            {
                return(node);
            }
            if (node._getChildrenCount() == 0)
            {
                return(null);
            }

            var n = node._getChildrenCount();

            for (var i = 0; i < n; i++)
            {
                var iChild             = node._getChildAt(i);
                var leftmostDescendant = this._GetLeftmost(iChild, level + 1, maxlevel);
                if (leftmostDescendant != null)
                {
                    return(leftmostDescendant);
                }
            }

            return(null);
        }
Exemple #4
0
 void _setLevelHeight(LayoutNode node, int level)
 {
     if (this.MaxLevelHeight[level] < node.H)
     {
         this.MaxLevelHeight[level] = node.H;
     }
 }
Exemple #5
0
        public double _getChildrenCenter(TreeLayout tree)
        {
            LayoutNode node  = this._getFirstChild();
            LayoutNode node1 = this._getLastChild();

            return(node.Prelim + ((node1.Prelim - node.Prelim) + tree.GetNodeSize(node1)) / 2);
        }
Exemple #6
0
 //
 public LayoutEdge(TreeLayout tree, LayoutNode source, LayoutNode target, object element)
 {
     Tree    = tree;
     Source  = source;
     Target  = target;
     Element = element;
 }
Exemple #7
0
 void _setNeighbors(LayoutNode node, int level)
 {
     node.LeftNeighbor = this.PreviousLevelNode[level];
     if (node.LeftNeighbor != null)
     {
         node.LeftNeighbor.RightNeighbor = node;
     }
     this.PreviousLevelNode[level] = node;
 }
Exemple #8
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 #9
0
        //TODO:Delete this one?
        public void CollapseNode(string nodeid, bool upd)
        {
            LayoutNode node = NodeMap[nodeid];

            node.Collapsed = !node.Collapsed;
            if (upd)
            {
                UpdateTree();
            }
        }
Exemple #10
0
        public void ToggleChildrenVisibility(string nodeid, bool upd)
        {
            LayoutNode node = NodeMap[nodeid];

            node.ToggleChildren();
            if (upd)
            {
                UpdateTree();
            }
        }
Exemple #11
0
        void _CollapseAllInt(bool flag)
        {
            LayoutNode node = null;

            for (var n = 0; n < this.Nodes.Count; n++)
            {
                node = this.Nodes[n];
                if (node.CanCollapse)
                {
                    node.Collapsed = flag;
                }
            }
            this.UpdateTree();
        }
Exemple #12
0
        public double GetNodeSize(LayoutNode node)
        {
            switch (this.Config.iRootOrientation)
            {
            case TreeLayout.RO_TOP:
            case TreeLayout.RO_BOTTOM:
                return(node.W);

            case TreeLayout.RO_RIGHT:
            case TreeLayout.RO_LEFT:
                return(node.H);
            }
            return(0);
        }
Exemple #13
0
        //Layout algorithm
        public void FirstWalk(LayoutNode node, int level)
        {
            LayoutNode leftSibling = null;

            node.X             = 0;
            node.Y             = 0;
            node.Prelim        = 0;
            node.Modifier      = 0;
            node.LeftNeighbor  = null;
            node.RightNeighbor = null;
            _setLevelHeight(node, level);
            _setLevelWidth(node, level);
            _setNeighbors(node, level);
            if (node._getChildrenCount() == 0 || level == Config.iMaxDepth)
            {
                leftSibling = node._getLeftSibling();
                if (leftSibling != null)
                {
                    node.Prelim = leftSibling.Prelim + GetNodeSize(leftSibling) + Config.iSiblingSeparation;
                }
                else
                {
                    node.Prelim = 0;
                }
            }
            else
            {
                var n = node._getChildrenCount();
                for (var i = 0; i < n; i++)
                {
                    var iChild = node._getChildAt(i);
                    FirstWalk(iChild, level + 1);
                }

                var midPoint = node._getChildrenCenter(this);
                midPoint   -= GetNodeSize(node) / 2;
                leftSibling = node._getLeftSibling();
                if (leftSibling != null)
                {
                    node.Prelim   = leftSibling.Prelim + GetNodeSize(leftSibling) + Config.iSiblingSeparation;
                    node.Modifier = node.Prelim - midPoint;
                    _apportion(node, level);
                }
                else
                {
                    node.Prelim = midPoint;
                }
            }
        }
Exemple #14
0
        public List <LayoutNode> GetSelectedNodes()
        {
            LayoutNode        node      = null;
            List <LayoutNode> selection = new List <LayoutNode>();
            LayoutNode        selnode   = null;

            for (var n = 0; n < this.Nodes.Count; n++)
            {
                node = this.Nodes[n];
                if (node.IsSelected)
                {
                    selnode = node;
                    selection[selection.Count] = selnode;
                }
            }
            return(selection);
        }
Exemple #15
0
        public void CreateEdge(string srcId, string tgtId, object element)
        {
            LayoutNode source = NodeMap[srcId];

            if (source.Parent == null)
            {
                Root = source;
            }
            source.CanCollapse = true;
            LayoutNode target = NodeMap[tgtId];

            target.Parent = source;
            source.Children.Add(target);
            LayoutEdge edge = new LayoutEdge(this, source, target, element);

            source.Edges.Add(edge);
            Edges.Add(edge);
        }
Exemple #16
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);
                }
            }
        }