Esempio n. 1
0
        private TreeNode <NodeData> BuildTree(CladogramNode cladogramRoot)
        {
            TreeNode <NodeData> root = cladogramRoot.Copy(cladogramNodeData => new NodeData {
                Data = cladogramNodeData
            });

            using (Font font = GetFont()) {
                // Measure the size of each node.

                float horizontalPadding = 5.0f;

                root.PostOrderTraverse(node => {
                    SizeF size = DrawingUtilities.MeasureText(StringUtilities.StripMarkup(TaxonFormatter.GetString(node.Value.Data.Species)), font);

                    node.Value.Bounds = new RectangleF(node.Value.Bounds.X, node.Value.Bounds.Y, size.Width + horizontalPadding, size.Height);
                });

                // Calculate node positions.

                CalculateNodePositions(root);

                // Calculate the size of the tree.

                RectangleF bounds = CalculateTreeBounds(root);

                // Shift the tree so that the entire thing is visible.

                float minX = 0.0f;

                root.PostOrderTraverse(node => {
                    if (node.Value.Bounds.X < minX)
                    {
                        minX = bounds.X;
                    }
                });

                ShiftTree(root, -minX, 0.0f);

                return(root);
            }
        }
 public AncestryTreeTextRenderer(CladogramNode tree)
 {
     Tree = tree;
 }