/// <summary>
 /// Adds a new tree to the list of trees to draw.
 /// </summary>
 /// <param name="tree">the tree to add</param>
 public void AddTree(AbstractTree tree)
 {
     if (tree.maxValue > this.maxValue || this.trees.Count == 0) {
         this.maxValue = tree.maxValue; }
     if (tree.minValue < this.minValue || this.trees.Count == 0) {
         this.minValue = tree.minValue; }
     this.trees.Add(tree);
     this.DrawTrees();
 }
Exemplo n.º 2
0
        /// <summary>
        /// Draw a particular join tree.
        /// </summary>
        /// <param name="tree">the tree to draw</param>
        /// <param name="graphics">allows things to be drawn</param>
        /// <param name="pen">for drawing lines</param>
        /// <param name="nodeFill">for drawing nodes</param>
        protected override void drawTree(AbstractTree tree, Graphics graphics, Pen pen, Brush nodeFill)
        {
            int   nrSlotsNeeded = tree.GetNumSlotsNeeded();
            float pixelsPerSlot = this.GetPixelsPerSlot(nrSlotsNeeded);
            float screenCenterX = this.Width / 2.0f;
            float half_Diameter = NODE_DIAMETER / 2.0f;

            int leftSlotsUsed = 0;
            int rightSlotsUsed = 0;

            // draw the top node
            graphics.FillEllipse(nodeFill, screenCenterX - half_Diameter, this.ValueToYCoordinate(tree.maxValue) - half_Diameter, NODE_DIAMETER, NODE_DIAMETER);

            TreeNode currentTrunkNode = tree.GetParentless()[0];
            int      currentDirection = -1;

            while (currentTrunkNode.GetChildren().Count > 0) {
                // look ahead at next trunk node
                TreeNode nextTrunkNode = currentTrunkNode.GetChildren()[0];

                // draw next node
                graphics.FillEllipse(nodeFill, screenCenterX - half_Diameter, this.ValueToYCoordinate(nextTrunkNode.value) - half_Diameter, NODE_DIAMETER, NODE_DIAMETER);

                // draw path to next trunk node
                graphics.DrawLine(pen, screenCenterX, this.ValueToYCoordinate(currentTrunkNode.value),
                                       screenCenterX, this.ValueToYCoordinate(   nextTrunkNode.value));

                // make a list of branches from the next trunk node
                List<TreeNode> branches = new List<TreeNode>(nextTrunkNode.GetParents());

                // remove the trunk node from the list of branches
                branches.Remove(currentTrunkNode);

                foreach (TreeNode branch in branches) {
                    drawBranch(branch, graphics, pen, nodeFill, currentDirection, currentDirection == -1 ? leftSlotsUsed : rightSlotsUsed, pixelsPerSlot, screenCenterX);
                    if (currentDirection == -1) {
                        leftSlotsUsed += branch.GetNumParentlessAncestors(); }
                    else {
                        rightSlotsUsed += branch.GetNumParentlessAncestors(); }
                }

                // toggle direction
                currentDirection *= -1;

                // point at next trunk node
                currentTrunkNode = nextTrunkNode;
            }
        }
 /// <summary>
 /// Draw one particular tree.
 /// </summary>
 /// <param name="tree">the tree to draw</param>
 /// <param name="graphics">allows things to be drawn</param>
 /// <param name="pen">for drawing lines</param>
 /// <param name="nodeFill">for drawing nodes</param>
 protected abstract void drawTree(AbstractTree tree, Graphics graphics, Pen pen, Brush nodeFill);