Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
12/29/17 16:43:29 (7 years ago)
Author:
bburlacu
Message:

#1772: Refactor SymbolicDataAnalysisGenealogyGraphView

Location:
branches/HeuristicLab.EvolutionTracking/HeuristicLab.EvolutionTracking.Views/3.4
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • branches/HeuristicLab.EvolutionTracking/HeuristicLab.EvolutionTracking.Views/3.4/GenealogyGraphChart.cs

    r13877 r15561  
    3232  public partial class GenealogyGraphChart : ChartControl {
    3333    private IGenealogyGraph genealogyGraph;
    34     private const double XIncrement = 30;
    35     private const double YIncrement = 30;
     34    private const double XIncrement = 25;
     35    private const double YIncrement = 25;
    3636    private const double Diameter = 20;
    3737    private readonly Brush defaultBrush;
     
    4444    public bool SimpleLineages { get; set; }
    4545    public bool LockGenealogy { get; set; }
    46     public bool TraceFragments { get; set; }
     46    public Func<IGenealogyGraphNode, Color> ColorSelector { get; set; }
    4747    #endregion
    4848
     
    9898    }
    9999
    100     public GenealogyGraphChart() : base(new Chart(0, 0, 800, 600)) {
     100    public GenealogyGraphChart() : base(new GridlessChart(0, 0, 800, 600)) {
    101101      InitializeComponent();
    102102      AddChartModes(new PanChartMode(this), new ZoomInChartMode(this), new ZoomOutChartMode(this), new SelectChartMode(this));
    103103      defaultBrush = new SolidBrush(Color.Transparent);
    104104      defaultPen = new Pen(Color.DarkGray);
     105
     106      ColorSelector = node => ColorGradient.Colors[(int)Math.Round(node.Quality * 255)];
    105107    }
    106108
     
    114116
    115117      foreach (var rank in ranks) {
     118        var rect = new Visualization.Rectangle(Chart, new PointD(x, y), new PointD(x + diameter, y + diameter));
     119        var font = new Font(FontFamily.GenericSansSerif, 12);
     120        var genLabel = new LabeledPrimitive(rect, rank.Rank.ToString(), font);
     121        Chart.Group.Add(genLabel);
     122
     123        x += xIncrement;
     124
    116125        var nodes = rank.Nodes.ToList();
    117126        nodes.Sort((a, b) => b.CompareTo(a)); // sort descending by quality
     
    119128
    120129        foreach (var node in nodes) {
    121           var brush = new SolidBrush(node.GetColor());
     130          var brush = new SolidBrush(ColorSelector(node));
    122131          var visualNode = new VisualGenealogyGraphNode(Chart, x, y, x + diameter, y + diameter, defaultPen, brush) {
    123132            Data = node,
     
    199208        var visualNode = GetMappedNode(graphNode);
    200209
    201         DrawLineage(visualNode, n => SimpleLineages ? n.IncomingArcs.Take(1) : n.IncomingArcs, a => a.Source);
     210        DrawLineage(visualNode, n => SimpleLineages ? n.IncomingArcs.Take(1) : n.IncomingArcs, a => a.Source, ColorSelector);
    202211        ((SolidBrush)visualNode.Brush).Color = Color.Transparent;
    203         DrawLineage(visualNode, n => n.OutgoingArcs, a => a.Target);
     212        DrawLineage(visualNode, n => n.OutgoingArcs, a => a.Target, ColorSelector);
    204213      }
    205214
     
    212221
    213222    #region drawing routines
    214     private static void DrawLineage(VisualGenealogyGraphNode node, Func<VisualGenealogyGraphNode, IEnumerable<VisualGenealogyGraphArc>> arcSelector, Func<VisualGenealogyGraphArc, VisualGenealogyGraphNode> nodeSelector) {
     223    private static void DrawLineage(VisualGenealogyGraphNode node, Func<VisualGenealogyGraphNode, IEnumerable<VisualGenealogyGraphArc>> arcSelector, Func<VisualGenealogyGraphArc, VisualGenealogyGraphNode> nodeSelector, Func<IGenealogyGraphNode, Color> getNodeColor) {
    215224      var brush = (SolidBrush)node.Brush;
    216225      if (brush.Color != Color.Transparent) return; // this lineage was already drawn (avoid redrawing common ancestors)
    217       brush.Color = node.Data.GetColor();
     226      brush.Color = getNodeColor(node.Data);
    218227      var arcs = arcSelector(node);
    219228      var pen = new Pen(Color.Transparent);
     
    224233        var end = new Point((int)arc.End.X, (int)arc.End.Y);
    225234        arc.Pen = pen;
    226         arc.Pen.Brush = new LinearGradientBrush(start, end, source.GetColor(), target.GetColor());
    227         DrawLineage(nodeSelector(arc), arcSelector, nodeSelector);
     235        arc.Pen.Brush = new LinearGradientBrush(start, end, getNodeColor(source), getNodeColor(target));
     236        DrawLineage(nodeSelector(arc), arcSelector, nodeSelector, getNodeColor);
    228237      }
    229238    }
     
    287296      foreach (var node in nodes) {
    288297        var graphNode = GetMappedNode(node);
    289         graphNode.Brush = new SolidBrush(node.GetColor());
     298        graphNode.Brush = new SolidBrush(ColorSelector(node));
    290299      }
    291300    }
     
    302311    public void HighlightAll() {
    303312      foreach (var visualNode in nodeMap.Values) {
    304         visualNode.Brush = new SolidBrush(visualNode.Data.GetColor());
    305       }
     313        visualNode.Brush = new SolidBrush(ColorSelector(visualNode.Data));
     314        Chart.IntoForeground(visualNode);
     315      }
     316      // draw arcs first and then nodes
    306317      foreach (var arc in arcMap.Values) {
    307318        var source = arc.Source.Data;
     
    309320        var start = new Point((int)arc.Start.X, (int)arc.Start.Y);
    310321        var end = new Point((int)arc.End.X, (int)arc.End.Y);
    311         arc.Pen.Brush = new LinearGradientBrush(start, end, source.GetColor(), target.GetColor());
     322        arc.Pen = new Pen(new LinearGradientBrush(start, end, ColorSelector(source), ColorSelector(target)));
     323        Chart.IntoBackground(arc);
    312324      }
    313325    }
     
    319331      var end = new Point((int)arc.End.X, (int)arc.End.Y);
    320332      arc.Pen = new Pen(Color.Transparent);
    321       arc.Pen.Brush = new LinearGradientBrush(start, end, source.GetColor(), target.GetColor());
     333      arc.Pen = new Pen(new LinearGradientBrush(start, end, ColorSelector(source), ColorSelector(target)));
     334      Chart.IntoBackground(arc);
    322335    }
    323336    #endregion
    324   }
    325 
    326   internal static class Util {
    327     public static Color GetColor(this IGenealogyGraphNode node) {
    328       if (double.IsNaN(node.Quality))
    329         return ColorGradient.Colors[0];
    330       var colorIndex = (int)Math.Round(node.Quality * ColorGradient.Colors.Count);
    331       if (colorIndex >= ColorGradient.Colors.Count) return ColorGradient.Colors.Last();
    332       return ColorGradient.Colors[colorIndex];
     337
     338    // workaround to disable the chart grid
     339    private class GridlessChart : Chart {
     340      public GridlessChart(PointD lowerLeft, PointD upperRight) : base(lowerLeft, upperRight) {
     341        Grid = null;
     342      }
     343
     344      public GridlessChart(double x1, double y1, double x2, double y2) : this(new PointD(x1, y1), new PointD(x2, y2)) { }
    333345    }
    334346  }
  • branches/HeuristicLab.EvolutionTracking/HeuristicLab.EvolutionTracking.Views/3.4/GenealogyGraphView.Designer.cs

    r13061 r15561  
    2626    private void InitializeComponent() {
    2727      this.splitContainer = new System.Windows.Forms.SplitContainer();
     28      this.genealogyGraphChart = new HeuristicLab.EvolutionTracking.Views.GenealogyGraphChart();
    2829      this.viewHost = new HeuristicLab.MainForm.WindowsForms.ViewHost();
    29       this.groupBox = new System.Windows.Forms.GroupBox();
    30       this.openNew_CheckBox = new System.Windows.Forms.CheckBox();
    31       this.lockGraph_checkBox = new System.Windows.Forms.CheckBox();
    32       this.simpleLineages_checkBox = new System.Windows.Forms.CheckBox();
    33       this.trace_checkBox = new System.Windows.Forms.CheckBox();
    34       this.genealogyGraphChart = new HeuristicLab.EvolutionTracking.Views.GenealogyGraphChart();
    3530      ((System.ComponentModel.ISupportInitialize)(this.splitContainer)).BeginInit();
    3631      this.splitContainer.Panel1.SuspendLayout();
    3732      this.splitContainer.Panel2.SuspendLayout();
    3833      this.splitContainer.SuspendLayout();
    39       this.groupBox.SuspendLayout();
    4034      this.SuspendLayout();
    4135      //
     
    4539            | System.Windows.Forms.AnchorStyles.Left)
    4640            | System.Windows.Forms.AnchorStyles.Right)));
    47       this.splitContainer.Location = new System.Drawing.Point(3, 55);
     41      this.splitContainer.Location = new System.Drawing.Point(3, 3);
    4842      this.splitContainer.Name = "splitContainer";
    4943      //
     
    5549      //
    5650      this.splitContainer.Panel2.Controls.Add(this.viewHost);
    57       this.splitContainer.Size = new System.Drawing.Size(1394, 742);
    58       this.splitContainer.SplitterDistance = 694;
     51      this.splitContainer.Size = new System.Drawing.Size(1404, 794);
     52      this.splitContainer.SplitterDistance = 698;
    5953      this.splitContainer.TabIndex = 0;
     54      //
     55      // genealogyGraphChart
     56      //
     57      this.genealogyGraphChart.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
     58            | System.Windows.Forms.AnchorStyles.Left)
     59            | System.Windows.Forms.AnchorStyles.Right)));
     60      this.genealogyGraphChart.BackColor = System.Drawing.SystemColors.Control;
     61      this.genealogyGraphChart.GenealogyGraph = null;
     62      this.genealogyGraphChart.Location = new System.Drawing.Point(0, 0);
     63      this.genealogyGraphChart.LockGenealogy = false;
     64      this.genealogyGraphChart.Mode = null;
     65      this.genealogyGraphChart.Name = "genealogyGraphChart";
     66      this.genealogyGraphChart.ScaleOnResize = true;
     67      this.genealogyGraphChart.SelectedGraphNode = null;
     68      this.genealogyGraphChart.ShowToolBar = true;
     69      this.genealogyGraphChart.SimpleLineages = false;
     70      this.genealogyGraphChart.Size = new System.Drawing.Size(693, 790);
     71      this.genealogyGraphChart.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.Default;
     72      this.genealogyGraphChart.TabIndex = 0;
    6073      //
    6174      // viewHost
     
    7184      this.viewHost.Name = "viewHost";
    7285      this.viewHost.ReadOnly = false;
    73       this.viewHost.Size = new System.Drawing.Size(697, 743);
     86      this.viewHost.Size = new System.Drawing.Size(703, 795);
    7487      this.viewHost.TabIndex = 0;
    7588      this.viewHost.ViewsLabelVisible = true;
    7689      this.viewHost.ViewType = null;
    77       //
    78       // groupBox
    79       //
    80       this.groupBox.Controls.Add(this.openNew_CheckBox);
    81       this.groupBox.Controls.Add(this.lockGraph_checkBox);
    82       this.groupBox.Controls.Add(this.simpleLineages_checkBox);
    83       this.groupBox.Controls.Add(this.trace_checkBox);
    84       this.groupBox.Location = new System.Drawing.Point(3, 4);
    85       this.groupBox.Name = "groupBox";
    86       this.groupBox.Size = new System.Drawing.Size(602, 44);
    87       this.groupBox.TabIndex = 1;
    88       this.groupBox.TabStop = false;
    89       this.groupBox.Text = "Genealogy Options";
    90       //
    91       // openNew_CheckBox
    92       //
    93       this.openNew_CheckBox.AutoSize = true;
    94       this.openNew_CheckBox.Location = new System.Drawing.Point(485, 19);
    95       this.openNew_CheckBox.Name = "openNew_CheckBox";
    96       this.openNew_CheckBox.Size = new System.Drawing.Size(111, 17);
    97       this.openNew_CheckBox.TabIndex = 1;
    98       this.openNew_CheckBox.Text = "Open in new view";
    99       this.openNew_CheckBox.UseVisualStyleBackColor = true;
    100       //
    101       // lockGraph_checkBox
    102       //
    103       this.lockGraph_checkBox.Appearance = System.Windows.Forms.Appearance.Button;
    104       this.lockGraph_checkBox.AutoSize = true;
    105       this.lockGraph_checkBox.Location = new System.Drawing.Point(157, 15);
    106       this.lockGraph_checkBox.Name = "lockGraph_checkBox";
    107       this.lockGraph_checkBox.Size = new System.Drawing.Size(73, 23);
    108       this.lockGraph_checkBox.TabIndex = 0;
    109       this.lockGraph_checkBox.Text = "Lock Graph";
    110       this.lockGraph_checkBox.UseVisualStyleBackColor = true;
    111       this.lockGraph_checkBox.CheckedChanged += new System.EventHandler(this.lockGraph_checkBox_CheckedChanged);
    112       //
    113       // simpleLineages_checkBox
    114       //
    115       this.simpleLineages_checkBox.Appearance = System.Windows.Forms.Appearance.Button;
    116       this.simpleLineages_checkBox.AutoSize = true;
    117       this.simpleLineages_checkBox.Location = new System.Drawing.Point(57, 15);
    118       this.simpleLineages_checkBox.Name = "simpleLineages_checkBox";
    119       this.simpleLineages_checkBox.Size = new System.Drawing.Size(94, 23);
    120       this.simpleLineages_checkBox.TabIndex = 0;
    121       this.simpleLineages_checkBox.Text = "Simple Lineages";
    122       this.simpleLineages_checkBox.UseVisualStyleBackColor = true;
    123       this.simpleLineages_checkBox.CheckedChanged += new System.EventHandler(this.simpleLineages_checkBox_CheckedChanged);
    124       //
    125       // trace_checkBox
    126       //
    127       this.trace_checkBox.Appearance = System.Windows.Forms.Appearance.Button;
    128       this.trace_checkBox.AutoSize = true;
    129       this.trace_checkBox.Location = new System.Drawing.Point(6, 15);
    130       this.trace_checkBox.Name = "trace_checkBox";
    131       this.trace_checkBox.Size = new System.Drawing.Size(45, 23);
    132       this.trace_checkBox.TabIndex = 0;
    133       this.trace_checkBox.Text = "Trace";
    134       this.trace_checkBox.UseVisualStyleBackColor = true;
    135       this.trace_checkBox.CheckedChanged += new System.EventHandler(this.trace_checkBox_CheckedChanged);
    136       //
    137       // genealogyGraphChart
    138       //
    139       this.genealogyGraphChart.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
    140             | System.Windows.Forms.AnchorStyles.Left)
    141             | System.Windows.Forms.AnchorStyles.Right)));
    142       this.genealogyGraphChart.BackColor = System.Drawing.SystemColors.Control;
    143       this.genealogyGraphChart.GenealogyGraph = null;
    144       this.genealogyGraphChart.Location = new System.Drawing.Point(0, 0);
    145       this.genealogyGraphChart.LockGenealogy = false;
    146       this.genealogyGraphChart.Name = "genealogyGraphChart";
    147       this.genealogyGraphChart.ScaleOnResize = true;
    148       this.genealogyGraphChart.SelectedGraphNode = null;
    149       this.genealogyGraphChart.SimpleLineages = false;
    150       this.genealogyGraphChart.Size = new System.Drawing.Size(689, 738);
    151       this.genealogyGraphChart.TabIndex = 0;
    152       this.genealogyGraphChart.TraceFragments = false;
    15390      //
    15491      // GenealogyGraphView
     
    15693      this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
    15794      this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
    158       this.Controls.Add(this.groupBox);
    15995      this.Controls.Add(this.splitContainer);
    16096      this.Name = "GenealogyGraphView";
    161       this.Size = new System.Drawing.Size(1400, 800);
     97      this.Size = new System.Drawing.Size(1410, 800);
    16298      this.splitContainer.Panel1.ResumeLayout(false);
    16399      this.splitContainer.Panel2.ResumeLayout(false);
    164100      ((System.ComponentModel.ISupportInitialize)(this.splitContainer)).EndInit();
    165101      this.splitContainer.ResumeLayout(false);
    166       this.groupBox.ResumeLayout(false);
    167       this.groupBox.PerformLayout();
    168102      this.ResumeLayout(false);
    169103
     
    175109    protected MainForm.WindowsForms.ViewHost viewHost;
    176110    protected GenealogyGraphChart genealogyGraphChart;
    177     private System.Windows.Forms.GroupBox groupBox;
    178     protected System.Windows.Forms.CheckBox trace_checkBox;
    179     protected System.Windows.Forms.CheckBox simpleLineages_checkBox;
    180     protected System.Windows.Forms.CheckBox lockGraph_checkBox;
    181     protected System.Windows.Forms.CheckBox openNew_CheckBox;
    182111
    183112  }
  • branches/HeuristicLab.EvolutionTracking/HeuristicLab.EvolutionTracking.Views/3.4/GenealogyGraphView.cs

    r12225 r15561  
    77  [View("GenealogyGraphView")]
    88  [Content(typeof(IGenealogyGraph<>), IsDefaultView = false)]
    9   public partial class GenealogyGraphView<T> : ItemView where T : class,IItem {
     9  public partial class GenealogyGraphView<T> : ItemView where T : class, IItem {
    1010    public new IGenealogyGraph<T> Content {
    1111      get { return (IGenealogyGraph<T>)base.Content; }
     
    4949      var visualNode = (VisualGenealogyGraphNode)sender;
    5050      var graphNode = (IGenealogyGraphNode<T>)visualNode.Data;
    51       if (graphNode == null) return;
    52       var content = graphNode.Data;
    53       if (content == null) return;
    54       viewHost.Content = content;
     51      if (graphNode == null || graphNode.Data == null) return;
     52      viewHost.Content = graphNode.Data;
    5553    }
    5654    public virtual void graphChart_GenealogyGraphNodeDoubleClicked(object sender, MouseEventArgs arcs) {
     
    6058    #region events for configuring the behavior of the genealogy chart (trace/match, simple lineages, etc)
    6159    private void trace_checkBox_CheckedChanged(object sender, System.EventArgs e) {
    62       genealogyGraphChart.TraceFragments = trace_checkBox.Checked;
     60      //genealogyGraphChart.TraceFragments = trace_checkBox.Checked;
    6361    }
    6462
    6563    private void simpleLineages_checkBox_CheckedChanged(object sender, System.EventArgs e) {
    66       genealogyGraphChart.SimpleLineages = simpleLineages_checkBox.Checked;
     64      //genealogyGraphChart.SimpleLineages = simpleLineages_checkBox.Checked;
    6765    }
    6866
    6967    private void lockGraph_checkBox_CheckedChanged(object sender, System.EventArgs e) {
    70       genealogyGraphChart.LockGenealogy = lockGraph_checkBox.Checked;
     68      //genealogyGraphChart.LockGenealogy = lockGraph_checkBox.Checked;
    7169    }
    7270    #endregion
  • branches/HeuristicLab.EvolutionTracking/HeuristicLab.EvolutionTracking.Views/3.4/HeuristicLab.EvolutionTracking.Views-3.4.csproj

    r15351 r15561  
    9797  </ItemGroup>
    9898  <ItemGroup>
    99     <Compile Include="GenealogyGraphChart.cs" />
     99    <Compile Include="GenealogyGraphChart.cs">
     100      <SubType>UserControl</SubType>
     101    </Compile>
    100102    <Compile Include="GenealogyGraphChart.Designer.cs">
    101103      <DependentUpon>GenealogyGraphChart.cs</DependentUpon>
Note: See TracChangeset for help on using the changeset viewer.