Free cookie consent management tool by TermsFeed Policy Generator

Changeset 13817


Ignore:
Timestamp:
04/29/16 17:09:15 (8 years ago)
Author:
bburlacu
Message:

#2597: Added RegressionSolutionTargetResponseGradientView and updated GradientChart.

Location:
branches/HeuristicLab.RegressionSolutionGradientView/HeuristicLab.Problems.DataAnalysis.Views/3.4
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/HeuristicLab.RegressionSolutionGradientView/HeuristicLab.Problems.DataAnalysis.Views/3.4/GradientChart.cs

    r13808 r13817  
    2323using System.Collections.Generic;
    2424using System.Drawing;
     25using System.Globalization;
    2526using System.Linq;
    2627using System.Windows.Forms;
     
    3233  public partial class GradientChart : EnhancedChart {
    3334    private ModifiableDataset internalDataset;
     35
     36    public bool ShowLegend { get; set; }
    3437
    3538    private bool useMedianValues;
     
    199202      if (points == 0)
    200203        return;
    201       CalculateAxisInterval();
    202204      Series.Clear();
    203205      var vla = VerticalLineAnnotation;
     
    212214        var p = series.Points.Last();
    213215        vla.X = p.XValue;
    214         var ta = new TextAnnotation {
    215           Text = string.Format("X: {0:0.000}, Y: {1:0.000}", p.XValue, p.YValues[0]),
    216           Visible = true,
    217           X = p.XValue,
    218           Y = p.YValues[0],
    219           AxisX = ChartAreas[0].AxisX,
    220           AxisY = ChartAreas[0].AxisY
    221         };
    222         ta.ClipToChartArea = "ChartArea1";
    223         ta.Name = series.Name;
    224         Annotations.Add(ta);
    225       }
     216        ChartAreas[0].AxisX.Title = Variable + " " + vla.X.ToString("N3", CultureInfo.CurrentCulture);
     217        //        var ta = new TextAnnotation {
     218        //          Text = string.Format("X: {0:0.000}, Y: {1:0.000}", p.XValue, p.YValues[0]),
     219        //          Visible = true,
     220        //          X = p.XValue,
     221        //          Y = p.YValues[0],
     222        //          AxisX = ChartAreas[0].AxisX,
     223        //          AxisY = ChartAreas[0].AxisY
     224        //        };
     225        //        ta.ClipToChartArea = "ChartArea1";
     226        //        ta.Name = series.Name;
     227        //        Annotations.Add(ta);
     228      }
     229      CalculateAxisInterval();
    226230      AddStripLines();
    227       AddLegends();
     231      if (ShowLegend)
     232        AddLegends();
    228233    }
    229234
     
    260265      var step = (max - min) / points;
    261266      var axisX = ChartAreas[0].AxisX;
    262       axisX.Title = Variable;
     267      axisX.Title = Variable + " : " + v.ToString("N3", CultureInfo.CurrentCulture);
    263268      var axisY = ChartAreas[0].AxisY;
    264269      axisY.Title = Target;
     
    290295      Legends.Clear();
    291296      var legend = new Legend();
    292       //      legend.Name = s.Name;
    293297      legend.Alignment = StringAlignment.Center;
    294298      legend.LegendStyle = LegendStyle.Row;
     
    302306    private void AddStripLines() {
    303307      var axisX = ChartAreas[0].AxisX;
    304       axisX.Title = Variable;
    305       var axisY = ChartAreas[0].AxisY;
    306       axisY.Title = ProblemData.TargetVariable;
    307308      axisX.StripLines.Clear();
    308309      axisX.StripLines.Add(new StripLine { BackColor = Color.FromArgb(30, Color.Green), IntervalOffset = axisX.Minimum, StripWidth = min - axisX.Minimum });
     
    317318      axis.Maximum = axisMax;
    318319      axis.Interval = axisInterval;
     320
     321      double ymin = 0, ymax = 0;
     322      foreach (var v in Series[0].Points.Select(x => x.YValues[0])) {
     323        if (ymin > v) ymin = v;
     324        if (ymax < v) ymax = v;
     325      }
     326      ChartUtil.CalculateAxisInterval(ymin, ymax, 5, out axisMin, out axisMax, out axisInterval);
     327      axis = ChartAreas[0].AxisY;
     328      axis.Minimum = axisMin;
     329      axis.Maximum = axisMax;
     330      axis.Interval = axisInterval;
    319331    }
    320332
     
    326338
    327339    #region events
     340    public event EventHandler VariableValueChanged;
     341    public void OnVariableValueChanged(object sender, EventArgs args) {
     342      var changed = VariableValueChanged;
     343      if (changed == null) return;
     344      changed(sender, args);
     345    }
     346
    328347    public event EventHandler ChartPropertyChanged;
    329348    public void OnChartPropertyChanged(object sender, EventArgs args) {
     
    353372        e.NewLocationX = axisX.Minimum;
    354373      var x = e.NewLocationX;
    355 
    356       //      var va = VerticalLineAnnotation;
    357       //      Annotations.Clear();
    358       //      Annotations.Add(va);
     374      internalDataset.SetVariableValue(x, Variable, 0);
    359375      for (int i = 0; i < solutionList.Count; ++i) {
    360376        var y = GetEstimatedValue(solutionList[i], x);
     
    363379        s.Points[n - 1] = new DataPoint(x, y) { MarkerColor = Color.Red, MarkerSize = 5 };
    364380      }
    365       foreach (var annotation in Annotations.OfType<TextAnnotation>()) {
    366         var p = Series[annotation.Name].Points.Last();
    367         annotation.Text = string.Format("X: {0:0.000}, Y: {1:0.000}", p.XValue, p.YValues[0]);
    368         annotation.X = p.XValue;
    369         annotation.Y = p.YValues[0];
    370       }
     381      ChartAreas[0].AxisX.Title = Variable + " : " + x.ToString("N3", CultureInfo.CurrentCulture);
    371382      Update();
     383      OnVariableValueChanged(this, EventArgs.Empty);
    372384    }
    373385
     
    390402      }
    391403    }
    392     #endregion
    393404
    394405    private void GradientChart_DragDrop(object sender, DragEventArgs e) {
     
    411422      }
    412423    }
     424    #endregion
    413425  }
    414426}
  • branches/HeuristicLab.RegressionSolutionGradientView/HeuristicLab.Problems.DataAnalysis.Views/3.4/RegressionSolutionTargetResponseGradientView.Designer.cs

    r13808 r13817  
    2525    private void InitializeComponent() {
    2626      this.variableListView = new System.Windows.Forms.ListView();
     27      this.panel1 = new System.Windows.Forms.Panel();
    2728      this.gradientChartTableLayout = new System.Windows.Forms.TableLayoutPanel();
     29      this.panel1.SuspendLayout();
    2830      this.SuspendLayout();
    2931      //
     
    3537      this.variableListView.Location = new System.Drawing.Point(4, 4);
    3638      this.variableListView.Name = "variableListView";
    37       this.variableListView.Size = new System.Drawing.Size(263, 944);
     39      this.variableListView.Size = new System.Drawing.Size(152, 332);
    3840      this.variableListView.TabIndex = 0;
    3941      this.variableListView.UseCompatibleStateImageBehavior = false;
    4042      this.variableListView.View = System.Windows.Forms.View.List;
    4143      //
     44      // panel1
     45      //
     46      this.panel1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
     47            | System.Windows.Forms.AnchorStyles.Left)
     48            | System.Windows.Forms.AnchorStyles.Right)));
     49      this.panel1.AutoScroll = true;
     50      this.panel1.Controls.Add(this.gradientChartTableLayout);
     51      this.panel1.Location = new System.Drawing.Point(162, 4);
     52      this.panel1.Name = "panel1";
     53      this.panel1.Size = new System.Drawing.Size(868, 693);
     54      this.panel1.TabIndex = 1;
     55      //
    4256      // gradientChartTableLayout
    4357      //
    44       this.gradientChartTableLayout.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
    45             | System.Windows.Forms.AnchorStyles.Left)
     58      this.gradientChartTableLayout.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
    4659            | System.Windows.Forms.AnchorStyles.Right)));
    47       this.gradientChartTableLayout.ColumnCount = 2;
    48       this.gradientChartTableLayout.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 50F));
    49       this.gradientChartTableLayout.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 50F));
    50       this.gradientChartTableLayout.Location = new System.Drawing.Point(274, 4);
     60      this.gradientChartTableLayout.AutoSize = true;
     61      this.gradientChartTableLayout.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink;
     62      this.gradientChartTableLayout.ColumnCount = 4;
     63      this.gradientChartTableLayout.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 25F));
     64      this.gradientChartTableLayout.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 25F));
     65      this.gradientChartTableLayout.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 25F));
     66      this.gradientChartTableLayout.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 25F));
     67      this.gradientChartTableLayout.Location = new System.Drawing.Point(3, 3);
    5168      this.gradientChartTableLayout.Name = "gradientChartTableLayout";
    52       this.gradientChartTableLayout.RowCount = 2;
    53       this.gradientChartTableLayout.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 50F));
    54       this.gradientChartTableLayout.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 50F));
    55       this.gradientChartTableLayout.Size = new System.Drawing.Size(1323, 944);
    56       this.gradientChartTableLayout.TabIndex = 1;
     69      this.gradientChartTableLayout.RowCount = 1;
     70      this.gradientChartTableLayout.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 693F));
     71      this.gradientChartTableLayout.Size = new System.Drawing.Size(848, 693);
     72      this.gradientChartTableLayout.TabIndex = 2;
    5773      //
    5874      // RegressionSolutionTargetResponseGradientView
     
    6076      this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
    6177      this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
    62       this.Controls.Add(this.gradientChartTableLayout);
     78      this.Controls.Add(this.panel1);
    6379      this.Controls.Add(this.variableListView);
    6480      this.Name = "RegressionSolutionTargetResponseGradientView";
    65       this.Size = new System.Drawing.Size(1600, 951);
     81      this.Size = new System.Drawing.Size(1033, 700);
     82      this.panel1.ResumeLayout(false);
     83      this.panel1.PerformLayout();
    6684      this.ResumeLayout(false);
    6785
     
    7189
    7290    private System.Windows.Forms.ListView variableListView;
     91    private System.Windows.Forms.Panel panel1;
    7392    private System.Windows.Forms.TableLayoutPanel gradientChartTableLayout;
    7493  }
  • branches/HeuristicLab.RegressionSolutionGradientView/HeuristicLab.Problems.DataAnalysis.Views/3.4/RegressionSolutionTargetResponseGradientView.cs

    r13808 r13817  
    1 using System.Collections.Generic;
     1#region License Information
     2/* HeuristicLab
     3 * Copyright (C) 2002-2016 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     4 *
     5 * This file is part of HeuristicLab.
     6 *
     7 * HeuristicLab is free software: you can redistribute it and/or modify
     8 * it under the terms of the GNU General Public License as published by
     9 * the Free Software Foundation, either version 3 of the License, or
     10 * (at your option) any later version.
     11 *
     12 * HeuristicLab is distributed in the hope that it will be useful,
     13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
     14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     15 * GNU General Public License for more details.
     16 *
     17 * You should have received a copy of the GNU General Public License
     18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
     19 */
     20#endregion
     21
     22using System.Collections.Generic;
    223using System.Linq;
    324using System.Windows.Forms;
    425using HeuristicLab.Common;
    526using HeuristicLab.MainForm;
     27using HeuristicLab.MainForm.WindowsForms;
    628
    729namespace HeuristicLab.Problems.DataAnalysis.Views {
     
    3961    protected override void OnContentChanged() {
    4062      base.OnContentChanged();
     63      if (Content == null) return;
    4164      var pd = Content.ProblemData;
    4265      var ds = pd.Dataset;
     
    5073      var variableValues = variableNames.Select(x => new List<double> { pd.Dataset.GetDoubleValues(x, pd.TrainingIndices).Median() });
    5174      internalDataset = new ModifiableDataset(variableNames, variableValues);
    52 
    5375      // update charts and variable limits
    5476      charts = new Dictionary<string, GradientChart>();
     
    6183        }
    6284        variableLimits[x] = new DoubleLimit(min, max);
    63         var gradientChart = new GradientChart();
     85        var gradientChart = new GradientChart { Dock = DockStyle.Fill, ShowLegend = false, Margin = Padding.Empty };
     86        gradientChart.VariableValueChanged += (o, e) => {
     87          foreach (var chart in gradientChartTableLayout.Controls.Cast<GradientChart>()) {
     88            if (chart == (GradientChart)o) continue;
     89            chart.UpdateChart();
     90          }
     91        };
    6492        gradientChart.Configure(new[] { Content }, pd, internalDataset, x, min, max, Points);
    6593        charts[x] = gradientChart;
     
    72100      var variable = item.Text;
    73101      var chart = charts[variable];
     102      var tl = gradientChartTableLayout;
     103      tl.SuspendLayout();
     104      var columnWidth = tl.GetColumnWidths()[0]; // all columns have the same width
     105      var rowHeight = 0.8f * columnWidth;
     106      tl.RowStyles.Clear();
     107
    74108      if (item.Checked) {
    75         gradientChartTableLayout.Controls.Add(chart);
     109        tl.Controls.Add(chart);
     110        var index = tl.Controls.Count - 1;
     111        int rowIndex = index / tl.ColumnCount;
     112        int columnIndex = index % tl.ColumnCount;
     113        tl.SetRow(chart, rowIndex);
     114        tl.SetColumn(chart, columnIndex);
    76115        chart.UpdateChart();
     116        tl.RowCount = rowIndex + 1;
    77117      } else {
    78         gradientChartTableLayout.Controls.Remove(chart);
     118        tl.Controls.Remove(chart);
     119        // relayout
     120        var count = tl.Controls.Count;
     121        tl.RowCount = count / tl.ColumnCount + (count % tl.ColumnCount == 0 ? 0 : 1);
     122        for (int i = 0; i < count; ++i) {
     123          var control = tl.Controls[i];
     124          int rowIndex = i / tl.ColumnCount;
     125          int columnIndex = i % tl.ColumnCount;
     126          tl.SetRow(control, rowIndex);
     127          tl.SetColumn(control, columnIndex);
     128        }
    79129      }
     130      // set absolute row sizes
     131      for (int i = 0; i < tl.RowCount; ++i) {
     132        tl.RowStyles.Add(new RowStyle(SizeType.Absolute, rowHeight));
     133      }
     134      tl.ResumeLayout();
    80135    }
    81136  }
Note: See TracChangeset for help on using the changeset viewer.