Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
02/26/14 02:19:58 (10 years ago)
Author:
bburlacu
Message:

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

Location:
branches/HeuristicLab.EvolutionTracking
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • branches/HeuristicLab.EvolutionTracking/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views/3.4/SymbolicExpressionTreeTile.cs

    r10514 r10517  
    2525using HeuristicLab.Visualization;
    2626using HeuristicLab.Visualization.Primitives;
    27 using Rectangle = HeuristicLab.Visualization.Rectangle;
    2827
    2928namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views {
     
    5655      LayoutEngine.CalculateLayout();
    5756
    58       var primitivesMap = new Dictionary<LayoutNode<ISymbolicExpressionTreeNode>, LabeledPrimitive>(); // both Ellipse and Rectangle are derived from the RectangularPrimitiveBase
     57      var primitivesMap = new Dictionary<LayoutNode<ISymbolicExpressionTreeNode>, IPrimitive>(); // both Ellipse and Rectangle are derived from the RectangularPrimitiveBase
    5958      var font = new Font(FontFamily.GenericSansSerif, 10, GraphicsUnit.Pixel);
    6059
    6160      foreach (var node in layoutNodes) {
    62         LabeledPrimitive labeledPrimitive;
    63         if (node.Children == null || node.Children.Count == 0) {
    64           var rectangle = new Rectangle(Chart, node.X, node.Y, node.X + preferredNodeWidth, node.Y + preferredNodeHeight);
    65           var textPrimitive = new TextPrimitive(Chart, rectangle.LowerLeft, rectangle.UpperRight) {
    66             Font = font,
    67             Text = node.Content.ToString()
    68           };
    69           labeledPrimitive = new LabeledPrimitive(Chart, rectangle, textPrimitive);
     61        var lowerLeft = new PointD(node.X, node.Y);
     62        var upperRight = new PointD(node.X + preferredNodeWidth, node.Y + preferredNodeHeight);
     63
     64        RectangularPrimitiveBase rectangularPrimitive;
     65        if (node.IsLeaf) {
     66          rectangularPrimitive = new LabeledRectangle(Chart, lowerLeft, upperRight) { Font = font, Text = node.Content.ToString() };
    7067        } else {
    71           var ellipse = new Ellipse(Chart, node.X, node.Y, node.X + preferredNodeWidth, node.Y + preferredNodeHeight);
    72           var textPrimitive = new TextPrimitive(Chart, ellipse.LowerLeft, ellipse.UpperRight) {
    73             Font = font,
    74             Text = node.Content.ToString()
    75           };
    76           labeledPrimitive = new LabeledPrimitive(Chart, ellipse, textPrimitive);
     68          rectangularPrimitive = new LabeledEllipse(Chart, lowerLeft, upperRight) { Font = font, Text = node.Content.ToString() };
    7769        }
    78         this.Add(labeledPrimitive);
    79         primitivesMap.Add(node, labeledPrimitive);
     70
     71        this.Add(rectangularPrimitive);
     72        primitivesMap.Add(node, rectangularPrimitive);
    8073      }
    8174
  • branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic.Views/3.4/SymbolicDataAnalysisExpressionLineageExplorerChart.cs

    r10514 r10517  
    11using System.Collections.Generic;
    22using System.Drawing;
     3using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views;
    34using HeuristicLab.Visualization;
    45
     
    78    public SymbolicDataAnalysisExpressionLineageExplorerChart() {
    89      InitializeComponent();
    9       if (Chart == null) {
    10         Chart = new Chart(0, 0, PreferredSize.Width, PreferredSize.Height);
    11       }
     10      if (Chart == null) { Chart = new Chart(0, 0, PreferredSize.Width, PreferredSize.Height); }
    1211    }
    1312
     
    2726      Chart.Group.Draw(graphics);
    2827    }
     28
     29    public bool UpdateEnabled {
     30      get { return Chart.UpdateEnabled; }
     31      set { Chart.UpdateEnabled = value; }
     32    }
     33
     34    public void EnforceUpdate() {
     35      Chart.EnforceUpdate();
     36    }
     37
     38    public void FlipVertical() {
     39      foreach (var primitive in Chart.Group.Primitives) {
     40        var tile = primitive as SymbolicExpressionTreeTile;
     41        if (tile != null) {
     42          foreach (var p in tile.Primitives) {
     43            FlipPrimitive(p);
     44          }
     45        } else {
     46          FlipPrimitive(primitive);
     47        }
     48      }
     49    }
     50
     51    public void FlipPrimitive(IPrimitive primitive) {
     52      var height = pictureBox.Height;
     53      var rect = primitive as RectangularPrimitiveBase;
     54      var line = primitive as LinearPrimitiveBase;
     55      if (rect != null) {
     56        rect.SetPosition(rect.LowerLeft.X, height - rect.UpperRight.Y, rect.UpperRight.X, height - rect.LowerLeft.Y);
     57      } else if (line != null) {
     58        line.SetPosition(line.Start.X, height - line.Start.Y, line.End.X, height - line.End.Y);
     59      }
     60    }
    2961  }
    3062}
  • branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic.Views/3.4/SymbolicDataAnalysisExpressionLineageExplorerView.Designer.cs

    r10514 r10517  
    2525    private void InitializeComponent() {
    2626      this.treeView = new System.Windows.Forms.TreeView();
    27       this.symbolicDataAnalysisExpressionLineageExplorerChart = new HeuristicLab.Problems.DataAnalysis.Symbolic.Views.SymbolicDataAnalysisExpressionLineageExplorerChart();
     27      this.lineageExplorerChart = new HeuristicLab.Problems.DataAnalysis.Symbolic.Views.SymbolicDataAnalysisExpressionLineageExplorerChart();
    2828      this.SuspendLayout();
    2929      //
     
    3838      this.treeView.AfterSelect += new System.Windows.Forms.TreeViewEventHandler(this.treeView_AfterSelect);
    3939      //
    40       // symbolicDataAnalysisExpressionLineageExplorerChart
     40      // lineageExplorerChart
    4141      //
    42       this.symbolicDataAnalysisExpressionLineageExplorerChart.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
     42      this.lineageExplorerChart.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
    4343            | System.Windows.Forms.AnchorStyles.Left)
    4444            | System.Windows.Forms.AnchorStyles.Right)));
    45       this.symbolicDataAnalysisExpressionLineageExplorerChart.AutoSize = true;
    46       this.symbolicDataAnalysisExpressionLineageExplorerChart.BackColor = System.Drawing.SystemColors.Control;
    47       this.symbolicDataAnalysisExpressionLineageExplorerChart.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
    48       this.symbolicDataAnalysisExpressionLineageExplorerChart.Chart = null;
    49       this.symbolicDataAnalysisExpressionLineageExplorerChart.Location = new System.Drawing.Point(176, 3);
    50       this.symbolicDataAnalysisExpressionLineageExplorerChart.Name = "symbolicDataAnalysisExpressionLineageExplorerChart";
    51       this.symbolicDataAnalysisExpressionLineageExplorerChart.ScaleOnResize = true;
    52       this.symbolicDataAnalysisExpressionLineageExplorerChart.Size = new System.Drawing.Size(657, 593);
    53       this.symbolicDataAnalysisExpressionLineageExplorerChart.TabIndex = 1;
     45      this.lineageExplorerChart.AutoSize = true;
     46      this.lineageExplorerChart.BackColor = System.Drawing.SystemColors.Control;
     47      this.lineageExplorerChart.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
     48      this.lineageExplorerChart.Chart = null;
     49      this.lineageExplorerChart.Location = new System.Drawing.Point(176, 3);
     50      this.lineageExplorerChart.Name = "lineageExplorerChart";
     51      this.lineageExplorerChart.ScaleOnResize = true;
     52      this.lineageExplorerChart.Size = new System.Drawing.Size(657, 593);
     53      this.lineageExplorerChart.TabIndex = 1;
    5454      //
    5555      // SymbolicDataAnalysisExpressionLineageExplorerView
     
    5757      this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
    5858      this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
    59       this.Controls.Add(this.symbolicDataAnalysisExpressionLineageExplorerChart);
     59      this.Controls.Add(this.lineageExplorerChart);
    6060      this.Controls.Add(this.treeView);
    6161      this.DoubleBuffered = true;
     
    7070
    7171    private System.Windows.Forms.TreeView treeView;
    72     private SymbolicDataAnalysisExpressionLineageExplorerChart symbolicDataAnalysisExpressionLineageExplorerChart;
     72    private SymbolicDataAnalysisExpressionLineageExplorerChart lineageExplorerChart;
    7373  }
    7474}
  • branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic.Views/3.4/SymbolicDataAnalysisExpressionLineageExplorerView.cs

    r10514 r10517  
    11using System.Collections.Generic;
    2 using System.Drawing.Text;
    32using System.Globalization;
    43using System.Linq;
     
    1514  [Content(typeof(IGenealogyGraph), false)]
    1615  public partial class SymbolicDataAnalysisExpressionLineageExplorerView : AsynchronousContentView {
    17     private readonly ReingoldTilfordLayoutEngine<ISymbolicExpressionTreeNode> SymbolicExpressionTreeNodeLayoutEngine;
    18     private readonly SymbolicExpressionTreeLayoutAdapter SymbolicExpressionTreeLayoutAdapter;
     16    private readonly ReingoldTilfordLayoutEngine<ISymbolicExpressionTreeNode> symbolicExpressionTreeNodeLayoutEngine;
     17    private readonly SymbolicExpressionTreeLayoutAdapter symbolicExpressionTreeLayoutAdapter;
    1918
    20     private readonly Dictionary<TreeNode, ISymbolicExpressionTree> TreeMap;
     19    private readonly Dictionary<TreeNode, ISymbolicExpressionTree> treeMap;
    2120
    2221    private const int MinHorizontalSpacing = 50;
     
    3231    public SymbolicDataAnalysisExpressionLineageExplorerView() {
    3332      InitializeComponent();
    34       SymbolicExpressionTreeNodeLayoutEngine = new ReingoldTilfordLayoutEngine<ISymbolicExpressionTreeNode> {
     33      symbolicExpressionTreeNodeLayoutEngine = new ReingoldTilfordLayoutEngine<ISymbolicExpressionTreeNode> {
    3534        MinHorizontalSpacing = MinHorizontalSpacing + PreferredNodeWidth,
    3635        MinVerticalSpacing = MinVerticalSpacing + PreferredNodeHeight
    3736      };
    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);
     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);
    4443      }
    4544    }
     
    6059    private void updateTreeView() {
    6160      var lastGen = Content.Ranks.OrderBy(x => x.Key).Last().Value.ToList();
    62       TreeMap.Clear();
    63       symbolicDataAnalysisExpressionLineageExplorerChart.Clear();
     61      treeMap.Clear();
     62      lineageExplorerChart.Clear();
    6463      foreach (var g in lastGen) {
    6564        var treeNode = new TreeNode(g.Quality.ToString(CultureInfo.InvariantCulture));
    6665        treeView.Nodes.Add(treeNode);
    67         TreeMap.Add(treeNode, (ISymbolicExpressionTree)g.Content);
     66        treeMap.Add(treeNode, (ISymbolicExpressionTree)g.Content);
    6867      }
    6968    }
    7069
    7170    private void treeView_AfterSelect(object sender, TreeViewEventArgs e) {
    72       symbolicDataAnalysisExpressionLineageExplorerChart.Clear();
     71      lineageExplorerChart.Clear();
    7372      var selectedNode = treeView.SelectedNode;
    74       var symbolicExpressionTree = TreeMap[selectedNode];
    75       var tile = new SymbolicExpressionTreeTile(this.symbolicDataAnalysisExpressionLineageExplorerChart.Chart) {
    76         LayoutAdapter = SymbolicExpressionTreeLayoutAdapter,
    77         LayoutEngine = SymbolicExpressionTreeNodeLayoutEngine,
     73      var symbolicExpressionTree = treeMap[selectedNode];
     74      var chart = lineageExplorerChart.Chart;
     75      var tile = new SymbolicExpressionTreeTile(chart) {
     76        LayoutAdapter = symbolicExpressionTreeLayoutAdapter,
     77        LayoutEngine = symbolicExpressionTreeNodeLayoutEngine,
    7878        PreferredNodeWidth = PreferredNodeWidth,
    79         PreferredNodeHeight = PreferredNodeHeight
     79        PreferredNodeHeight = PreferredNodeHeight,
     80        SymbolicExpressionTree = symbolicExpressionTree
    8081      };
    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);
     82      lineageExplorerChart.UpdateEnabled = false;
     83      lineageExplorerChart.Add(tile);
     84      lineageExplorerChart.FlipVertical();
     85      lineageExplorerChart.UpdateEnabled = true;
     86      lineageExplorerChart.EnforceUpdate();
    9187    }
    9288  }
Note: See TracChangeset for help on using the changeset viewer.