Free cookie consent management tool by TermsFeed Policy Generator

Changeset 10797


Ignore:
Timestamp:
05/05/14 17:04:25 (11 years ago)
Author:
bburlacu
Message:

#1772: Added text labels to SymbolicExpressionTreeTiles so that the generation number is also displayed.

Location:
branches/HeuristicLab.EvolutionTracking
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/HeuristicLab.EvolutionTracking/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views/3.4/SymbolicExpressionTreeTile.cs

    r10752 r10797  
    2424using System.Drawing;
    2525using System.Drawing.Drawing2D;
     26using System.Drawing.Text;
    2627using System.Linq;
    2728using HeuristicLab.Common;
     
    3839    public int PreferredNodeWidth { get; set; }
    3940    public int PreferredNodeHeight { get; set; }
     41
     42    private const int labelHeight = 30;
     43
    4044    public ReingoldTilfordLayoutEngine<ISymbolicExpressionTreeNode> LayoutEngine { get; set; }
    4145    private readonly Dictionary<IPrimitive, ISymbolicExpressionTreeNode> primitivesToNodes;
    4246    private readonly Dictionary<ISymbolicExpressionTreeNode, IPrimitive> nodesToPrimitives;
     47
     48    private string label;
     49    public string Label {
     50      get { return label; }
     51      set { label = value; }
     52    }
    4353
    4454    private Size size;
     
    142152
    143153        RectangularPrimitiveBase rectangularPrimitive;
    144         var label = ShortenLabel(node);
     154        var shortenedLabel = ShortenLabel(node);
    145155        if (node.SubtreeCount == 0) {
    146           rectangularPrimitive = new Rectangle(Chart, lowerLeft, upperRight) { Font = font, Text = label };
     156          rectangularPrimitive = new Rectangle(Chart, lowerLeft, upperRight) { Font = font, Text = shortenedLabel };
    147157        } else {
    148           rectangularPrimitive = new Ellipse(Chart, lowerLeft, upperRight) { Font = font, Text = label };
     158          rectangularPrimitive = new Ellipse(Chart, lowerLeft, upperRight) { Font = font, Text = shortenedLabel };
    149159        }
    150160
     
    174184        if (ymax < rpb.UpperRight.Y) ymax = (int)Math.Ceiling(rpb.UpperRight.Y);
    175185      }
    176       Size = new Size(xmax - xmin, ymax - ymin);
    177       var width = Size.Width;
    178       var height = Size.Height;
     186      int width = xmax - xmin;
     187      int height = ymax - ymin;
     188
     189      // draw a primitive to display the label
     190      var labelRect = new Rectangle(this.Chart, new PointD(0, height), new PointD(width, height + labelHeight)) {
     191        Pen = new Pen(Color.Black),
     192        Brush = new SolidBrush(Color.Transparent),
     193        Text = Label,
     194        Font = new Font(FontFamily.GenericSansSerif, 12)
     195      };
     196      this.Add(labelRect);
     197
    179198      // draw a rectangle to mark the countour of this tile
    180       var rectangle = new Rectangle(this.Chart, new PointD(0, 0), new PointD(width, height)) {
     199      Size = new Size(width, height + labelHeight);
     200
     201      var rectangle = new Rectangle(this.Chart, new PointD(0, 0), new PointD(Size.Width, Size.Height)) {
    181202        Pen = new Pen(Color.Gray),
    182203        Brush = new SolidBrush(Color.Transparent)
     
    188209        var rpb = primitive as RectangularPrimitiveBase;
    189210        if (rpb != null) {
    190           rpb.SetPosition(rpb.LowerLeft.X, height - rpb.UpperRight.Y, rpb.UpperRight.X, height - rpb.LowerLeft.Y);
     211          rpb.SetPosition(rpb.LowerLeft.X, Size.Height - rpb.UpperRight.Y, rpb.UpperRight.X, Size.Height - rpb.LowerLeft.Y);
    191212
    192213        } else {
    193214          var line = primitive as LinearPrimitiveBase;
    194215          if (line != null) {
    195             line.SetPosition(line.Start.X, height - line.Start.Y, line.End.X, height - line.End.Y);
     216            line.SetPosition(line.Start.X, Size.Height - line.Start.Y, line.End.X, Size.Height - line.End.Y);
    196217          }
    197218        }
     
    201222    public override void Draw(Graphics graphics) {
    202223      graphics.SmoothingMode = SmoothingMode.HighQuality;
     224      graphics.TextRenderingHint = TextRenderingHint.AntiAlias;
    203225      base.Draw(graphics);
    204226    }
  • branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic.Views/3.4/Tracking/FragmentGraphView.cs

    r10755 r10797  
    22using System.Drawing;
    33using System.Linq;
    4 using HeuristicLab.Common;
    54using HeuristicLab.Core.Views;
    65using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
     
    5150        var tile = new SymbolicExpressionTreeTile(chart);
    5251        tile.LayoutEngine = symbolicExpressionEngine;
     52        tile.Label = "Generation " + node.Rank;
    5353        tile.Root = node.Content.Root;
    5454        var tileNode = new TileLayoutNode { Tile = tile };
     
    9494        var aPos = aTile.Position;
    9595
    96         if (node.Rank.IsAlmost(0)) {
    97           foreach (var s in node.Content.Root.IterateNodesPrefix()) {
     96        if (node.Content.Index1 > 0) {
     97          var subtree = node.Content.Root.NodeAt(node.Content.Index1);
     98          foreach (var s in subtree.IterateNodesPrefix()) {
    9899            var primitive = aTile.GetPrimitive(s);
    99100            if (primitive != null) {
    100101              var rpb = primitive as RectangularPrimitiveBase;
    101102              if (rpb != null) {
    102                 rpb.Pen = new Pen(Color.ForestGreen);
    103               }
    104             }
    105           }
    106         } else {
    107 
    108           if (node.Content.Index1 > 0) {
    109             var subtree = node.Content.Root.NodeAt(node.Content.Index1);
    110             foreach (var s in subtree.IterateNodesPrefix()) {
    111               var primitive = aTile.GetPrimitive(s);
    112               if (primitive != null) {
    113                 var rpb = primitive as RectangularPrimitiveBase;
    114                 if (rpb != null) {
    115                   rpb.Pen = new Pen(Color.RoyalBlue);
    116                 }
     103                rpb.Pen = new Pen(Color.RoyalBlue);
    117104              }
    118105            }
  • branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Tracking/SymbolicDataAnalysisExpressionTracing.cs

    r10755 r10797  
    8686            }
    8787            var right = Trace(node.Parents.Last(), fragment.Index2, fragmentNode); // trace fragment
    88             foreach (var v in left.Concat(right)) {
    89               yield return v;
    90             }
     88            foreach (var v in left.Concat(right)) { yield return v; }
    9189            break;
    9290          } else {
Note: See TracChangeset for help on using the changeset viewer.