Free cookie consent management tool by TermsFeed Policy Generator

Changeset 9993 for branches


Ignore:
Timestamp:
09/19/13 14:24:47 (11 years ago)
Author:
bburlacu
Message:

#2076: Improved tree aspect by calculating maximum visual node width per level.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/HeuristicLab.ReingoldTilfordTreeLayout/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views/3.4/SymbolicExpressionTreeChart.cs

    r9970 r9993  
    277277      layoutEngine.CalculateLayout();
    278278      var bounds = layoutEngine.Bounds();
    279       double sx = this.Width / bounds.Width;
     279      double sx = this.Width / (bounds.Width + preferredWidth);
    280280      if (sx > 1) sx = 1;
    281       double sy = this.Height / bounds.Height;
     281      double sy = this.Height / (bounds.Height + preferredHeight);
    282282      if (sy > 1) sy = 1;
    283       double dx = (this.Width - bounds.Width) / 2;
     283      double dx = (this.Width - bounds.Width + preferredWidth) / 2;
    284284      if (dx < 0) dx = 0;
    285       double dy = (this.Height - bounds.Height) / 2;
     285      double dy = (this.Height - bounds.Height + preferredHeight) / 2;
    286286      if (dy < 0) dy = 0;
    287       var levels = layoutEngine.Nodes.GroupBy(n => n.Value.Level, n => n.Value);
     287
     288      var levels = layoutNodes.GroupBy(n => n.Level, n => n);
    288289
    289290      foreach (var level in levels) {
    290         double width = (level.Max(n => n.X) - level.Min(n => n.X) + preferredWidth);
    291         double ssx = this.Width / width;
    292         if (ssx > 1) ssx = 1;
     291        var nodes = level.ToList();
     292        double min = 0;
     293        for (int i = 0; i < nodes.Count - 1; ++i) {
     294          var w = (nodes[i + 1].X - nodes[i].X) * sx - preferredWidth;
     295          if (w < min) min = w;
     296        }
     297        if (min > 0) min = 0;
     298
    293299        foreach (var layoutNode in level) {
    294           var node = layoutNode.Content;
    295           var visualNode = visualTreeNodes[node];
    296           visualNode.Width = (int)Math.Round(preferredWidth * ssx);
     300          var visualNode = visualTreeNodes[layoutNode.Content];
     301          visualNode.Width = (int)Math.Round(preferredWidth + min) - 2; // -2 to allow enough padding (1px on each side) for the node contour to be drawn
    297302          visualNode.Height = (int)Math.Round(preferredHeight * sy);
    298303          visualNode.X = (int)(Math.Round(layoutNode.X * sx + dx));
     
    301306        }
    302307      }
     308
    303309      graphics.ResetClip(); // reset clip region
     310      // draw node connections
    304311      foreach (var visualNode in visualTreeNodes.Values) {
    305312        var node = visualNode.SymbolicExpressionTreeNode;
Note: See TracChangeset for help on using the changeset viewer.