Free cookie consent management tool by TermsFeed Policy Generator

Changeset 15029 for trunk


Ignore:
Timestamp:
06/08/17 11:43:26 (8 years ago)
Author:
bburlacu
Message:

#2794: Improve centering and add padding. The padding is handled by the SymbolicExpressionTreeChart which asks the layout engine to layout the tree in the remaining area (minus the padding).

Location:
trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views/3.4
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views/3.4/LayoutEngines/ReingoldTilfordLayoutEngine.cs

    r10565 r15029  
    4040      SecondWalk(layoutRoot, -layoutRoot.Prelim);
    4141      NormalizeCoordinates(layoutNodeMap.Values);
    42       if (height != 0 && width != 0) {
     42      if (width > 0 && height > 0) {
    4343        FitToBounds(width, height, layoutNodeMap.Values);
    4444        Center(width, height, layoutNodeMap.Values);
     
    158158        if (ymax < y) ymax = y;
    159159      }
    160       return new RectangleF(xmin, ymin, xmax + minHorizontalSpacing + NodeWidth, ymax + minVerticalSpacing + NodeHeight);
     160      return new RectangleF(xmin, ymin, xmax + NodeWidth, ymax + NodeHeight);
    161161    }
    162162
  • trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views/3.4/SymbolicExpressionTreeChart.cs

    r14185 r15029  
    287287        actualRoot = tree.Root.GetSubtree(0);
    288288      }
    289 
    290       var visualNodes = layoutEngine.CalculateLayout(actualRoot, Width, Height).ToList();
     289      var paddingX = 20; // add 10px padding on each side (left and right)
     290      var paddingY = 20; // add 10px padding on top and bottom
     291      var visualNodes = layoutEngine.CalculateLayout(actualRoot, Width - paddingX, Height - paddingY).ToList();
     292      // add the padding
     293      foreach (var vn in visualNodes) {
     294        vn.X += paddingX / 2;
     295        vn.Y += paddingY / 2;
     296      }
     297
    291298      visualTreeNodes = visualNodes.ToDictionary(x => x.Content, x => x);
    292299      visualLines = new Dictionary<Tuple<ISymbolicExpressionTreeNode, ISymbolicExpressionTreeNode>, VisualTreeNodeConnection>();
     
    321328    }
    322329
     330    private Action<Brush, int, int, int, int> fill;
     331    private Action<Pen, int, int, int, int> draw;
    323332    protected void DrawTreeNode(Graphics graphics, VisualTreeNode<ISymbolicExpressionTreeNode> visualTreeNode) {
    324333      graphics.Clip = new Region(new Rectangle(visualTreeNode.X, visualTreeNode.Y, visualTreeNode.Width + 1, visualTreeNode.Height + 1));
     
    328337      using (var nodeLinePen = new Pen(visualTreeNode.LineColor))
    329338      using (var nodeFillBrush = new SolidBrush(visualTreeNode.FillColor)) {
    330         //draw terminal node
    331         if (node.SubtreeCount == 0) {
    332           graphics.FillRectangle(nodeFillBrush, visualTreeNode.X, visualTreeNode.Y, visualTreeNode.Width, visualTreeNode.Height);
    333           graphics.DrawRectangle(nodeLinePen, visualTreeNode.X, visualTreeNode.Y, visualTreeNode.Width, visualTreeNode.Height);
     339        var x = visualTreeNode.X;
     340        var y = visualTreeNode.Y;
     341        var w = visualTreeNode.Width - 1;  // allow 1px for the drawing of the line
     342        var h = visualTreeNode.Height - 1; // allow 1px for the drawing of the line
     343        // draw leaf nodes as rectangles and internal nodes as ellipses
     344        if (node.SubtreeCount > 0) {
     345          fill = graphics.FillEllipse; draw = graphics.DrawEllipse;
    334346        } else {
    335           graphics.FillEllipse(nodeFillBrush, visualTreeNode.X, visualTreeNode.Y, visualTreeNode.Width, visualTreeNode.Height);
    336           graphics.DrawEllipse(nodeLinePen, visualTreeNode.X, visualTreeNode.Y, visualTreeNode.Width, visualTreeNode.Height);
    337         }
     347          fill = graphics.FillRectangle; draw = graphics.DrawRectangle;
     348        }
     349        fill(nodeFillBrush, x, y, w, h);
     350        draw(nodeLinePen, x, y, w, h);
    338351        //draw name of symbol
    339         var text = node.ToString();
    340         graphics.DrawString(text, textFont, textBrush, new RectangleF(visualTreeNode.X, visualTreeNode.Y, visualTreeNode.Width, visualTreeNode.Height), stringFormat);
     352        graphics.DrawString(node.ToString(), textFont, textBrush, new RectangleF(x, y, w, h), stringFormat);
    341353      }
    342354    }
Note: See TracChangeset for help on using the changeset viewer.