Free cookie consent management tool by TermsFeed Policy Generator

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

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

File:
1 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    }
Note: See TracChangeset for help on using the changeset viewer.