Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.EvolutionaryTracking/HeuristicLab.EvolutionaryTracking.Views/3.4/VisualGenealogyGraphNode.cs @ 8236

Last change on this file since 8236 was 8236, checked in by bburlacu, 12 years ago

#1772: Refactored code in the GenealogyGraphChart and the SymbolicExpressionTreeGenealogyAnalyzer. Used gradient from HeuristicLab.Common to color the graph nodes.

File size: 4.1 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2010 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;
23using System.Collections.Generic;
24using System.Drawing;
25using HeuristicLab.Common;
26using HeuristicLab.Visualization;
27
28namespace HeuristicLab.EvolutionaryTracking.Views {
29  public class VisualGenealogyGraphNode : Ellipse {
30    public GenealogyGraphNode Data { get; internal set; }
31    private List<VisualGenealogyGraphArc> _incomingArcs = new List<VisualGenealogyGraphArc>();
32    private List<VisualGenealogyGraphArc> _outgoingArgs = new List<VisualGenealogyGraphArc>();
33
34    public List<VisualGenealogyGraphArc> IncomingArcs {
35      get { return _incomingArcs; }
36      set { _incomingArcs = value; }
37    }
38    public List<VisualGenealogyGraphArc> OutgoingArcs {
39      get { return _outgoingArgs; }
40      set { _outgoingArgs = value; }
41    }
42
43    public VisualGenealogyGraphNode(IChart chart, PointD lowerLeft, PointD upperRight)
44      : base(chart, lowerLeft, upperRight) {
45    }
46    public VisualGenealogyGraphNode(IChart chart, double x1, double y1, double x2, double y2)
47      : this(chart, new PointD(x1, y1), new PointD(x2, y2)) {
48    }
49    public VisualGenealogyGraphNode(IChart chart, PointD lowerLeft, PointD upperRight, Pen pen, Brush brush)
50      : base(chart, lowerLeft, upperRight, pen, brush) {
51    }
52    public VisualGenealogyGraphNode(IChart chart, double x1, double y1, double x2, double y2, Pen pen, Brush brush)
53      : this(chart, new PointD(x1, y1), new PointD(x2, y2), pen, brush) {
54    }
55
56    // compute the intersection point of an ellipse and a line passing through its center with the angular coordinate theta
57    public PointD CalculateIntersection(double theta) {
58      double sin = Math.Sin(theta);
59      double cos = Math.Cos(theta);
60      double a = Size.Width / 2;
61      double b = Size.Height / 2;
62      double r = a * b / Math.Sqrt(Math.Pow(a * sin, 2) + Math.Pow(b * cos, 2)); // radius at intersection point
63      double rx = r * cos; // X-component (relative to the origin/center of the ellipse)
64      double ry = r * sin; // Y-component (relative to the origin/center of the ellipse)
65      return new PointD(rx, ry);
66    }
67
68    public override void SetPosition(PointD lowLeft, PointD upRight) {
69      base.SetPosition(lowLeft, upRight);
70      foreach (var a in IncomingArcs) a.UpdatePosition();
71      foreach (var a in OutgoingArcs) a.UpdatePosition();
72    }
73
74    public PointD Center {
75      get { return new PointD((LowerLeft.X + UpperRight.X) / 2, (LowerLeft.Y + UpperRight.Y) / 2); }
76    }
77
78    public Color ToColor() {
79      //      return Color.FromArgb((int)((1 - Data.Quality) * 255), (int)(Data.Quality * 255), 0);
80      int i = (int)(Data.Quality * ColorGradient.Colors.Count);
81      if (i == ColorGradient.Colors.Count) --i;
82      return ColorGradient.Colors[i];
83    }
84
85    public override void Draw(Graphics graphics) {
86      if (Data.IsElite) {
87        Point p = Chart.TransformWorldToPixel(new PointD(LowerLeft.X, LowerLeft.Y + Size.Height));
88        Size s = Chart.TransformWorldToPixel(Size);
89        if (Brush != null)
90          graphics.FillEllipse(Brush, p.X, p.Y, s.Width, s.Height);
91        graphics.DrawEllipse(Pen, p.X, p.Y, s.Width, s.Height);
92        graphics.DrawEllipse(Pen, p.X + 2, p.Y + 2, s.Width - 4, s.Height - 4);
93      } else {
94        base.Draw(graphics);
95      }
96    }
97  }
98}
Note: See TracBrowser for help on using the repository browser.