Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic.Views/3.4/SymbolicDataAnalysisExpressionLineageExplorerView.cs @ 10514

Last change on this file since 10514 was 10514, checked in by bburlacu, 10 years ago

#1772: Added user controls for displaying lineages and tracking building blocks with the help of the genealogy graph (work in progress).

File size: 4.2 KB
Line 
1using System.Collections.Generic;
2using System.Drawing.Text;
3using System.Globalization;
4using System.Linq;
5using System.Windows.Forms;
6using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
7using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views;
8using HeuristicLab.EvolutionTracking;
9using HeuristicLab.MainForm;
10using HeuristicLab.MainForm.WindowsForms;
11using HeuristicLab.Visualization;
12
13namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Views {
14  [View("LineageExplorerView")]
15  [Content(typeof(IGenealogyGraph), false)]
16  public partial class SymbolicDataAnalysisExpressionLineageExplorerView : AsynchronousContentView {
17    private readonly ReingoldTilfordLayoutEngine<ISymbolicExpressionTreeNode> SymbolicExpressionTreeNodeLayoutEngine;
18    private readonly SymbolicExpressionTreeLayoutAdapter SymbolicExpressionTreeLayoutAdapter;
19
20    private readonly Dictionary<TreeNode, ISymbolicExpressionTree> TreeMap;
21
22    private const int MinHorizontalSpacing = 50;
23    private const int MinVerticalSpacing = 50;
24    private const int PreferredNodeWidth = 80;
25    private const int PreferredNodeHeight = 40;
26
27    public new IGenealogyGraph Content {
28      get { return (IGenealogyGraph)base.Content; }
29      set { base.Content = value; }
30    }
31
32    public SymbolicDataAnalysisExpressionLineageExplorerView() {
33      InitializeComponent();
34      SymbolicExpressionTreeNodeLayoutEngine = new ReingoldTilfordLayoutEngine<ISymbolicExpressionTreeNode> {
35        MinHorizontalSpacing = MinHorizontalSpacing + PreferredNodeWidth,
36        MinVerticalSpacing = MinVerticalSpacing + PreferredNodeHeight
37      };
38      SymbolicExpressionTreeLayoutAdapter = new SymbolicExpressionTreeLayoutAdapter();
39      TreeMap = new Dictionary<TreeNode, ISymbolicExpressionTree>();
40      double width = symbolicDataAnalysisExpressionLineageExplorerChart.PreferredSize.Width;
41      double height = symbolicDataAnalysisExpressionLineageExplorerChart.PreferredSize.Height;
42      if (symbolicDataAnalysisExpressionLineageExplorerChart.Chart == null) {
43        symbolicDataAnalysisExpressionLineageExplorerChart.Chart = new Chart(0, 0, width, height);
44      }
45    }
46
47
48    #region events
49    protected override void OnContentChanged() {
50      base.OnContentChanged();
51      if (Content != null) { updateTreeView(); }
52    }
53    #endregion
54
55    protected override void SetEnabledStateOfControls() {
56      base.SetEnabledStateOfControls();
57      treeView.Enabled = Content != null;
58    }
59
60    private void updateTreeView() {
61      var lastGen = Content.Ranks.OrderBy(x => x.Key).Last().Value.ToList();
62      TreeMap.Clear();
63      symbolicDataAnalysisExpressionLineageExplorerChart.Clear();
64      foreach (var g in lastGen) {
65        var treeNode = new TreeNode(g.Quality.ToString(CultureInfo.InvariantCulture));
66        treeView.Nodes.Add(treeNode);
67        TreeMap.Add(treeNode, (ISymbolicExpressionTree)g.Content);
68      }
69    }
70
71    private void treeView_AfterSelect(object sender, TreeViewEventArgs e) {
72      symbolicDataAnalysisExpressionLineageExplorerChart.Clear();
73      var selectedNode = treeView.SelectedNode;
74      var symbolicExpressionTree = TreeMap[selectedNode];
75      var tile = new SymbolicExpressionTreeTile(this.symbolicDataAnalysisExpressionLineageExplorerChart.Chart) {
76        LayoutAdapter = SymbolicExpressionTreeLayoutAdapter,
77        LayoutEngine = SymbolicExpressionTreeNodeLayoutEngine,
78        PreferredNodeWidth = PreferredNodeWidth,
79        PreferredNodeHeight = PreferredNodeHeight
80      };
81      tile.SymbolicExpressionTree = symbolicExpressionTree;
82      symbolicDataAnalysisExpressionLineageExplorerChart.Add(tile);
83
84      //      graphics.TranslateTransform(0, symbolicDataAnalysisExpressionLineageExplorerChart.Height);
85      //      graphics.ScaleTransform(1f, -1f); // flip vertically (because the visualization plugin is upside-down
86      //      graphics.RotateTransform(180F);
87      var graphics = symbolicDataAnalysisExpressionLineageExplorerChart.CreateGraphics();
88      graphics.ScaleTransform(1f, -1f); // flip vertically (because the visualization plugin is upside-down
89      graphics.TextRenderingHint = TextRenderingHint.AntiAlias;
90      symbolicDataAnalysisExpressionLineageExplorerChart.Draw(graphics);
91    }
92  }
93}
Note: See TracBrowser for help on using the repository browser.