Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
04/20/10 15:49:22 (14 years ago)
Author:
gkronber
Message:

Implemented views for DataAnalysisProblems and DataAnalysisSolutions. #938 (Data types and operators for regression problems)

Location:
trunk/sources/HeuristicLab.Problems.DataAnalysis.Views/3.3
Files:
11 added
2 deleted
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Views/3.3/DataAnalysisProblemDataView.Designer.cs

    r3373 r3442  
    1 #region License Information
    2 /* HeuristicLab
    3  * Copyright (C) 2002-2010 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 
    22 namespace HeuristicLab.Problems.DataAnalysis {
     1namespace HeuristicLab.Problems.DataAnalysis.Views {
    232  partial class DataAnalysisProblemDataView {
    243    /// <summary>
     
    3211    /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
    3312    protected override void Dispose(bool disposing) {
    34       if (disposing) {
    35         if (openFileDialog != null) openFileDialog.Dispose();
    36         if (components != null) components.Dispose();
     13      if (disposing && (components != null)) {
     14        components.Dispose();
    3715      }
    3816      base.Dispose(disposing);
     
    4624    /// </summary>
    4725    private void InitializeComponent() {
     26      this.variableCollectionView = new HeuristicLab.Core.Views.VariableCollectionView();
    4827      this.importButton = new System.Windows.Forms.Button();
    49       this.datasetView = new HeuristicLab.Data.Views.StringConvertibleMatrixView();
    5028      ((System.ComponentModel.ISupportInitialize)(this.errorProvider)).BeginInit();
    5129      this.SuspendLayout();
     
    5533      this.errorProvider.SetIconAlignment(this.nameTextBox, System.Windows.Forms.ErrorIconAlignment.MiddleLeft);
    5634      this.errorProvider.SetIconPadding(this.nameTextBox, 2);
    57       this.nameTextBox.Size = new System.Drawing.Size(457, 20);
    5835      //
    59       // descriptionTextBox
     36      // variableCollectionView
    6037      //
    61       this.descriptionTextBox.Size = new System.Drawing.Size(457, 20);
     38      this.variableCollectionView.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
     39                  | System.Windows.Forms.AnchorStyles.Left)
     40                  | System.Windows.Forms.AnchorStyles.Right)));
     41      this.variableCollectionView.Caption = "VariableCollection";
     42      this.variableCollectionView.Content = null;
     43      this.variableCollectionView.Location = new System.Drawing.Point(0, 52);
     44      this.variableCollectionView.Name = "variableCollectionView";
     45      this.variableCollectionView.ReadOnly = false;
     46      this.variableCollectionView.Size = new System.Drawing.Size(588, 366);
     47      this.variableCollectionView.TabIndex = 0;
    6248      //
    6349      // importButton
     
    6551      this.importButton.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)
    6652                  | System.Windows.Forms.AnchorStyles.Right)));
    67       this.importButton.Location = new System.Drawing.Point(0, 399);
     53      this.importButton.Location = new System.Drawing.Point(6, 424);
    6854      this.importButton.Name = "importButton";
    69       this.importButton.Size = new System.Drawing.Size(529, 23);
    70       this.importButton.TabIndex = 5;
    71       this.importButton.Text = "&Import from CSV file";
     55      this.importButton.Size = new System.Drawing.Size(579, 23);
     56      this.importButton.TabIndex = 4;
     57      this.importButton.Text = "Import from CSV file";
    7258      this.importButton.UseVisualStyleBackColor = true;
    7359      this.importButton.Click += new System.EventHandler(this.importButton_Click);
    7460      //
    75       // datasetView
    76       //
    77       this.datasetView.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
    78                   | System.Windows.Forms.AnchorStyles.Left)
    79                   | System.Windows.Forms.AnchorStyles.Right)));
    80       this.datasetView.Caption = "StringConvertibleMatrix View";
    81       this.datasetView.Content = null;
    82       this.datasetView.Location = new System.Drawing.Point(0, 52);
    83       this.datasetView.Name = "datasetView";
    84       this.datasetView.Size = new System.Drawing.Size(526, 341);
    85       this.datasetView.TabIndex = 6;
    86       //
    87       // RegressionProblemDataView
     61      // ProblemDataView
    8862      //
    8963      this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
    9064      this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
     65      this.Controls.Add(this.variableCollectionView);
    9166      this.Controls.Add(this.importButton);
    92       this.Controls.Add(this.datasetView);
    93       this.Name = "RegressionProblemDataView";
    94       this.Size = new System.Drawing.Size(529, 422);
    95       this.Controls.SetChildIndex(this.datasetView, 0);
     67      this.Name = "ProblemDataView";
     68      this.Size = new System.Drawing.Size(588, 450);
    9669      this.Controls.SetChildIndex(this.importButton, 0);
     70      this.Controls.SetChildIndex(this.variableCollectionView, 0);
    9771      this.Controls.SetChildIndex(this.nameLabel, 0);
    9872      this.Controls.SetChildIndex(this.descriptionLabel, 0);
     
    10781    #endregion
    10882
     83    private HeuristicLab.Core.Views.VariableCollectionView variableCollectionView;
    10984    private System.Windows.Forms.Button importButton;
    110     private HeuristicLab.Data.Views.StringConvertibleMatrixView datasetView;
    111 
    11285  }
    11386}
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Views/3.3/DataAnalysisProblemDataView.cs

    r3376 r3442  
    1 #region License Information
    2 /* HeuristicLab
    3  * Copyright (C) 2002-2010 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 
    22 using System;
     1using System;
     2using System.Collections.Generic;
     3using System.ComponentModel;
     4using System.Drawing;
     5using System.Data;
     6using System.Linq;
     7using System.Text;
    238using System.Windows.Forms;
    24 using HeuristicLab.Common;
    25 using HeuristicLab.Core;
    269using HeuristicLab.Core.Views;
    2710using HeuristicLab.MainForm;
    2811
    29 namespace HeuristicLab.Problems.DataAnalysis {
    30   [View("Data-Analysis Data View")]
    31   [Content(typeof(DataAnalysisProblemData), true)]
     12namespace HeuristicLab.Problems.DataAnalysis.Views {
     13  [View("Data-Analysis Problem View")]
     14  [Content(typeof(DataAnalysisProblemData))]
    3215  public partial class DataAnalysisProblemDataView : NamedItemView {
    3316    private OpenFileDialog openFileDialog;
    34 
    3517    public new DataAnalysisProblemData Content {
    3618      get { return (DataAnalysisProblemData)base.Content; }
    37       set { base.Content = value; }
     19      set {
     20        base.Content = value;
     21      }
    3822    }
    3923
     
    4529      : this() {
    4630      Content = content;
     31      variableCollectionView.Content = content.Variables.AsReadOnly();
    4732    }
    4833
    49     protected override void RegisterContentEvents() {
    50       base.RegisterContentEvents();
    51       if (Content != null)
    52         Content.DatasetChanged += new EventHandler(Content_DatasetChanged);
    53     }
    54 
    55     protected override void DeregisterContentEvents() {
    56       base.DeregisterContentEvents();
    57       if(Content != null)
    58         Content.DatasetChanged -= new EventHandler(Content_DatasetChanged);
    59     }
    60 
    61     private void Content_DatasetChanged(object sender, EventArgs e) {
    62       this.datasetView.Content = this.Content.Dataset;
    63     }
    64 
    65     protected override void OnContentChanged() {
    66       base.OnContentChanged();
    67       if (Content == null) {
    68         importButton.Enabled = false;
    69       } else {
    70         importButton.Enabled = true;
    71         this.datasetView.Content = this.Content.Dataset;
    72       }
    73     }
    74 
    75     private void importButton_Click(object sender, System.EventArgs e) {
     34    private void importButton_Click(object sender, EventArgs e) {
    7635      if (openFileDialog == null) openFileDialog = new OpenFileDialog();
    7736
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Views/3.3/HeuristicLab.Problems.DataAnalysis.Views-3.3.csproj

    r3437 r3442  
    7272    <Reference Include="System.Drawing" />
    7373    <Reference Include="System.Windows.Forms" />
     74    <Reference Include="System.Windows.Forms.DataVisualization, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL" />
    7475    <Reference Include="System.Xml.Linq">
    7576      <RequiredTargetFramework>3.5</RequiredTargetFramework>
     
    8485    <None Include="HeuristicLab.snk" />
    8586    <None Include="Properties\AssemblyInfo.frame" />
     87    <Compile Include="EstimatedValuesView.cs">
     88      <SubType>UserControl</SubType>
     89    </Compile>
     90    <Compile Include="EstimatedValuesView.Designer.cs">
     91      <DependentUpon>EstimatedValuesView.cs</DependentUpon>
     92    </Compile>
    8693    <Compile Include="DataAnalysisProblemDataView.cs">
    8794      <SubType>UserControl</SubType>
     
    9198    </Compile>
    9299    <Compile Include="HeuristicLabProblemsDataAnalysisViewsPlugin.cs" />
     100    <Compile Include="LineChartView.cs">
     101      <SubType>UserControl</SubType>
     102    </Compile>
     103    <Compile Include="LineChartView.Designer.cs">
     104      <DependentUpon>LineChartView.cs</DependentUpon>
     105    </Compile>
    93106    <Compile Include="Properties\AssemblyInfo.cs" />
     107    <Compile Include="ScatterPlotView.cs">
     108      <SubType>UserControl</SubType>
     109    </Compile>
     110    <Compile Include="ScatterPlotView.Designer.cs">
     111      <DependentUpon>ScatterPlotView.cs</DependentUpon>
     112    </Compile>
     113    <Compile Include="Symbolic\SimplifiedSymbolicExpressionModelView.cs">
     114      <SubType>UserControl</SubType>
     115    </Compile>
     116    <Compile Include="Symbolic\SimplifiedSymbolicExpressionModelView.designer.cs">
     117      <DependentUpon>SimplifiedSymbolicExpressionModelView.cs</DependentUpon>
     118    </Compile>
     119    <Compile Include="Symbolic\SymbolicExpressionModelView.cs">
     120      <SubType>UserControl</SubType>
     121    </Compile>
     122    <Compile Include="Symbolic\SymbolicExpressionModelView.designer.cs">
     123      <DependentUpon>SymbolicExpressionModelView.cs</DependentUpon>
     124    </Compile>
    94125  </ItemGroup>
    95126  <ItemGroup>
     
    118149      <Name>HeuristicLab.Data-3.3</Name>
    119150    </ProjectReference>
     151    <ProjectReference Include="..\..\HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views\3.3\HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views-3.3.csproj">
     152      <Project>{6F42C5F8-16CD-43EE-8208-FD4573A69D85}</Project>
     153      <Name>HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views-3.3</Name>
     154    </ProjectReference>
    120155    <ProjectReference Include="..\..\HeuristicLab.Encodings.SymbolicExpressionTreeEncoding\3.3\HeuristicLab.Encodings.SymbolicExpressionTreeEncoding-3.3.csproj">
    121156      <Project>{125D3006-67F5-48CB-913E-73C0548F17FA}</Project>
     
    146181      <Name>HeuristicLab.PluginInfrastructure</Name>
    147182    </ProjectReference>
     183    <ProjectReference Include="..\..\HeuristicLab.Problems.DataAnalysis.Regression\3.3\HeuristicLab.Problems.DataAnalysis.Regression-3.3.csproj">
     184      <Project>{BDF86B1D-630E-4CE2-8A49-8C90B1BDE4C9}</Project>
     185      <Name>HeuristicLab.Problems.DataAnalysis.Regression-3.3</Name>
     186    </ProjectReference>
    148187    <ProjectReference Include="..\..\HeuristicLab.Problems.DataAnalysis\3.3\HeuristicLab.Problems.DataAnalysis-3.3.csproj">
    149188      <Project>{70DFD984-B1D9-46FE-8EB7-4DE92D71A9FC}</Project>
    150189      <Name>HeuristicLab.Problems.DataAnalysis-3.3</Name>
    151190    </ProjectReference>
     191  </ItemGroup>
     192  <ItemGroup>
     193    <EmbeddedResource Include="EstimatedValuesView.resx">
     194      <DependentUpon>EstimatedValuesView.cs</DependentUpon>
     195    </EmbeddedResource>
     196    <EmbeddedResource Include="DataAnalysisProblemDataView.resx">
     197      <DependentUpon>DataAnalysisProblemDataView.cs</DependentUpon>
     198    </EmbeddedResource>
     199    <EmbeddedResource Include="LineChartView.resx">
     200      <DependentUpon>LineChartView.cs</DependentUpon>
     201    </EmbeddedResource>
     202    <EmbeddedResource Include="ScatterPlotView.resx">
     203      <DependentUpon>ScatterPlotView.cs</DependentUpon>
     204    </EmbeddedResource>
     205    <EmbeddedResource Include="Symbolic\SimplifiedSymbolicExpressionModelView.resx">
     206      <DependentUpon>SimplifiedSymbolicExpressionModelView.cs</DependentUpon>
     207    </EmbeddedResource>
     208    <EmbeddedResource Include="Symbolic\SymbolicExpressionModelView.resx">
     209      <DependentUpon>SymbolicExpressionModelView.cs</DependentUpon>
     210    </EmbeddedResource>
    152211  </ItemGroup>
    153212  <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Views/3.3/LineChartView.Designer.cs

    r3408 r3442  
    1919 */
    2020#endregion
    21 namespace HeuristicLab.Problem.DataAnalysis.Views {
     21namespace HeuristicLab.Problems.DataAnalysis.Views {
    2222  partial class LineChartView {
    2323    /// <summary>
     
    6363      this.chart.Size = new System.Drawing.Size(358, 225);
    6464      this.chart.TabIndex = 0;
    65       this.chart.MouseMove += new System.Windows.Forms.MouseEventHandler(this.chart_MouseMove);
    66       this.chart.MouseDown += new System.Windows.Forms.MouseEventHandler(this.chart_MouseDown);
    6765      //
    6866      // QualityLineChart
     
    7472      this.Name = "QualityLineChart";
    7573      this.Size = new System.Drawing.Size(358, 225);
    76       this.DragDrop += new System.Windows.Forms.DragEventHandler(this.ModelLineChart_DragDrop);
    77       this.DragEnter += new System.Windows.Forms.DragEventHandler(this.ModelLineChart_DragEnter);
    7874      ((System.ComponentModel.ISupportInitialize)(this.chart)).EndInit();
    7975      this.ResumeLayout(false);
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Views/3.3/LineChartView.cs

    r3408 r3442  
    3232using HeuristicLab.Problems.DataAnalysis;
    3333using HeuristicLab.MainForm.WindowsForms;
     34using System.Windows.Forms.DataVisualization.Charting;
    3435
    35 namespace HeuristicLab.Problems.DataAnalysis {
     36namespace HeuristicLab.Problems.DataAnalysis.Views {
    3637  [View("Line Chart View")]
    3738  [Content(typeof(DataAnalysisSolution))]
    38   public partial class LineChartView : ContentView {
    39    
     39  public partial class LineChartView : AsynchronousContentView {
     40    private const string TARGETVARIABLE_SERIES_NAME = "TargetVariable";
     41    private const string ESTIMATEDVALUES_SERIES_NAME = "EstimatedValues";
     42
     43    public new DataAnalysisSolution Content {
     44      get { return (DataAnalysisSolution)base.Content; }
     45      set {
     46        base.Content = value;
     47      }
     48    }
     49
    4050    public LineChartView()
    4151      : base() {
     
    4959      this.chart.ChartAreas[0].CursorY.IsUserSelectionEnabled = true;
    5060      this.chart.ChartAreas[0].AxisY.ScaleView.Zoomable = true;
    51       this.chart.ChartAreas[0].CursorY.Interval = 0;     
     61      this.chart.ChartAreas[0].CursorY.Interval = 0;
    5262    }
    5363
    5464    public LineChartView(DataAnalysisSolution dataAnalysisSolution)
    5565      : this() {
    56      
     66      Content = dataAnalysisSolution;
     67      DrawTargetVariableValues();
     68      DrawEstimatedValues();
    5769    }
    5870
    59     private void model_Changed(object sender, EventArgs e) {
    60       if (InvokeRequired) {
    61         Action<object, EventArgs> action = new Action<object, EventArgs>(model_Changed);
    62         this.Invoke(action, sender, e);
    63       } else {
    64         IVisualModel model = (IVisualModel)sender;
    65         Series s = this.chart.Series.Single(x => x.Tag == model);
    66         s.Points.DataBindY(model.PredictedValues.ToArray());
    67         s.LegendText = model.ModelName;
    68         this.UpdateStripLines();
    69       }
     71    private void DrawEstimatedValues() {
     72      this.chart.Series.Add(ESTIMATEDVALUES_SERIES_NAME);
     73      this.chart.Series[ESTIMATEDVALUES_SERIES_NAME].LegendText = Content.ItemName;
     74      this.chart.Series[ESTIMATEDVALUES_SERIES_NAME].ChartType = SeriesChartType.FastLine;
     75      this.chart.Series[ESTIMATEDVALUES_SERIES_NAME].Points.DataBindY(Content.EstimatedValues.ToArray());
     76      this.chart.Series[ESTIMATEDVALUES_SERIES_NAME].Tag = Content;
    7077    }
    7178
    72     protected override void ModelsCollectionChanged(object sender, NotifyCollectionChangedEventArgs e) {
    73       base.ModelsCollectionChanged(sender, e);
    74       if (InvokeRequired) {
    75         Action<object, NotifyCollectionChangedEventArgs> action = new Action<object, NotifyCollectionChangedEventArgs>(ModelsCollectionChanged);
    76         this.Invoke(action, sender, e);
    77       } else {
    78         if (e.Action == NotifyCollectionChangedAction.Remove) {
    79           foreach (IVisualModel model in e.OldItems) {
    80             if (this.chart.Series.Any(x => x.Tag == model))
    81               this.RemoveModel(model);
    82           }
    83           this.UpdateStripLines();
    84         } else if (e.Action == NotifyCollectionChangedAction.Reset)
    85           this.RemoveAllModels();
    86       }
    87     }
    88 
    89     private void AddModel(IVisualModel model) {
    90       if (this.targetVariableName != model.TargetVariableName) {
    91         this.RemoveAllModels();
    92         this.chart.Series.Clear();
    93         this.chart.Series.Add(TARGETVARIABLE);
    94         this.chart.Series[TARGETVARIABLE].LegendText = model.TargetVariableName;
    95         this.chart.Series[TARGETVARIABLE].ChartType = SeriesChartType.FastLine;
    96         this.chart.Series[TARGETVARIABLE].Points.DataBindY(model.Dataset.GetVariableValues(model.TargetVariableName));
    97         this.targetVariableName = model.TargetVariableName;
    98         this.Caption = this.targetVariableName + " Model Line Chart";
    99       }
    100       string seriesName = model.GetHashCode().ToString();
    101       this.chart.Series.Add(seriesName);
    102       this.chart.Series[seriesName].Tag = model;
    103       this.chart.Series[seriesName].LegendText = model.ModelName;
    104       this.chart.Series[seriesName].ChartType = SeriesChartType.FastLine;
    105       this.chart.Series[seriesName].Points.DataBindY(model.PredictedValues.ToArray());
    106       model.Changed += new EventHandler(model_Changed);
     79    private void DrawTargetVariableValues() {
     80      this.chart.Series.Clear();
     81      this.chart.Series.Add(TARGETVARIABLE_SERIES_NAME);
     82      this.chart.Series[TARGETVARIABLE_SERIES_NAME].LegendText = Content.ProblemData.TargetVariable.Value;
     83      this.chart.Series[TARGETVARIABLE_SERIES_NAME].ChartType = SeriesChartType.FastLine;
     84      this.chart.Series[TARGETVARIABLE_SERIES_NAME].Points.DataBindY(Content.ProblemData.Dataset[Content.ProblemData.TargetVariable.Value]);
    10785      this.UpdateStripLines();
    10886    }
    10987
    110     private void RemoveModel(IVisualModel model) {
    111       Series s = this.chart.Series.Single(x => x.Tag == model);
    112       this.chart.Series.Remove(s);
    113       model.Changed -= new EventHandler(model_Changed);
     88    #region events
     89    protected override void RegisterContentEvents() {
     90      base.RegisterContentEvents();
     91      Content.ModelChanged += new EventHandler(Content_ModelChanged);
     92      Content.ProblemDataChanged += new EventHandler(Content_ProblemDataChanged);
    11493    }
    11594
    116     private void RemoveAllModels() {
    117       var models = (from s in chart.Series
    118                     let m = s.Tag as IVisualModel
    119                     where m != null
    120                     select m).ToArray(); // select and copy currently displayed models
    121       foreach (var m in models) {
    122         this.RemoveModel(m);
    123       }
    124       this.UpdateStripLines();
     95    protected override void DeregisterContentEvents() {
     96      base.DeregisterContentEvents();
     97      Content.ModelChanged -= new EventHandler(Content_ModelChanged);
     98      Content.ProblemDataChanged -= new EventHandler(Content_ProblemDataChanged);
    12599    }
    126100
    127     private void chart_MouseDown(object sender, MouseEventArgs e) {
    128       HitTestResult result = this.chart.HitTest(e.X, e.Y);
    129       if (result.ChartElementType == ChartElementType.LegendItem) {
    130         if (result.Series.Name != TARGETVARIABLE) {
    131           this.RemoveModel(result.Series.Tag as IVisualModel);
    132           this.UpdateStripLines();
     101    void Content_ProblemDataChanged(object sender, EventArgs e) {
     102      OnContentChanged();
     103    }
     104
     105    void Content_ModelChanged(object sender, EventArgs e) {
     106      OnContentChanged();
     107    }
     108
     109    protected override void OnContentChanged() {
     110      base.OnContentChanged();
     111      UpdateEstimatedValuesLineChart();
     112    }
     113
     114    private void UpdateEstimatedValuesLineChart() {
     115      if (InvokeRequired) Invoke((Action)UpdateEstimatedValuesLineChart);
     116      else {
     117        if (this.chart.Series.Count > 0) {
     118          Series s = this.chart.Series.SingleOrDefault(x => x.Tag == Content);
     119          if (s != null) {
     120            s.Points.DataBindY(Content.EstimatedValues.ToArray());
     121            s.LegendText = Content.ItemName;
     122            this.UpdateStripLines();
     123          }
    133124        }
    134125      }
    135126    }
    136 
    137     private void chart_MouseMove(object sender, MouseEventArgs e) {
    138       HitTestResult result = this.chart.HitTest(e.X, e.Y);
    139       if (result.ChartElementType == ChartElementType.LegendItem) {
    140         if (result.Series.Name != TARGETVARIABLE)
    141           this.Cursor = Cursors.Hand;
    142       } else
    143         this.Cursor = Cursors.Default;
    144     }
     127    #endregion
    145128
    146129    private void UpdateStripLines() {
    147130      this.chart.ChartAreas[0].AxisX.StripLines.Clear();
    148       IEnumerable<IVisualModel> visualModels = from Series s in this.chart.Series
    149                                                where s.Tag is IVisualModel
    150                                                select (IVisualModel)s.Tag;
    151       if (visualModels.Count() > 0) {
    152         IVisualModel model = visualModels.ElementAt(0);
    153         if (visualModels.All(x => x.TrainingSamplesStart == model.TrainingSamplesStart && x.TrainingSamplesEnd == model.TrainingSamplesEnd))
    154           this.CreateAndAddStripLine("Training", Color.FromArgb(20, Color.Green), model.TrainingSamplesStart, model.TrainingSamplesEnd);
    155         if (visualModels.All(x => x.ValidationSamplesStart == model.ValidationSamplesStart && x.ValidationSamplesEnd == model.ValidationSamplesEnd))
    156           this.CreateAndAddStripLine("Validation", Color.FromArgb(20, Color.Yellow), model.ValidationSamplesStart, model.ValidationSamplesEnd);
    157         if (visualModels.All(x => x.TestSamplesStart == model.TestSamplesStart && x.TestSamplesEnd == model.TestSamplesEnd))
    158           this.CreateAndAddStripLine("Test", Color.FromArgb(20, Color.Red), model.TestSamplesStart, model.TestSamplesEnd);
    159       }
     131      this.CreateAndAddStripLine("Training", Color.FromArgb(20, Color.Green),
     132        Content.ProblemData.TrainingSamplesStart.Value,
     133        Content.ProblemData.TrainingSamplesEnd.Value);
     134      this.CreateAndAddStripLine("Test", Color.FromArgb(20, Color.Red),
     135        Content.ProblemData.TestSamplesStart.Value,
     136        Content.ProblemData.TestSamplesEnd.Value);
    160137    }
    161138
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Views/3.3/ScatterPlotView.Designer.cs

    r3408 r3442  
    7575      this.AllowDrop = true;
    7676      this.Size = new System.Drawing.Size(527, 392);
    77       this.DragDrop += new System.Windows.Forms.DragEventHandler(this.ScatterPlotView_DragDrop);
    78       this.DragEnter += new System.Windows.Forms.DragEventHandler(this.ScatterPlotView_DragEnter);
    7977      ((System.ComponentModel.ISupportInitialize)(this.chart)).EndInit();
    8078      this.ResumeLayout(false);
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Views/3.3/ScatterPlotView.cs

    r3408 r3442  
    3232using HeuristicLab.MainForm;
    3333using HeuristicLab.Problems.DataAnalysis;
    34 
    35 namespace HeuristicLab.Problems.DataAnalyis.Views {
     34using HeuristicLab.MainForm.WindowsForms;
     35
     36namespace HeuristicLab.Problems.DataAnalysis.Views {
    3637  [View("Scatter Plot View")]
    3738  [Content(typeof(DataAnalysisSolution))]
    38   public partial class ScatterPlotView : ContentView {
     39  public partial class ScatterPlotView : AsynchronousContentView {
    3940    private const string DEFAULT_CAPTION = "Scatter Plot";
    4041    private const string ALL_SERIES = "All Samples";
    4142    private const string TRAINING_SERIES = "Training Samples";
    42     private const string validationSeries = "Validation Samples";
    4343    private const string TEST_SERIES = "Test Samples";
     44
     45    public new DataAnalysisSolution Content {
     46      get { return (DataAnalysisSolution)base.Content; }
     47      set { base.Content = value; }
     48    }
    4449
    4550    public ScatterPlotView()
     
    5560      this.chart.Series[TRAINING_SERIES].LegendText = TRAINING_SERIES;
    5661      this.chart.Series[TRAINING_SERIES].ChartType = SeriesChartType.FastPoint;
    57 
    58       this.chart.Series.Add(validationSeries);
    59       this.chart.Series[validationSeries].LegendText = validationSeries;
    60       this.chart.Series[validationSeries].ChartType = SeriesChartType.FastPoint;
    6162
    6263      this.chart.Series.Add(TEST_SERIES);
     
    8081    }
    8182
    82     public ScatterPlotView(IVisualModel visualModel)
     83    public ScatterPlotView(DataAnalysisSolution dataAnalysisSolution)
    8384      : this() {
    84       this.VisualModel = visualModel;
    85     }
    86 
    87     private IVisualModel visualModel;
    88     public IVisualModel VisualModel {
    89       get { return this.visualModel; }
    90       private set {
    91         if (this.visualModel != null) {
    92           this.visualModel.Changed -= new EventHandler(model_Changed);                 
    93         }
    94         this.visualModel = value;
    95         if (this.visualModel != null) {
    96           this.Caption = this.visualModel.ModelName + " " + DEFAULT_CAPTION;
    97           this.visualModel.Changed += new EventHandler(model_Changed);
     85      Content = dataAnalysisSolution;
     86    }
     87
     88    protected override void RegisterContentEvents() {
     89      base.RegisterContentEvents();
     90      Content.ModelChanged += new EventHandler(Content_ModelChanged);
     91      Content.ProblemDataChanged += new EventHandler(Content_ProblemDataChanged);
     92    }
     93    protected override void DeregisterContentEvents() {
     94      base.DeregisterContentEvents();
     95      Content.ModelChanged -= new EventHandler(Content_ModelChanged);
     96      Content.ProblemDataChanged -= new EventHandler(Content_ProblemDataChanged);
     97    }
     98
     99
     100    void Content_ProblemDataChanged(object sender, EventArgs e) {
     101      OnContentChanged();
     102    }
     103
     104    void Content_ModelChanged(object sender, EventArgs e) {
     105      OnContentChanged();
     106    }
     107
     108    protected override void OnContentChanged() {
     109      base.OnContentChanged();
     110      UpdateChart();
     111    }
     112
     113    private void UpdateChart() {
     114      if (InvokeRequired) Invoke((Action)UpdateChart);
     115      else {
     116        if (Content != null) {
     117          this.Caption = Content.ItemName + " " + DEFAULT_CAPTION;
    98118          this.UpdateSeries();
    99119          if (!this.chart.Series.Any(s => s.Points.Count > 0))
     
    107127
    108128    private void UpdateSeries() {
     129      string targetVariableName = Content.ProblemData.TargetVariable.Value;
     130      Dataset dataset = Content.ProblemData.Dataset;
     131      int trainingStart = Content.ProblemData.TrainingSamplesStart.Value;
     132      int trainingEnd = Content.ProblemData.TrainingSamplesEnd.Value;
     133      int testStart = Content.ProblemData.TestSamplesStart.Value;
     134      int testEnd = Content.ProblemData.TestSamplesEnd.Value;
    109135      if (this.chart.Series[ALL_SERIES].Points.Count > 0)
    110         this.chart.Series[ALL_SERIES].Points.DataBindXY(this.visualModel.PredictedValues.ToArray(), "",
    111           this.visualModel.Dataset.GetVariableValues(this.visualModel.TargetVariableName), "");
     136        this.chart.Series[ALL_SERIES].Points.DataBindXY(Content.EstimatedValues.ToArray(), "",
     137          dataset[targetVariableName], "");
    112138      if (this.chart.Series[TRAINING_SERIES].Points.Count > 0)
    113         this.chart.Series[TRAINING_SERIES].Points.DataBindXY(this.visualModel.PredictedTrainingValues.ToArray(), "",
    114           this.visualModel.Dataset.GetVariableValues(this.visualModel.TargetVariableName, this.visualModel.TrainingSamplesStart, this.visualModel.TrainingSamplesEnd), "");
    115       if (this.chart.Series[validationSeries].Points.Count > 0)
    116         this.chart.Series[validationSeries].Points.DataBindXY(this.visualModel.PredictedValidationValues.ToArray(), "",
    117           this.visualModel.Dataset.GetVariableValues(this.visualModel.TargetVariableName, this.visualModel.ValidationSamplesStart, this.visualModel.ValidationSamplesEnd), "");
     139        this.chart.Series[TRAINING_SERIES].Points.DataBindXY(Content.EstimatedTrainingValues.ToArray(), "",
     140          dataset.GetVariableValues(targetVariableName, trainingStart, trainingEnd), "");
    118141      if (this.chart.Series[TEST_SERIES].Points.Count > 0)
    119         this.chart.Series[TEST_SERIES].Points.DataBindXY(this.visualModel.PredictedTestValues.ToArray(), "",
    120           this.visualModel.Dataset.GetVariableValues(this.visualModel.TargetVariableName, this.visualModel.TestSamplesStart, this.visualModel.TestSamplesEnd), "");
    121 
    122       double x = this.visualModel.PredictedValues.Max();
    123       double y = this.visualModel.Dataset.GetMaximum(this.visualModel.TargetVariableName);
    124       double max = x > y ? x : y;
    125       x = this.visualModel.PredictedValues.Min();
    126       y = this.visualModel.Dataset.GetMinimum(this.visualModel.TargetVariableName);
    127       double min = x < y ? x : y;
     142        this.chart.Series[TEST_SERIES].Points.DataBindXY(Content.EstimatedTestValues.ToArray(), "",
     143          dataset.GetVariableValues(targetVariableName, testStart, testEnd), "");
     144
     145      double max = Math.Max(Content.EstimatedValues.Max(), dataset.GetMax(targetVariableName));
     146      double min = Math.Min(Content.EstimatedValues.Min(), dataset.GetMin(targetVariableName));
    128147
    129148      max = Math.Ceiling(max) * 1.2;
     
    139158      this.chart.Series[ALL_SERIES].Points.Clear();
    140159      this.chart.Series[TRAINING_SERIES].Points.Clear();
    141       this.chart.Series[validationSeries].Points.Clear();
    142160      this.chart.Series[TEST_SERIES].Points.Clear();
    143161    }
    144 
    145 
    146     private void model_Changed(object sender, EventArgs e) {
    147       if (InvokeRequired) {
    148         Action<object, EventArgs> action = new Action<object, EventArgs>(model_Changed);
    149         this.Invoke(action, sender, e);
    150       } else {
    151         this.Caption = this.visualModel.ModelName + " " + DEFAULT_CAPTION;
    152         this.UpdateSeries();
    153       }
    154     }
    155 
    156     protected override void OnClosed(FormClosedEventArgs e) {
    157       base.OnClosed( e);
    158       this.VisualModel = null;
    159     }
    160 
    161     protected override void ModelsCollectionChanged(object sender, NotifyCollectionChangedEventArgs e) {
    162       if (InvokeRequired) {
    163         Action<object, NotifyCollectionChangedEventArgs> action = new Action<object, NotifyCollectionChangedEventArgs>(ModelsCollectionChanged);
    164         this.Invoke(action, sender, e);
    165       } else {
    166         if (e.Action == NotifyCollectionChangedAction.Remove) {
    167           if (e.OldItems.Contains(this.visualModel))
    168             this.VisualModel = null;
    169         }
    170         if(e.Action == NotifyCollectionChangedAction.Reset)
    171           this.VisualModel = null;
    172       }
    173     } 
    174162
    175163    private void ToggleSeriesData(Series series) {
    176164      if (series.Points.Count > 0) {  //checks if series is shown
    177165        if (this.chart.Series.Any(s => s != series && s.Points.Count > 0)) {
    178           series.Points.Clear();   
     166          series.Points.Clear();
    179167        }
    180       } else if (this.visualModel != null) {
     168      } else if (Content != null) {
     169        string targetVariableName = Content.ProblemData.TargetVariable.Value;
     170        Dataset dataset = Content.ProblemData.Dataset;
     171        int trainingStart = Content.ProblemData.TrainingSamplesStart.Value;
     172        int trainingEnd = Content.ProblemData.TrainingSamplesEnd.Value;
     173        int testStart = Content.ProblemData.TestSamplesStart.Value;
     174        int testEnd = Content.ProblemData.TestSamplesEnd.Value;
     175
    181176        IEnumerable<double> predictedValues = null;
    182177        IEnumerable<double> targetValues = null;
    183178        switch (series.Name) {
    184179          case ALL_SERIES:
    185             predictedValues = this.visualModel.PredictedValues;
    186             targetValues = this.visualModel.Dataset.GetVariableValues(this.visualModel.TargetVariableName);
     180            predictedValues = Content.EstimatedValues;
     181            targetValues = dataset[targetVariableName];
    187182            break;
    188183          case TRAINING_SERIES:
    189             predictedValues = this.visualModel.PredictedTrainingValues;
    190             targetValues = this.visualModel.Dataset.GetVariableValues(this.visualModel.TargetVariableName, this.visualModel.TrainingSamplesStart, this.visualModel.TrainingSamplesEnd);
    191             break;
    192           case validationSeries:
    193             predictedValues = this.visualModel.PredictedValidationValues;
    194             targetValues = this.visualModel.Dataset.GetVariableValues(this.visualModel.TargetVariableName, this.visualModel.ValidationSamplesStart, this.visualModel.ValidationSamplesEnd);
     184            predictedValues = Content.EstimatedTrainingValues;
     185            targetValues = dataset.GetVariableValues(targetVariableName, trainingStart, trainingEnd);
    195186            break;
    196187          case TEST_SERIES:
    197             predictedValues = this.visualModel.PredictedTestValues;
    198             targetValues = this.visualModel.Dataset.GetVariableValues(this.visualModel.TargetVariableName, this.visualModel.TestSamplesStart, this.visualModel.TestSamplesEnd);
     188            predictedValues = Content.EstimatedTestValues;
     189            targetValues = dataset.GetVariableValues(targetVariableName, testStart, testEnd);
    199190            break;
    200191        }
    201         series.Points.DataBindXY(predictedValues.ToArray(), "", targetValues, "");
     192        series.Points.DataBindXY(predictedValues, "", targetValues, "");
    202193        this.chart.Legends[series.Legend].ForeColor = Color.Black;
    203194      }
     
    227218      e.LegendItems[0].Cells[1].ForeColor = this.chart.Series[ALL_SERIES].Points.Count == 0 ? Color.Gray : Color.Black;
    228219      e.LegendItems[1].Cells[1].ForeColor = this.chart.Series[TRAINING_SERIES].Points.Count == 0 ? Color.Gray : Color.Black;
    229       e.LegendItems[2].Cells[1].ForeColor = this.chart.Series[validationSeries].Points.Count == 0 ? Color.Gray : Color.Black;
    230       e.LegendItems[3].Cells[1].ForeColor = this.chart.Series[TEST_SERIES].Points.Count == 0 ? Color.Gray : Color.Black;
    231     }
    232 
    233 
    234     private void ScatterPlotView_DragDrop(object sender, DragEventArgs e) {
    235       IVisualModel model = this.ExtractModel(e.Data);
    236       if (model != null) {
    237         this.VisualModel = model;
    238       }
    239     }
    240 
    241     private void ScatterPlotView_DragEnter(object sender, DragEventArgs e) {
    242       IVisualModel model = this.ExtractModel(e.Data);
    243       if (model != null)
    244         e.Effect = DragDropEffects.Link;
    245       else
    246         e.Effect = DragDropEffects.None;
     220      e.LegendItems[2].Cells[1].ForeColor = this.chart.Series[TEST_SERIES].Points.Count == 0 ? Color.Gray : Color.Black;
    247221    }
    248222  }
Note: See TracChangeset for help on using the changeset viewer.