Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.EvolutionaryTracking/HeuristicLab.EvolutionaryTracking.Views/3.4/Primitives/LabeledEllipse.cs @ 11598

Last change on this file since 11598 was 9963, checked in by bburlacu, 11 years ago

#1772: Merged changes from the trunk and other branches. Added new ExtendedSymbolicExpressionTreeCanvas control for the visual exploration of tree genealogies. Reorganized some files and folders.

File size: 4.4 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2013 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
4 *
5 * This file is part of HeuristicLab.
6 *
7 * HeuristicLab is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * HeuristicLab is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
19 */
20#endregion
21
22using System.Collections.Generic;
23using System.Drawing;
24using System.Linq;
25using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
26using HeuristicLab.Visualization;
27
28namespace HeuristicLab.EvolutionaryTracking.Views {
29  public class LabeledEllipse : Ellipse, ILayoutNode<ISymbolicExpressionTreeNode> {
30    private string text;
31    public string Text { get { return text; } set { text = value; } }
32
33    private Font font;
34    public Font Font { get { return font; } set { font = value; } }
35
36    private Brush fontBrush;
37    public Brush FontBrush { get { return fontBrush; } set { fontBrush = value; } }
38
39    public LabeledEllipse(IChart chart, PointD lowerLeft, PointD upperRight)
40      : base(chart, lowerLeft, upperRight) {
41      font = new Font(FontFamily.GenericSansSerif, 10);
42    }
43    public LabeledEllipse(IChart chart, double x1, double y1, double x2, double y2)
44      : this(chart, new PointD(x1, y1), new PointD(x2, y2)) {
45    }
46    public LabeledEllipse(IChart chart, PointD lowerLeft, PointD upperRight, Pen pen, Brush brush)
47      : base(chart, lowerLeft, upperRight, pen, brush) {
48      font = new Font(FontFamily.GenericSansSerif, 10);
49    }
50    public LabeledEllipse(IChart chart, double x1, double y1, double x2, double y2, Pen pen, Brush brush)
51      : this(chart, new PointD(x1, y1), new PointD(x2, y2), pen, brush) {
52    }
53
54    public override void Draw(Graphics graphics) {
55      var p = Chart.TransformWorldToPixel(new PointD(LowerLeft.X, LowerLeft.Y));
56      var s = Chart.TransformWorldToPixel(Size);
57      var stringSize = graphics.MeasureString(Text, Font);
58      var fontSize = Font.Size * s.Width / stringSize.Width;
59      if (fontSize > 12) fontSize = 12; // limit maximum font size to 10pt
60      font = new Font(font.Name, fontSize, FontStyle.Regular, GraphicsUnit.Pixel);
61      stringSize = graphics.MeasureString(Text, Font);
62      graphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias;
63      graphics.DrawString(Text, Font, FontBrush, p.X + (s.Width - stringSize.Width) / 2f, p.Y - (s.Height + stringSize.Height) / 2f);
64      base.Draw(graphics);
65    }
66
67    public ILayoutNode<ISymbolicExpressionTreeNode> Thread { get; set; }
68    public ILayoutNode<ISymbolicExpressionTreeNode> Ancestor { get; set; }
69    public ILayoutNode<ISymbolicExpressionTreeNode> Parent { get; set; }
70    public List<ILayoutNode<ISymbolicExpressionTreeNode>> Children { get; set; }
71    public float Mod { get; set; }
72    public float Prelim { get; set; }
73    public float Change { get; set; }
74    public float Shift { get; set; }
75    public int Number { get; set; }
76    public int Level { get; set; }
77    public float X { get; set; }
78    public float Y { get; set; }
79    public bool IsLeaf {
80      get { return Children == null || Children.Count == 0; }
81    }
82    public ILayoutNode<ISymbolicExpressionTreeNode> NextLeft {
83      get {
84        return Children == null ? Thread : Children.First();
85      }
86    }
87    public ILayoutNode<ISymbolicExpressionTreeNode> NextRight {
88      get {
89        return Children == null ? Thread : Children.Last();
90      }
91    }
92    public ILayoutNode<ISymbolicExpressionTreeNode> LeftSibling {
93      get {
94        if (Parent == null) return null;
95        return Number == 0 ? null : Parent.Children[Number - 1];
96      }
97    }
98    public ILayoutNode<ISymbolicExpressionTreeNode> LeftmostSibling {
99      get {
100        if (Parent == null) return null;
101        return Number == 0 ? null : Parent.Children[0];
102      }
103    }
104    public ISymbolicExpressionTreeNode Content { get; set; }
105  }
106}
Note: See TracBrowser for help on using the repository browser.