Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.EvolutionTracking/HeuristicLab.EvolutionTracking.Views/3.4/Primitives/LabeledEllipse.cs @ 10265

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

#1772: Renamed projects from HeuristicLab.EvolutionaryTracking to HeuristicLab.EvolutionTracking

File size: 4.3 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.Visualization;
26
27namespace HeuristicLab.EvolutionaryTracking.Views.Primitives {
28  public class LabeledEllipse : Ellipse, ILayoutNode<ISymbolicExpressionTreeNode> {
29    private string text;
30    public string Text { get { return text; } set { text = value; } }
31
32    private Font font;
33    public Font Font { get { return font; } set { font = value; } }
34
35    private Brush fontBrush;
36    public Brush FontBrush { get { return fontBrush; } set { fontBrush = value; } }
37
38    public LabeledEllipse(IChart chart, PointD lowerLeft, PointD upperRight)
39      : base(chart, lowerLeft, upperRight) {
40      font = new Font(FontFamily.GenericSansSerif, 10);
41    }
42    public LabeledEllipse(IChart chart, double x1, double y1, double x2, double y2)
43      : this(chart, new PointD(x1, y1), new PointD(x2, y2)) {
44    }
45    public LabeledEllipse(IChart chart, PointD lowerLeft, PointD upperRight, Pen pen, Brush brush)
46      : base(chart, lowerLeft, upperRight, pen, brush) {
47      font = new Font(FontFamily.GenericSansSerif, 10);
48    }
49    public LabeledEllipse(IChart chart, double x1, double y1, double x2, double y2, Pen pen, Brush brush)
50      : this(chart, new PointD(x1, y1), new PointD(x2, y2), pen, brush) {
51    }
52
53    public override void Draw(Graphics graphics) {
54      var p = Chart.TransformWorldToPixel(new PointD(LowerLeft.X, LowerLeft.Y));
55      var s = Chart.TransformWorldToPixel(Size);
56      var stringSize = graphics.MeasureString(Text, Font);
57      var fontSize = Font.Size * s.Width / stringSize.Width;
58      if (fontSize > 12) fontSize = 12; // limit maximum font size to 10pt
59      font = new Font(font.Name, fontSize, FontStyle.Regular, GraphicsUnit.Pixel);
60      stringSize = graphics.MeasureString(Text, Font);
61      graphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias;
62      graphics.DrawString(Text, Font, FontBrush, p.X + (s.Width - stringSize.Width) / 2f, p.Y - (s.Height + stringSize.Height) / 2f);
63      base.Draw(graphics);
64    }
65
66    public ILayoutNode<ISymbolicExpressionTreeNode> Thread { get; set; }
67    public ILayoutNode<ISymbolicExpressionTreeNode> Ancestor { get; set; }
68    public ILayoutNode<ISymbolicExpressionTreeNode> Parent { get; set; }
69    public List<ILayoutNode<ISymbolicExpressionTreeNode>> Children { get; set; }
70    public float Mod { get; set; }
71    public float Prelim { get; set; }
72    public float Change { get; set; }
73    public float Shift { get; set; }
74    public int Number { get; set; }
75    public int Level { get; set; }
76    public float X { get; set; }
77    public float Y { get; set; }
78    public bool IsLeaf {
79      get { return Children == null || Children.Count == 0; }
80    }
81    public ILayoutNode<ISymbolicExpressionTreeNode> NextLeft {
82      get {
83        return Children == null ? Thread : Children.First();
84      }
85    }
86    public ILayoutNode<ISymbolicExpressionTreeNode> NextRight {
87      get {
88        return Children == null ? Thread : Children.Last();
89      }
90    }
91    public ILayoutNode<ISymbolicExpressionTreeNode> LeftSibling {
92      get {
93        if (Parent == null) return null;
94        return Number == 0 ? null : Parent.Children[Number - 1];
95      }
96    }
97    public ILayoutNode<ISymbolicExpressionTreeNode> LeftmostSibling {
98      get {
99        if (Parent == null) return null;
100        return Number == 0 ? null : Parent.Children[0];
101      }
102    }
103    public ISymbolicExpressionTreeNode Content { get; set; }
104  }
105}
Note: See TracBrowser for help on using the repository browser.