1 | using System.Collections.Generic;
|
---|
2 | using System.Globalization;
|
---|
3 | using System.Linq;
|
---|
4 | using System.Windows.Forms;
|
---|
5 | using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
|
---|
6 | using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views;
|
---|
7 | using HeuristicLab.EvolutionTracking;
|
---|
8 | using HeuristicLab.MainForm;
|
---|
9 | using HeuristicLab.MainForm.WindowsForms;
|
---|
10 | using HeuristicLab.Visualization;
|
---|
11 |
|
---|
12 | namespace 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 |
|
---|
18 | private readonly Dictionary<TreeNode, ISymbolicExpressionTree> treeMap;
|
---|
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();
|
---|
32 | symbolicExpressionTreeNodeLayoutEngine = new ReingoldTilfordLayoutEngine<ISymbolicExpressionTreeNode>(node => node.Subtrees) {
|
---|
33 | HorizontalSpacing = MinHorizontalSpacing,
|
---|
34 | VerticalSpacing = MinVerticalSpacing,
|
---|
35 | NodeWidth = PreferredNodeWidth,
|
---|
36 | NodeHeight = PreferredNodeHeight
|
---|
37 | };
|
---|
38 |
|
---|
39 | treeMap = new Dictionary<TreeNode, ISymbolicExpressionTree>();
|
---|
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);
|
---|
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 | symbolicExpressionChartControl.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.Data);
|
---|
67 | }
|
---|
68 | }
|
---|
69 |
|
---|
70 | private void treeView_AfterSelect(object sender, TreeViewEventArgs e) {
|
---|
71 | symbolicExpressionChartControl.Clear();
|
---|
72 | var selectedNode = treeView.SelectedNode;
|
---|
73 | var symbolicExpressionTree = treeMap[selectedNode];
|
---|
74 | var chart = symbolicExpressionChartControl.Chart;
|
---|
75 | var tile = new SymbolicExpressionTreeTile(chart) {
|
---|
76 | LayoutEngine = symbolicExpressionTreeNodeLayoutEngine,
|
---|
77 | PreferredNodeWidth = PreferredNodeWidth,
|
---|
78 | PreferredNodeHeight = PreferredNodeHeight,
|
---|
79 | SymbolicExpressionTree = symbolicExpressionTree
|
---|
80 | };
|
---|
81 | symbolicExpressionChartControl.UpdateEnabled = false;
|
---|
82 | symbolicExpressionChartControl.Add(tile);
|
---|
83 | // symbolicExpressionChartControl.FlipVertical();
|
---|
84 | symbolicExpressionChartControl.UpdateEnabled = true;
|
---|
85 | symbolicExpressionChartControl.EnforceUpdate();
|
---|
86 | }
|
---|
87 | }
|
---|
88 | }
|
---|