Index: stable/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views/3.4/SymbolicExpressionTreeChart.cs
===================================================================
--- stable/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views/3.4/SymbolicExpressionTreeChart.cs	(revision 14186)
+++ stable/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views/3.4/SymbolicExpressionTreeChart.cs	(revision 15118)
@@ -1,5 +1,5 @@
 ﻿#region License Information
 /* HeuristicLab
- * Copyright (C) 2002-2016 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
+ * Copyright (C) 2002-2017 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
  *
  * This file is part of HeuristicLab.
@@ -37,14 +37,8 @@
     private ILayoutEngine<ISymbolicExpressionTreeNode> layoutEngine;
 
-    private const int preferredNodeWidth = 70;
-    private const int preferredNodeHeight = 46;
-    private int minHorizontalDistance = 30;
-    private int minVerticalDistance = 30;
-
     public SymbolicExpressionTreeChart() {
       InitializeComponent();
       this.image = new Bitmap(Width, Height);
       this.stringFormat = new StringFormat { Alignment = StringAlignment.Center, LineAlignment = StringAlignment.Center };
-      this.spacing = 5;
       this.lineColor = Color.Black;
       this.backgroundColor = Color.White;
@@ -55,8 +49,8 @@
 
       layoutEngine = new ReingoldTilfordLayoutEngine<ISymbolicExpressionTreeNode>(n => n.Subtrees) {
-        NodeWidth = preferredNodeWidth,
-        NodeHeight = preferredNodeHeight,
-        HorizontalSpacing = minHorizontalDistance,
-        VerticalSpacing = minVerticalDistance
+        NodeWidth = PreferredNodeWidth,
+        NodeHeight = PreferredNodeHeight,
+        HorizontalSpacing = MinimumHorizontalDistance,
+        VerticalSpacing = MinimumVerticalDistance
       };
       reingoldTilfordToolStripMenuItem.Checked = true;
@@ -69,10 +63,55 @@
 
     #region Public properties
-    private int spacing;
-    public int Spacing {
-      get { return this.spacing; }
-      set {
-        this.spacing = value;
-        this.Repaint();
+    private int preferredNodeWidth = 70;
+    public int PreferredNodeWidth {
+      get { return preferredNodeWidth; }
+      set {
+        preferredNodeWidth = value;
+        Repaint();
+      }
+    }
+
+    private int preferredNodeHeight = 46;
+    public int PreferredNodeHeight {
+      get { return preferredNodeHeight; }
+      set {
+        preferredNodeHeight = value;
+        Repaint();
+      }
+    }
+
+    private int minHorizontalDistance = 30;
+    public int MinimumHorizontalDistance {
+      get { return minHorizontalDistance; }
+      set {
+        minHorizontalDistance = value;
+        Repaint();
+      }
+    }
+
+    private int minVerticalDistance = 30;
+    public int MinimumVerticalDistance {
+      get { return minVerticalDistance; }
+      set {
+        minVerticalDistance = value;
+        Repaint();
+      }
+    }
+
+    private int minHorizontalPadding = 20;
+    public int MinimumHorizontalPadding {
+      get { return minHorizontalPadding; }
+      set {
+        minHorizontalPadding = value;
+        Repaint();
+      }
+    }
+
+    private int minVerticalPadding = 20;
+    public int MinimumVerticalPadding {
+      get { return minVerticalPadding; }
+      set {
+        minVerticalPadding = value;
+        Repaint();
       }
     }
@@ -186,5 +225,5 @@
         graphics.Clear(backgroundColor);
         if (tree != null) {
-          DrawFunctionTree(graphics, preferredNodeWidth, preferredNodeHeight, minHorizontalDistance, minVerticalDistance);
+          DrawFunctionTree(graphics, PreferredNodeWidth, PreferredNodeHeight, MinimumHorizontalDistance, MinimumVerticalDistance);
         }
       }
@@ -287,6 +326,11 @@
         actualRoot = tree.Root.GetSubtree(0);
       }
-
-      var visualNodes = layoutEngine.CalculateLayout(actualRoot, Width, Height).ToList();
+      var visualNodes = layoutEngine.CalculateLayout(actualRoot, Width - MinimumHorizontalPadding, Height - MinimumVerticalPadding).ToList();
+      // add the padding
+      foreach (var vn in visualNodes) {
+        vn.X += MinimumHorizontalPadding / 2;
+        vn.Y += MinimumVerticalPadding / 2;
+      }
+
       visualTreeNodes = visualNodes.ToDictionary(x => x.Content, x => x);
       visualLines = new Dictionary<Tuple<ISymbolicExpressionTreeNode, ISymbolicExpressionTreeNode>, VisualTreeNodeConnection>();
@@ -321,4 +365,6 @@
     }
 
+    private Action<Brush, int, int, int, int> fill;
+    private Action<Pen, int, int, int, int> draw;
     protected void DrawTreeNode(Graphics graphics, VisualTreeNode<ISymbolicExpressionTreeNode> visualTreeNode) {
       graphics.Clip = new Region(new Rectangle(visualTreeNode.X, visualTreeNode.Y, visualTreeNode.Width + 1, visualTreeNode.Height + 1));
@@ -328,15 +374,18 @@
       using (var nodeLinePen = new Pen(visualTreeNode.LineColor))
       using (var nodeFillBrush = new SolidBrush(visualTreeNode.FillColor)) {
-        //draw terminal node
-        if (node.SubtreeCount == 0) {
-          graphics.FillRectangle(nodeFillBrush, visualTreeNode.X, visualTreeNode.Y, visualTreeNode.Width, visualTreeNode.Height);
-          graphics.DrawRectangle(nodeLinePen, visualTreeNode.X, visualTreeNode.Y, visualTreeNode.Width, visualTreeNode.Height);
+        var x = visualTreeNode.X;
+        var y = visualTreeNode.Y;
+        var w = visualTreeNode.Width - 1;  // allow 1px for the drawing of the line
+        var h = visualTreeNode.Height - 1; // allow 1px for the drawing of the line
+        // draw leaf nodes as rectangles and internal nodes as ellipses
+        if (node.SubtreeCount > 0) {
+          fill = graphics.FillEllipse; draw = graphics.DrawEllipse;
         } else {
-          graphics.FillEllipse(nodeFillBrush, visualTreeNode.X, visualTreeNode.Y, visualTreeNode.Width, visualTreeNode.Height);
-          graphics.DrawEllipse(nodeLinePen, visualTreeNode.X, visualTreeNode.Y, visualTreeNode.Width, visualTreeNode.Height);
-        }
+          fill = graphics.FillRectangle; draw = graphics.DrawRectangle;
+        }
+        fill(nodeFillBrush, x, y, w, h);
+        draw(nodeLinePen, x, y, w, h);
         //draw name of symbol
-        var text = node.ToString();
-        graphics.DrawString(text, textFont, textBrush, new RectangleF(visualTreeNode.X, visualTreeNode.Y, visualTreeNode.Width, visualTreeNode.Height), stringFormat);
+        graphics.DrawString(node.ToString(), textFont, textBrush, new RectangleF(x, y, w, h), stringFormat);
       }
     }
@@ -367,5 +416,5 @@
       Image image = new Bitmap(Width, Height);
       using (Graphics g = Graphics.FromImage(image)) {
-        DrawFunctionTree(g, preferredNodeWidth, preferredNodeHeight, minHorizontalDistance, minVerticalDistance, false);
+        DrawFunctionTree(g, PreferredNodeWidth, PreferredNodeHeight, MinimumHorizontalDistance, MinimumVerticalDistance, false);
       }
       image.Save(filename);
@@ -377,5 +426,5 @@
         using (Metafile file = new Metafile(filename, g.GetHdc())) {
           using (Graphics emfFile = Graphics.FromImage(file)) {
-            DrawFunctionTree(emfFile, preferredNodeWidth, preferredNodeHeight, minHorizontalDistance, minVerticalDistance, false);
+            DrawFunctionTree(emfFile, PreferredNodeWidth, PreferredNodeHeight, MinimumHorizontalDistance, MinimumVerticalDistance, false);
           }
         }
@@ -398,11 +447,9 @@
 
     private void reingoldTilfordToolStripMenuItem_Click(object sender, EventArgs e) {
-      minHorizontalDistance = 30;
-      minVerticalDistance = 30;
       layoutEngine = new ReingoldTilfordLayoutEngine<ISymbolicExpressionTreeNode>(n => n.Subtrees) {
-        NodeWidth = preferredNodeWidth,
-        NodeHeight = preferredNodeHeight,
-        HorizontalSpacing = minHorizontalDistance,
-        VerticalSpacing = minVerticalDistance
+        NodeWidth = PreferredNodeWidth,
+        NodeHeight = PreferredNodeHeight,
+        HorizontalSpacing = MinimumHorizontalDistance,
+        VerticalSpacing = MinimumVerticalDistance
       };
       reingoldTilfordToolStripMenuItem.Checked = true;
@@ -412,11 +459,9 @@
 
     private void boxesToolStripMenuItem_Click(object sender, EventArgs e) {
-      minHorizontalDistance = 5;
-      minVerticalDistance = 5;
       layoutEngine = new BoxesLayoutEngine<ISymbolicExpressionTreeNode>(n => n.Subtrees, n => n.GetLength(), n => n.GetDepth()) {
-        NodeWidth = preferredNodeWidth,
-        NodeHeight = preferredNodeHeight,
-        HorizontalSpacing = minHorizontalDistance,
-        VerticalSpacing = minVerticalDistance
+        NodeWidth = PreferredNodeWidth,
+        NodeHeight = PreferredNodeHeight,
+        HorizontalSpacing = MinimumHorizontalDistance,
+        VerticalSpacing = MinimumVerticalDistance
       };
       reingoldTilfordToolStripMenuItem.Checked = false;
