Free cookie consent management tool by TermsFeed Policy Generator

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

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

#1772: Small improvements to FragmentGraphView, moved tracking classes to separate folder.

File size: 3.5 KB
RevLine 
[10514]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 {
[10517]16    private readonly ReingoldTilfordLayoutEngine<ISymbolicExpressionTreeNode> symbolicExpressionTreeNodeLayoutEngine;
[10514]17
[10517]18    private readonly Dictionary<TreeNode, ISymbolicExpressionTree> treeMap;
[10514]19
20    private const int MinHorizontalSpacing = 50;
21    private const int MinVerticalSpacing = 50;
22    private const int PreferredNodeWidth = 80;
23    private const int PreferredNodeHeight = 40;
24
25    public new IGenealogyGraph Content {
26      get { return (IGenealogyGraph)base.Content; }
27      set { base.Content = value; }
28    }
29
30    public SymbolicDataAnalysisExpressionLineageExplorerView() {
31      InitializeComponent();
[10650]32      symbolicExpressionTreeNodeLayoutEngine = new ReingoldTilfordLayoutEngine<ISymbolicExpressionTreeNode>(node => node.Subtrees) {
[10524]33        HorizontalSpacing = MinHorizontalSpacing,
34        VerticalSpacing = MinVerticalSpacing,
35        NodeWidth = PreferredNodeWidth,
36        NodeHeight = PreferredNodeHeight
[10514]37      };
[10650]38
[10517]39      treeMap = new Dictionary<TreeNode, ISymbolicExpressionTree>();
[10655]40      double width = symbolicExpressionChartControl.PreferredSize.Width;
41      double height = symbolicExpressionChartControl.PreferredSize.Height;
42      if (symbolicExpressionChartControl.Chart == null) {
43        symbolicExpressionChartControl.Chart = new Chart(0, 0, width, height);
[10514]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();
[10517]61      treeMap.Clear();
[10655]62      symbolicExpressionChartControl.Clear();
[10514]63      foreach (var g in lastGen) {
64        var treeNode = new TreeNode(g.Quality.ToString(CultureInfo.InvariantCulture));
65        treeView.Nodes.Add(treeNode);
[10517]66        treeMap.Add(treeNode, (ISymbolicExpressionTree)g.Content);
[10514]67      }
68    }
69
70    private void treeView_AfterSelect(object sender, TreeViewEventArgs e) {
[10655]71      symbolicExpressionChartControl.Clear();
[10514]72      var selectedNode = treeView.SelectedNode;
[10517]73      var symbolicExpressionTree = treeMap[selectedNode];
[10655]74      var chart = symbolicExpressionChartControl.Chart;
[10517]75      var tile = new SymbolicExpressionTreeTile(chart) {
76        LayoutEngine = symbolicExpressionTreeNodeLayoutEngine,
[10514]77        PreferredNodeWidth = PreferredNodeWidth,
[10517]78        PreferredNodeHeight = PreferredNodeHeight,
79        SymbolicExpressionTree = symbolicExpressionTree
[10514]80      };
[10655]81      symbolicExpressionChartControl.UpdateEnabled = false;
82      symbolicExpressionChartControl.Add(tile);
[10728]83      //      symbolicExpressionChartControl.FlipVertical();
[10655]84      symbolicExpressionChartControl.UpdateEnabled = true;
85      symbolicExpressionChartControl.EnforceUpdate();
[10514]86    }
87  }
88}
Note: See TracBrowser for help on using the repository browser.