Free cookie consent management tool by TermsFeed Policy Generator

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

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

#1772: Got the lineageExplorerChart to display symbolic expression trees with the correct orientation (vertically flipped).

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