Changeset 3442 for trunk/sources/HeuristicLab.Problems.DataAnalysis.Views
- Timestamp:
- 04/20/10 15:49:22 (14 years ago)
- 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 { 1 namespace HeuristicLab.Problems.DataAnalysis.Views { 23 2 partial class DataAnalysisProblemDataView { 24 3 /// <summary> … … 32 11 /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param> 33 12 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(); 37 15 } 38 16 base.Dispose(disposing); … … 46 24 /// </summary> 47 25 private void InitializeComponent() { 26 this.variableCollectionView = new HeuristicLab.Core.Views.VariableCollectionView(); 48 27 this.importButton = new System.Windows.Forms.Button(); 49 this.datasetView = new HeuristicLab.Data.Views.StringConvertibleMatrixView();50 28 ((System.ComponentModel.ISupportInitialize)(this.errorProvider)).BeginInit(); 51 29 this.SuspendLayout(); … … 55 33 this.errorProvider.SetIconAlignment(this.nameTextBox, System.Windows.Forms.ErrorIconAlignment.MiddleLeft); 56 34 this.errorProvider.SetIconPadding(this.nameTextBox, 2); 57 this.nameTextBox.Size = new System.Drawing.Size(457, 20);58 35 // 59 // descriptionTextBox36 // variableCollectionView 60 37 // 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; 62 48 // 63 49 // importButton … … 65 51 this.importButton.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left) 66 52 | 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); 68 54 this.importButton.Name = "importButton"; 69 this.importButton.Size = new System.Drawing.Size(5 29, 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"; 72 58 this.importButton.UseVisualStyleBackColor = true; 73 59 this.importButton.Click += new System.EventHandler(this.importButton_Click); 74 60 // 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 88 62 // 89 63 this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); 90 64 this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; 65 this.Controls.Add(this.variableCollectionView); 91 66 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); 96 69 this.Controls.SetChildIndex(this.importButton, 0); 70 this.Controls.SetChildIndex(this.variableCollectionView, 0); 97 71 this.Controls.SetChildIndex(this.nameLabel, 0); 98 72 this.Controls.SetChildIndex(this.descriptionLabel, 0); … … 107 81 #endregion 108 82 83 private HeuristicLab.Core.Views.VariableCollectionView variableCollectionView; 109 84 private System.Windows.Forms.Button importButton; 110 private HeuristicLab.Data.Views.StringConvertibleMatrixView datasetView;111 112 85 } 113 86 } -
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; 1 using System; 2 using System.Collections.Generic; 3 using System.ComponentModel; 4 using System.Drawing; 5 using System.Data; 6 using System.Linq; 7 using System.Text; 23 8 using System.Windows.Forms; 24 using HeuristicLab.Common;25 using HeuristicLab.Core;26 9 using HeuristicLab.Core.Views; 27 10 using HeuristicLab.MainForm; 28 11 29 namespace HeuristicLab.Problems.DataAnalysis {30 [View("Data-Analysis DataView")]31 [Content(typeof(DataAnalysisProblemData) , true)]12 namespace HeuristicLab.Problems.DataAnalysis.Views { 13 [View("Data-Analysis Problem View")] 14 [Content(typeof(DataAnalysisProblemData))] 32 15 public partial class DataAnalysisProblemDataView : NamedItemView { 33 16 private OpenFileDialog openFileDialog; 34 35 17 public new DataAnalysisProblemData Content { 36 18 get { return (DataAnalysisProblemData)base.Content; } 37 set { base.Content = value; } 19 set { 20 base.Content = value; 21 } 38 22 } 39 23 … … 45 29 : this() { 46 30 Content = content; 31 variableCollectionView.Content = content.Variables.AsReadOnly(); 47 32 } 48 33 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) { 76 35 if (openFileDialog == null) openFileDialog = new OpenFileDialog(); 77 36 -
trunk/sources/HeuristicLab.Problems.DataAnalysis.Views/3.3/HeuristicLab.Problems.DataAnalysis.Views-3.3.csproj
r3437 r3442 72 72 <Reference Include="System.Drawing" /> 73 73 <Reference Include="System.Windows.Forms" /> 74 <Reference Include="System.Windows.Forms.DataVisualization, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL" /> 74 75 <Reference Include="System.Xml.Linq"> 75 76 <RequiredTargetFramework>3.5</RequiredTargetFramework> … … 84 85 <None Include="HeuristicLab.snk" /> 85 86 <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> 86 93 <Compile Include="DataAnalysisProblemDataView.cs"> 87 94 <SubType>UserControl</SubType> … … 91 98 </Compile> 92 99 <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> 93 106 <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> 94 125 </ItemGroup> 95 126 <ItemGroup> … … 118 149 <Name>HeuristicLab.Data-3.3</Name> 119 150 </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> 120 155 <ProjectReference Include="..\..\HeuristicLab.Encodings.SymbolicExpressionTreeEncoding\3.3\HeuristicLab.Encodings.SymbolicExpressionTreeEncoding-3.3.csproj"> 121 156 <Project>{125D3006-67F5-48CB-913E-73C0548F17FA}</Project> … … 146 181 <Name>HeuristicLab.PluginInfrastructure</Name> 147 182 </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> 148 187 <ProjectReference Include="..\..\HeuristicLab.Problems.DataAnalysis\3.3\HeuristicLab.Problems.DataAnalysis-3.3.csproj"> 149 188 <Project>{70DFD984-B1D9-46FE-8EB7-4DE92D71A9FC}</Project> 150 189 <Name>HeuristicLab.Problems.DataAnalysis-3.3</Name> 151 190 </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> 152 211 </ItemGroup> 153 212 <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> -
trunk/sources/HeuristicLab.Problems.DataAnalysis.Views/3.3/LineChartView.Designer.cs
r3408 r3442 19 19 */ 20 20 #endregion 21 namespace HeuristicLab.Problem .DataAnalysis.Views {21 namespace HeuristicLab.Problems.DataAnalysis.Views { 22 22 partial class LineChartView { 23 23 /// <summary> … … 63 63 this.chart.Size = new System.Drawing.Size(358, 225); 64 64 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);67 65 // 68 66 // QualityLineChart … … 74 72 this.Name = "QualityLineChart"; 75 73 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);78 74 ((System.ComponentModel.ISupportInitialize)(this.chart)).EndInit(); 79 75 this.ResumeLayout(false); -
trunk/sources/HeuristicLab.Problems.DataAnalysis.Views/3.3/LineChartView.cs
r3408 r3442 32 32 using HeuristicLab.Problems.DataAnalysis; 33 33 using HeuristicLab.MainForm.WindowsForms; 34 using System.Windows.Forms.DataVisualization.Charting; 34 35 35 namespace HeuristicLab.Problems.DataAnalysis {36 namespace HeuristicLab.Problems.DataAnalysis.Views { 36 37 [View("Line Chart View")] 37 38 [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 40 50 public LineChartView() 41 51 : base() { … … 49 59 this.chart.ChartAreas[0].CursorY.IsUserSelectionEnabled = true; 50 60 this.chart.ChartAreas[0].AxisY.ScaleView.Zoomable = true; 51 this.chart.ChartAreas[0].CursorY.Interval = 0; 61 this.chart.ChartAreas[0].CursorY.Interval = 0; 52 62 } 53 63 54 64 public LineChartView(DataAnalysisSolution dataAnalysisSolution) 55 65 : this() { 56 66 Content = dataAnalysisSolution; 67 DrawTargetVariableValues(); 68 DrawEstimatedValues(); 57 69 } 58 70 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; 70 77 } 71 78 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]); 107 85 this.UpdateStripLines(); 108 86 } 109 87 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); 114 93 } 115 94 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); 125 99 } 126 100 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 } 133 124 } 134 125 } 135 126 } 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 145 128 146 129 private void UpdateStripLines() { 147 130 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); 160 137 } 161 138 -
trunk/sources/HeuristicLab.Problems.DataAnalysis.Views/3.3/ScatterPlotView.Designer.cs
r3408 r3442 75 75 this.AllowDrop = true; 76 76 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);79 77 ((System.ComponentModel.ISupportInitialize)(this.chart)).EndInit(); 80 78 this.ResumeLayout(false); -
trunk/sources/HeuristicLab.Problems.DataAnalysis.Views/3.3/ScatterPlotView.cs
r3408 r3442 32 32 using HeuristicLab.MainForm; 33 33 using HeuristicLab.Problems.DataAnalysis; 34 35 namespace HeuristicLab.Problems.DataAnalyis.Views { 34 using HeuristicLab.MainForm.WindowsForms; 35 36 namespace HeuristicLab.Problems.DataAnalysis.Views { 36 37 [View("Scatter Plot View")] 37 38 [Content(typeof(DataAnalysisSolution))] 38 public partial class ScatterPlotView : ContentView {39 public partial class ScatterPlotView : AsynchronousContentView { 39 40 private const string DEFAULT_CAPTION = "Scatter Plot"; 40 41 private const string ALL_SERIES = "All Samples"; 41 42 private const string TRAINING_SERIES = "Training Samples"; 42 private const string validationSeries = "Validation Samples";43 43 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 } 44 49 45 50 public ScatterPlotView() … … 55 60 this.chart.Series[TRAINING_SERIES].LegendText = TRAINING_SERIES; 56 61 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;61 62 62 63 this.chart.Series.Add(TEST_SERIES); … … 80 81 } 81 82 82 public ScatterPlotView( IVisualModel visualModel)83 public ScatterPlotView(DataAnalysisSolution dataAnalysisSolution) 83 84 : 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; 98 118 this.UpdateSeries(); 99 119 if (!this.chart.Series.Any(s => s.Points.Count > 0)) … … 107 127 108 128 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; 109 135 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], ""); 112 138 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), ""); 118 141 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)); 128 147 129 148 max = Math.Ceiling(max) * 1.2; … … 139 158 this.chart.Series[ALL_SERIES].Points.Clear(); 140 159 this.chart.Series[TRAINING_SERIES].Points.Clear(); 141 this.chart.Series[validationSeries].Points.Clear();142 160 this.chart.Series[TEST_SERIES].Points.Clear(); 143 161 } 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 }174 162 175 163 private void ToggleSeriesData(Series series) { 176 164 if (series.Points.Count > 0) { //checks if series is shown 177 165 if (this.chart.Series.Any(s => s != series && s.Points.Count > 0)) { 178 series.Points.Clear(); 166 series.Points.Clear(); 179 167 } 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 181 176 IEnumerable<double> predictedValues = null; 182 177 IEnumerable<double> targetValues = null; 183 178 switch (series.Name) { 184 179 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]; 187 182 break; 188 183 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); 195 186 break; 196 187 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); 199 190 break; 200 191 } 201 series.Points.DataBindXY(predictedValues .ToArray(), "", targetValues, "");192 series.Points.DataBindXY(predictedValues, "", targetValues, ""); 202 193 this.chart.Legends[series.Legend].ForeColor = Color.Black; 203 194 } … … 227 218 e.LegendItems[0].Cells[1].ForeColor = this.chart.Series[ALL_SERIES].Points.Count == 0 ? Color.Gray : Color.Black; 228 219 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; 247 221 } 248 222 }
Note: See TracChangeset
for help on using the changeset viewer.